Skip to content

Commit 7fbc3ec

Browse files
committed
nRF52: Don't break out of flash erase/writes if interrupted (Ctrl-C) - these shouldn't take too long and can corrupt data if interruptable
Also fix regression on unaligned writes 2 commits ago, and fix some compiler warnings!
1 parent c7d20e9 commit 7fbc3ec

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- The default Nordic UART scan response will be removed in future to reduce power usage
4949
nRF52: Ensure that if enabled the HID service gets added to the main advertising packet (#2631)
5050
nRF52: Fix unreliable internal flash writes when writing >2k (big issue for compaction) (fix #2509)
51+
nRF52: Don't break out of flash erase/writes if interrupted (Ctrl-C) - these shouldn't take too long and can corrupt data if interruptable
5152

5253
2v25 : ESP32C3: Get analogRead working correctly
5354
Graphics: Adjust image alignment when rotating images to avoid cropping (fix #2535)

targets/nrf5x/jshardware.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ bool jshFlashErasePages(uint32_t addr, uint32_t byteLength) {
24732473
jshFlashWriteProtect(startAddr + byteLength - 1))
24742474
return false;
24752475
uint32_t err;
2476-
while (byteLength>=4096 && !jspIsInterrupted()) {
2476+
while (byteLength>=4096) {
24772477
flashIsBusy = true;
24782478
while ((err = sd_flash_page_erase(startAddr / NRF_FICR->CODEPAGESIZE)) == NRF_ERROR_BUSY);
24792479
if (err!=NRF_SUCCESS) flashIsBusy = false;
@@ -2487,7 +2487,7 @@ bool jshFlashErasePages(uint32_t addr, uint32_t byteLength) {
24872487
jshKickWatchDog();
24882488
jshKickSoftWatchDog();
24892489
}
2490-
return !jspIsInterrupted();
2490+
return true;
24912491
}
24922492

24932493
/**
@@ -2644,23 +2644,23 @@ void jshFlashWrite(void * buf, uint32_t addr, uint32_t len) {
26442644
uint8_t *wrbuf = (uint8_t*)buf; // source, we increment this as we write
26452645
uint8_t alignedBuf[32]; // aligned buffer if writes need it (misaligned source)
26462646

2647-
while (wrlen>0 && !jspIsInterrupted()) {
2647+
while (wrlen>0) {
26482648
uint32_t l = wrlen;
26492649
uint8_t *awrbuf = wrbuf; // write buffer pointer (always updated to be aligned)
26502650
#ifdef NRF51_SERIES
26512651
if (l>1024) l=1024; // max write size
26522652
#else // SD 6.1.1 doesn't like flash ops that take too long so we must not write the full 4096 (probably a good plan on older SD too)
26532653
if (l>2048) l=2048; // max write size
26542654
#endif
2655-
if ((size_t)wrbuf & 3) {
2655+
if (((size_t)wrbuf) & 3) {
26562656
// Unaligned *SOURCE* is a problem on nRF5x, so if so we are unaligned, do a whole bunch of tiny writes via a buffer
26572657
if (l>sizeof(alignedBuf)) l=sizeof(alignedBuf); // max write size
26582658
memcpy(alignedBuf, wrbuf, l);
2659-
awrbuf = wrbuf;
2659+
awrbuf = alignedBuf;
26602660
}
26612661

26622662
flashIsBusy = true;
2663-
while ((err = sd_flash_write(wraddr, awrbuf, l>>2)) == NRF_ERROR_BUSY && !jspIsInterrupted());
2663+
while ((err = sd_flash_write((uint32_t*)wraddr, (uint32_t*)awrbuf, l>>2)) == NRF_ERROR_BUSY);
26642664
if (err!=NRF_SUCCESS) flashIsBusy = false;
26652665
WAIT_UNTIL(!flashIsBusy, "jshFlashWrite");
26662666
wrlen -= l;
@@ -2964,12 +2964,12 @@ void COMP_LPCOMP_IRQHandler() {
29642964
if (nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_UP) && nrf_lpcomp_int_enable_check(LPCOMP_INTENSET_UP_Msk)) {
29652965
nrf_lpcomp_event_clear(NRF_LPCOMP_EVENT_UP);
29662966
IOCustomEventFlags customFlags = EVC_LPCOMP | EVC_DATA_LPCOMP_UP;
2967-
jshPushEvent(EV_CUSTOM, &customFlags, sizeof(customFlags));
2967+
jshPushEvent(EV_CUSTOM, (uint8_t*)&customFlags, sizeof(customFlags));
29682968
}
29692969
if (nrf_lpcomp_event_check(NRF_LPCOMP_EVENT_DOWN) && nrf_lpcomp_int_enable_check(LPCOMP_INTENSET_DOWN_Msk)) {
29702970
nrf_lpcomp_event_clear(NRF_LPCOMP_EVENT_DOWN);
29712971
IOCustomEventFlags customFlags = EVC_LPCOMP;
2972-
jshPushEvent(EV_CUSTOM, &customFlags, sizeof(customFlags));
2972+
jshPushEvent(EV_CUSTOM, (uint8_t*)&customFlags, sizeof(customFlags));
29732973
}
29742974
}
29752975

@@ -3028,4 +3028,4 @@ bool jshSetComparator(Pin pin, JsVarFloat level) {
30283028
nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_START);
30293029
return true;
30303030
}
3031-
#endif
3031+
#endif

0 commit comments

Comments
 (0)