Skip to content

Commit

Permalink
Merge pull request #8589 from davidsaada/david_flash_erase_value
Browse files Browse the repository at this point in the history
Support erase value in Flash HAL drivers, FlashIAP and block devices
  • Loading branch information
Cruz Monrreal authored Nov 8, 2018
2 parents 760b074 + 542744d commit 3046e31
Show file tree
Hide file tree
Showing 30 changed files with 232 additions and 4 deletions.
18 changes: 14 additions & 4 deletions TESTS/mbed_drivers/flashiap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ void flashiap_program_test()
TEST_ASSERT_TRUE(sector_size % page_size == 0);
uint32_t prog_size = std::max(page_size, (uint32_t)8);
uint8_t *data = new uint8_t[prog_size + 2];
for (uint32_t i = 0; i < prog_size + 2; i++) {
data[i] = i;
}

// the one before the last sector in the system
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
Expand All @@ -68,14 +65,27 @@ void flashiap_program_test()
ret = flash_device.erase(address, sector_size);
TEST_ASSERT_EQUAL_INT32(0, ret);

uint8_t erase_val = flash_device.get_erase_value();
memset(data, erase_val, prog_size);

uint8_t *data_flashed = new uint8_t[prog_size];
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t page_addr = address + i * prog_size;
ret = flash_device.read(data_flashed, page_addr, prog_size);
TEST_ASSERT_EQUAL_INT32(0, ret);
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, prog_size);
}

for (uint32_t i = 0; i < prog_size + 2; i++) {
data[i] = i;
}

for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t prog_addr = address + i * prog_size;
ret = flash_device.program(data, prog_addr, prog_size);
TEST_ASSERT_EQUAL_INT32(0, ret);
}

uint8_t *data_flashed = new uint8_t[prog_size];
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t page_addr = address + i * prog_size;
ret = flash_device.read(data_flashed, page_addr, prog_size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,20 @@ bd_size_t FlashIAPBlockDevice::get_erase_size(bd_addr_t addr) const
return erase_size;
}

int FlashIAPBlockDevice::get_erase_value() const
{
if (!_is_initialized) {
return -1;
}

uint8_t erase_val = _flash.get_erase_value();

DEBUG_PRINTF("get_erase_value: %" PRIX8 "\r\n", erase_val);

return erase_val;
}


bd_size_t FlashIAPBlockDevice::size() const
{
DEBUG_PRINTF("size: %" PRIX64 "\r\n", _size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class FlashIAPBlockDevice : public BlockDevice {
*/
virtual bd_size_t get_erase_size(bd_addr_t addr) const;

/** Get the value of storage when erased
*
* @return The value of storage when erased
*/
virtual int get_erase_value() const;

/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
Expand Down
5 changes: 5 additions & 0 deletions drivers/FlashIAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ uint32_t FlashIAP::get_flash_size() const
return flash_get_size(&_flash);
}

uint8_t FlashIAP::get_erase_value() const
{
return flash_get_erase_value(&_flash);
}

}

#endif
7 changes: 7 additions & 0 deletions drivers/FlashIAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class FlashIAP : private NonCopyable<FlashIAP> {
*/
uint32_t get_page_size() const;

/** Get the flash erase value
*
* Get the value we read after erase operation
* @return flash erase value
*/
uint8_t get_erase_value() const;

private:

/* Check if address and size are aligned to a sector
Expand Down
7 changes: 7 additions & 0 deletions hal/TARGET_FLASH_CMSIS_ALGO/flash_common_algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,11 @@ MBED_NONSECURE_ENTRY uint32_t flash_get_size(const flash_t *obj)
return obj->target_config->flash_size;
}

MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif // #ifndef DOMAIN_NS
7 changes: 7 additions & 0 deletions hal/flash_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ uint32_t flash_get_start_address(const flash_t *obj);
*/
uint32_t flash_get_size(const flash_t *obj);

/** Get the flash erase value
*
* @param obj The flash object
* @return The flash erase value
*/
uint8_t flash_get_erase_value(const flash_t *obj);

/**@}*/

#ifdef __cplusplus
Expand Down
7 changes: 7 additions & 0 deletions targets/TARGET_ARM_FM/TARGET_FVP_MPS2/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)

return ZBT_SRAM1_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}
7 changes: 7 additions & 0 deletions targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)

return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}
7 changes: 7 additions & 0 deletions targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ uint32_t flash_get_size(const flash_t *obj)
return CY_FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif // DEVICE_FLASH
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,11 @@ uint32_t flash_get_size(const flash_t *obj)
#endif
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ uint32_t flash_get_start_address(const flash_t *obj)
return 0;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif

/** @}*/
7 changes: 7 additions & 0 deletions targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,11 @@ uint32_t flash_get_start_address(const flash_t *obj)
return 0;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
8 changes: 8 additions & 0 deletions targets/TARGET_NUVOTON/TARGET_M2351/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,12 @@ void flash_set_target_config(flash_t *obj)
}

#endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)

MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif // #if DEVICE_FLASH
7 changes: 7 additions & 0 deletions targets/TARGET_NXP/TARGET_LPC176X/device/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ uint32_t flash_get_size(const flash_t *obj)
return 0x80000;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
8 changes: 8 additions & 0 deletions targets/TARGET_RENESAS/TARGET_RZ_A1XX/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,12 @@ static void cache_control(void)
__DSB(); // ensure completion of the invalidation
__ISB(); // ensure instruction fetch path sees new I cache state
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F0/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F1/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F2/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F3/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F4/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32F7/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L0/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L1/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
7 changes: 7 additions & 0 deletions targets/TARGET_STM/TARGET_STM32L4/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif
12 changes: 12 additions & 0 deletions targets/TARGET_Silicon_Labs/TARGET_EFM32/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,16 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE;
}

/** Get the flash erase value
*
* @param obj The flash object
* @return The flash erase value
*/
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

#endif // DEVICE_FLASH
11 changes: 11 additions & 0 deletions targets/TARGET_TOSHIBA/TARGET_TMPM46B/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,14 @@ uint32_t flash_get_size(const flash_t *obj)
{
return FLASH_CHIP_SIZE;
}

#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma location = "FLASH_ROM"
#endif
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;

return 0xFF;
}

Loading

0 comments on commit 3046e31

Please sign in to comment.