Merge pull request #9722 from theamirocohen/update_flashiap_driver_test

Add flash sum check
pull/9741/head
Martin Kojtal 2019-02-15 10:10:20 +01:00 committed by GitHub
commit 1554b0c143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 0 deletions

View File

@ -29,6 +29,17 @@
#include "mbed.h"
// Debug available
#ifndef FLASHIAP_DEBUG
#define FLASHIAP_DEBUG 0
#endif
#if FLASHIAP_DEBUG
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)
#endif
using namespace utest::v1;
@ -37,6 +48,21 @@ void flashiap_init_test()
FlashIAP flash_device;
uint32_t ret = flash_device.init();
TEST_ASSERT_EQUAL_INT32(0, ret);
uint32_t flash_start = flash_device.get_flash_start();
uint32_t flash_size = flash_device.get_flash_size();
utest_printf("Flash address: 0x%08x, size: %d\n", flash_start, flash_size);
uint32_t address = flash_start;
int num = 0;
while (flash_size) {
uint32_t sector_size = flash_device.get_sector_size(address);
// Make sure all sectors sum up to the total flash size
TEST_ASSERT(flash_size >= sector_size);
DEBUG_PRINTF("\tsector %3d: address 0x%08x, size %8d\n", num++, address, sector_size);
flash_size -= sector_size;
address += sector_size;
}
ret = flash_device.deinit();
TEST_ASSERT_EQUAL_INT32(0, ret);
}