Skip to content

Commit 1554b0c

Browse files
authored
Merge pull request #9722 from theamirocohen/update_flashiap_driver_test
Add flash sum check
2 parents 883b8b8 + 92ed1cb commit 1554b0c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929

3030
#include "mbed.h"
3131

32+
// Debug available
33+
#ifndef FLASHIAP_DEBUG
34+
#define FLASHIAP_DEBUG 0
35+
#endif
36+
37+
#if FLASHIAP_DEBUG
38+
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
39+
#else
40+
#define DEBUG_PRINTF(...)
41+
#endif
42+
3243
using namespace utest::v1;
3344

3445

@@ -37,6 +48,21 @@ void flashiap_init_test()
3748
FlashIAP flash_device;
3849
uint32_t ret = flash_device.init();
3950
TEST_ASSERT_EQUAL_INT32(0, ret);
51+
52+
uint32_t flash_start = flash_device.get_flash_start();
53+
uint32_t flash_size = flash_device.get_flash_size();
54+
utest_printf("Flash address: 0x%08x, size: %d\n", flash_start, flash_size);
55+
uint32_t address = flash_start;
56+
int num = 0;
57+
while (flash_size) {
58+
uint32_t sector_size = flash_device.get_sector_size(address);
59+
// Make sure all sectors sum up to the total flash size
60+
TEST_ASSERT(flash_size >= sector_size);
61+
DEBUG_PRINTF("\tsector %3d: address 0x%08x, size %8d\n", num++, address, sector_size);
62+
flash_size -= sector_size;
63+
address += sector_size;
64+
}
65+
4066
ret = flash_device.deinit();
4167
TEST_ASSERT_EQUAL_INT32(0, ret);
4268
}

0 commit comments

Comments
 (0)