Skip to content

Commit a800c20

Browse files
committed
only write half page flash for nrf52840 as walkaround
1 parent 9a4d94f commit a800c20

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

cores/nRF5/flash/flash_nrf5x.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,38 @@ static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
127127
{
128128
cprintf("Programming 0x%08X\n", dst);
129129

130-
// try again if busy
130+
// wait for async event if SD is enabled
131+
uint8_t sd_en = 0;
132+
(void) sd_softdevice_is_enabled(&sd_en);
133+
131134
uint32_t err;
132-
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len / 4)) )
135+
136+
// Somehow S140 v6.1.0 assert an error when writing a whole page
137+
// https://devzone.nordicsemi.com/f/nordic-q-a/40088/sd_flash_write-cause-nrf_fault_id_sd_assert
138+
// Workaround: write half page at a time.
139+
#if NRF52832_XXAA
140+
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len/4)) )
133141
{
134142
delay(1);
135143
}
136144
VERIFY_STATUS(err, 0);
137145

138-
// wait for async event if SD is enabled
139-
uint8_t sd_en = 0;
140-
(void) sd_softdevice_is_enabled(&sd_en);
146+
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
147+
#else
148+
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len/8)) )
149+
{
150+
delay(1);
151+
}
152+
VERIFY_STATUS(err, 0);
153+
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
141154

155+
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) (dst+ len/2), (uint32_t const *) (src + len/2), len/8)) )
156+
{
157+
delay(1);
158+
}
159+
VERIFY_STATUS(err, 0);
142160
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
161+
#endif
143162

144163
return len;
145164
}

0 commit comments

Comments
 (0)