Skip to content

Commit 1c3b6f4

Browse files
authored
Merge pull request #9268 from yossi2le/yossi_fix_flashiap_test
Calculate FlashIAPBlockDevice start address and size automatically for test only
2 parents e6efad1 + bdeb545 commit 1c3b6f4

File tree

1 file changed

+32
-0
lines changed
  • components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen

1 file changed

+32
-0
lines changed

components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
//#include "mbed.h"
25+
#include "FlashIAP.h"
2526
#include "LittleFileSystem.h"
2627
#include "fslittle_debug.h"
2728
#include "fslittle_test.h"
@@ -48,6 +49,15 @@ using namespace utest::v1;
4849
#endif
4950
/// @endcond
5051

52+
// Align a value to a specified size.
53+
// Parameters :
54+
// val - [IN] Value.
55+
// size - [IN] Size.
56+
// Return : Aligned value.
57+
static inline uint32_t align_up(uint32_t val, uint32_t size)
58+
{
59+
return (((val - 1) / size) + 1) * size;
60+
}
5161

5262
/* DEVICE_SPI
5363
* This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support.
@@ -1247,7 +1257,29 @@ control_t fslittle_fopen_test_00(const size_t call_count)
12471257
(void) call_count;
12481258
int32_t ret = -1;
12491259

1260+
#if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF)
1261+
1262+
size_t flash_size;
1263+
uint32_t start_address;
1264+
uint32_t bottom_address;
1265+
mbed::FlashIAP flash_driver;
1266+
1267+
ret = flash_driver.init();
1268+
TEST_ASSERT_EQUAL(0, ret);
1269+
1270+
//Find the start of first sector after text area
1271+
bottom_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash_driver.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));
1272+
start_address = flash_driver.get_flash_start();
1273+
flash_size = flash_driver.get_flash_size();
1274+
ret = flash_driver.deinit();
1275+
flash = new FlashIAPBlockDevice(bottom_address, start_address + flash_size - bottom_address);
1276+
1277+
#else
1278+
12501279
flash = new FlashIAPBlockDevice();
1280+
1281+
#endif
1282+
12511283
ret = flash->init();
12521284
TEST_ASSERT_EQUAL(0, ret);
12531285

0 commit comments

Comments
 (0)