Skip to content

Commit 3046e31

Browse files
author
Cruz Monrreal
authored
Merge pull request ARMmbed#8589 from davidsaada/david_flash_erase_value
Support erase value in Flash HAL drivers, FlashIAP and block devices
2 parents 760b074 + 542744d commit 3046e31

File tree

30 files changed

+232
-4
lines changed

30 files changed

+232
-4
lines changed

TESTS/mbed_drivers/flashiap/main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ void flashiap_program_test()
5555
TEST_ASSERT_TRUE(sector_size % page_size == 0);
5656
uint32_t prog_size = std::max(page_size, (uint32_t)8);
5757
uint8_t *data = new uint8_t[prog_size + 2];
58-
for (uint32_t i = 0; i < prog_size + 2; i++) {
59-
data[i] = i;
60-
}
6158

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

68+
uint8_t erase_val = flash_device.get_erase_value();
69+
memset(data, erase_val, prog_size);
70+
71+
uint8_t *data_flashed = new uint8_t[prog_size];
72+
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
73+
uint32_t page_addr = address + i * prog_size;
74+
ret = flash_device.read(data_flashed, page_addr, prog_size);
75+
TEST_ASSERT_EQUAL_INT32(0, ret);
76+
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, prog_size);
77+
}
78+
79+
for (uint32_t i = 0; i < prog_size + 2; i++) {
80+
data[i] = i;
81+
}
7182

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

78-
uint8_t *data_flashed = new uint8_t[prog_size];
7989
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
8090
uint32_t page_addr = address + i * prog_size;
8191
ret = flash_device.read(data_flashed, page_addr, prog_size);

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ bd_size_t FlashIAPBlockDevice::get_erase_size(bd_addr_t addr) const
227227
return erase_size;
228228
}
229229

230+
int FlashIAPBlockDevice::get_erase_value() const
231+
{
232+
if (!_is_initialized) {
233+
return -1;
234+
}
235+
236+
uint8_t erase_val = _flash.get_erase_value();
237+
238+
DEBUG_PRINTF("get_erase_value: %" PRIX8 "\r\n", erase_val);
239+
240+
return erase_val;
241+
}
242+
243+
230244
bd_size_t FlashIAPBlockDevice::size() const
231245
{
232246
DEBUG_PRINTF("size: %" PRIX64 "\r\n", _size);

components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ class FlashIAPBlockDevice : public BlockDevice {
109109
*/
110110
virtual bd_size_t get_erase_size(bd_addr_t addr) const;
111111

112+
/** Get the value of storage when erased
113+
*
114+
* @return The value of storage when erased
115+
*/
116+
virtual int get_erase_value() const;
117+
112118
/** Get the total size of the underlying device
113119
*
114120
* @return Size of the underlying device in bytes

drivers/FlashIAP.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ uint32_t FlashIAP::get_flash_size() const
203203
return flash_get_size(&_flash);
204204
}
205205

206+
uint8_t FlashIAP::get_erase_value() const
207+
{
208+
return flash_get_erase_value(&_flash);
209+
}
210+
206211
}
207212

208213
#endif

drivers/FlashIAP.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class FlashIAP : private NonCopyable<FlashIAP> {
131131
*/
132132
uint32_t get_page_size() const;
133133

134+
/** Get the flash erase value
135+
*
136+
* Get the value we read after erase operation
137+
* @return flash erase value
138+
*/
139+
uint8_t get_erase_value() const;
140+
134141
private:
135142

136143
/* Check if address and size are aligned to a sector

hal/TARGET_FLASH_CMSIS_ALGO/flash_common_algo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,11 @@ MBED_NONSECURE_ENTRY uint32_t flash_get_size(const flash_t *obj)
260260
return obj->target_config->flash_size;
261261
}
262262

263+
MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
264+
{
265+
(void)obj;
266+
267+
return 0xFF;
268+
}
269+
263270
#endif // #ifndef DOMAIN_NS

hal/flash_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ uint32_t flash_get_start_address(const flash_t *obj);
117117
*/
118118
uint32_t flash_get_size(const flash_t *obj);
119119

120+
/** Get the flash erase value
121+
*
122+
* @param obj The flash object
123+
* @return The flash erase value
124+
*/
125+
uint8_t flash_get_erase_value(const flash_t *obj);
126+
120127
/**@}*/
121128

122129
#ifdef __cplusplus

targets/TARGET_ARM_FM/TARGET_FVP_MPS2/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)
101101

102102
return ZBT_SRAM1_SIZE;
103103
}
104+
105+
uint8_t flash_get_erase_value(const flash_t *obj)
106+
{
107+
(void)obj;
108+
109+
return 0xFF;
110+
}

targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)
101101

102102
return FLASH_SIZE;
103103
}
104+
105+
uint8_t flash_get_erase_value(const flash_t *obj)
106+
{
107+
(void)obj;
108+
109+
return 0xFF;
110+
}

targets/TARGET_Cypress/TARGET_PSOC6/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,11 @@ uint32_t flash_get_size(const flash_t *obj)
8282
return CY_FLASH_SIZE;
8383
}
8484

85+
uint8_t flash_get_erase_value(const flash_t *obj)
86+
{
87+
(void)obj;
88+
89+
return 0xFF;
90+
}
91+
8592
#endif // DEVICE_FLASH

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,11 @@ uint32_t flash_get_size(const flash_t *obj)
148148
#endif
149149
}
150150

151+
uint8_t flash_get_erase_value(const flash_t *obj)
152+
{
153+
(void)obj;
154+
155+
return 0xFF;
156+
}
157+
151158
#endif

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ uint32_t flash_get_start_address(const flash_t *obj)
195195
return 0;
196196
}
197197

198+
uint8_t flash_get_erase_value(const flash_t *obj)
199+
{
200+
(void)obj;
201+
202+
return 0xFF;
203+
}
204+
198205
#endif
199206

200207
/** @}*/

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,11 @@ uint32_t flash_get_start_address(const flash_t *obj)
209209
return 0;
210210
}
211211

212+
uint8_t flash_get_erase_value(const flash_t *obj)
213+
{
214+
(void)obj;
215+
216+
return 0xFF;
217+
}
218+
212219
#endif

targets/TARGET_NUVOTON/TARGET_M2351/flash_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,12 @@ void flash_set_target_config(flash_t *obj)
134134
}
135135

136136
#endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
137+
138+
MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
139+
{
140+
(void)obj;
141+
142+
return 0xFF;
143+
}
144+
137145
#endif // #if DEVICE_FLASH

targets/TARGET_NXP/TARGET_LPC176X/device/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ uint32_t flash_get_size(const flash_t *obj)
200200
return 0x80000;
201201
}
202202

203+
uint8_t flash_get_erase_value(const flash_t *obj)
204+
{
205+
(void)obj;
206+
207+
return 0xFF;
208+
}
209+
203210
#endif

targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_LPC/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,11 @@ uint32_t flash_get_size(const flash_t *obj)
122122
return FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES;
123123
}
124124

125+
uint8_t flash_get_erase_value(const flash_t *obj)
126+
{
127+
(void)obj;
128+
129+
return 0xFF;
130+
}
131+
125132
#endif

targets/TARGET_RENESAS/TARGET_RZ_A1XX/flash_api.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,12 @@ static void cache_control(void)
751751
__DSB(); // ensure completion of the invalidation
752752
__ISB(); // ensure instruction fetch path sees new I cache state
753753
}
754+
755+
uint8_t flash_get_erase_value(const flash_t *obj)
756+
{
757+
(void)obj;
758+
759+
return 0xFF;
760+
}
761+
754762
#endif

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_MCU_RTL8195A/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ uint32_t flash_get_size(const flash_t *obj)
6969
return FLASH_SIZE;
7070
}
7171

72+
uint8_t flash_get_erase_value(const flash_t *obj)
73+
{
74+
(void)obj;
75+
76+
return 0xFF;
77+
}
78+

targets/TARGET_STM/TARGET_STM32F0/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
172172
return FLASH_SIZE;
173173
}
174174

175+
uint8_t flash_get_erase_value(const flash_t *obj)
176+
{
177+
(void)obj;
178+
179+
return 0xFF;
180+
}
181+
175182
#endif

targets/TARGET_STM/TARGET_STM32F1/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
172172
return FLASH_SIZE;
173173
}
174174

175+
uint8_t flash_get_erase_value(const flash_t *obj)
176+
{
177+
(void)obj;
178+
179+
return 0xFF;
180+
}
181+
175182
#endif

targets/TARGET_STM/TARGET_STM32F2/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
215215
return sectorsize;
216216
}
217217

218+
uint8_t flash_get_erase_value(const flash_t *obj)
219+
{
220+
(void)obj;
221+
222+
return 0xFF;
223+
}
224+
218225
#endif

targets/TARGET_STM/TARGET_STM32F3/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
172172
return FLASH_SIZE;
173173
}
174174

175+
uint8_t flash_get_erase_value(const flash_t *obj)
176+
{
177+
(void)obj;
178+
179+
return 0xFF;
180+
}
181+
175182
#endif

targets/TARGET_STM/TARGET_STM32F4/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
230230
return sectorsize;
231231
}
232232

233+
uint8_t flash_get_erase_value(const flash_t *obj)
234+
{
235+
(void)obj;
236+
237+
return 0xFF;
238+
}
239+
233240
#endif

targets/TARGET_STM/TARGET_STM32F7/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
265265
return sectorsize;
266266
}
267267

268+
uint8_t flash_get_erase_value(const flash_t *obj)
269+
{
270+
(void)obj;
271+
272+
return 0xFF;
273+
}
274+
268275
#endif

targets/TARGET_STM/TARGET_STM32L0/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,11 @@ uint32_t flash_get_size(const flash_t *obj)
174174
return FLASH_SIZE;
175175
}
176176

177+
uint8_t flash_get_erase_value(const flash_t *obj)
178+
{
179+
(void)obj;
180+
181+
return 0xFF;
182+
}
183+
177184
#endif

targets/TARGET_STM/TARGET_STM32L1/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,11 @@ uint32_t flash_get_size(const flash_t *obj)
171171
return FLASH_SIZE;
172172
}
173173

174+
uint8_t flash_get_erase_value(const flash_t *obj)
175+
{
176+
(void)obj;
177+
178+
return 0xFF;
179+
}
180+
174181
#endif

targets/TARGET_STM/TARGET_STM32L4/flash_api.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,11 @@ uint32_t flash_get_size(const flash_t *obj)
284284
return FLASH_SIZE;
285285
}
286286

287+
uint8_t flash_get_erase_value(const flash_t *obj)
288+
{
289+
(void)obj;
290+
291+
return 0xFF;
292+
}
293+
287294
#endif

targets/TARGET_Silicon_Labs/TARGET_EFM32/flash_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,16 @@ uint32_t flash_get_size(const flash_t *obj)
144144
return FLASH_SIZE;
145145
}
146146

147+
/** Get the flash erase value
148+
*
149+
* @param obj The flash object
150+
* @return The flash erase value
151+
*/
152+
uint8_t flash_get_erase_value(const flash_t *obj)
153+
{
154+
(void)obj;
155+
156+
return 0xFF;
157+
}
158+
147159
#endif // DEVICE_FLASH

targets/TARGET_TOSHIBA/TARGET_TMPM46B/flash_api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@ uint32_t flash_get_size(const flash_t *obj)
162162
{
163163
return FLASH_CHIP_SIZE;
164164
}
165+
166+
#if defined ( __ICCARM__ ) /* IAR Compiler */
167+
#pragma location = "FLASH_ROM"
168+
#endif
169+
uint8_t flash_get_erase_value(const flash_t *obj)
170+
{
171+
(void)obj;
172+
173+
return 0xFF;
174+
}
175+

0 commit comments

Comments
 (0)