10000 Fix FreeRTOS Flash Freeze, Fastly (#2486) · marklove5102/arduino-pico@a6ab6e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a6ab6e1

Browse files
Fix FreeRTOS Flash Freeze, Fastly (earlephilhower#2486)
Fixes earlephilhower#2485
1 parent b2ec6ec commit a6ab6e1

File tree

7 files changed

+68
-15
lines changed

7 files changed

+68
-15
lines changed

cores/rp2040/Bootsel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() {
2626

2727
// Must disable interrupts, as interrupt handlers may be in flash, and we
2828
// are about to temporarily disable flash access!
29-
noInterrupts();
29+
if (!__isFreeRTOS) {
30+
noInterrupts();
31+
}
3032
rp2040.idleOtherCore();
3133

3234
// Set chip select to Hi-Z
@@ -53,7 +55,9 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() {
5355
IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_BITS);
5456

5557
rp2040.resumeOtherCore();
56-
interrupts();
58+
if (!__isFreeRTOS) {
59+
interrupts();
60+
}
5761

5862
return button_state;
5963
}

cores/rp2040/sdkoverride/btstack_flash_bank.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ static uint32_t pico_flash_bank_get_alignment(void * context) {
4949
static void pico_flash_bank_erase(void * context, int bank) {
5050
(void)(context);
5151
DEBUG_PRINT("erase: bank %d\n", bank);
52-
noInterrupts();
52+
if (!__isFreeRTOS) {
53+
noInterrupts();
54+
}
5355
rp2040.idleOtherCore();
5456
flash_range_erase(PICO_FLASH_BANK_STORAGE_OFFSET + (PICO_FLASH_BANK_SIZE * bank), PICO_FLASH_BANK_SIZE);
5557
rp2040.resumeOtherCore();
56-
interrupts();
58+
if (!__isFreeRTOS) {
59+
interrupts();
60+
}
5761
}
5862

5963
static void pico_flash_bank_read(void *context, int bank, uint32_t offset, uint8_t *buffer, uint32_t size) {
@@ -147,11 +151,15 @@ static void pico_flash_bank_write(void * context, int bank, uint32_t offset, con
147151
offset = 0;
148152

149153
// Now program the entire page
150-
noInterrupts();
154+
if (!__isFreeRTOS) {
155+
noInterrupts();
156+
}
151157
rp2040.idleOtherCore();
152158
flash_range_program(bank_start_pos + (page * FLASH_PAGE_SIZE), page_data, FLASH_PAGE_SIZE);
153159
rp2040.resumeOtherCore();
154-
interrupts();
160+
if (!__isFreeRTOS) {
161+
interrupts();
162+
}
155163
}
156164
}
157165

libraries/EEPROM/src/EEPROM.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,16 @@ bool EEPROMClass::commit() {
118118
return false;
119119
}
120120

121-
noInterrupts();
121+
if (!__isFreeRTOS) {
122+
noInterrupts();
123+
}
122124
rp2040.idleOtherCore();
123125
flash_range_erase((intptr_t)_sector - (intptr_t)XIP_BASE, 4096);
124126
flash_range_program((intptr_t)_sector - (intptr_t)XIP_BASE, _data, _size);
125127
rp2040.resumeOtherCore();
126-
interrupts();
128+
if (!__isFreeRTOS) {
129+
interrupts();
130+
}
127131
_dirty = false;
128132

129133
return true;

libraries/FatFS/lib/SPIFTL

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <Arduino.h>
2+
#include <FreeRTOS.h>
3+
#include "LittleFS.h"
4+
5+
void setup() {
6+
pinMode(LED_BUILTIN, OUTPUT);
7+
digitalWrite(LED_BUILTIN, LOW);
8+
LittleFS.format();
9+
}
10+
11+
void setup1() {
12+
}
13+
14+
void loop() {
15+
digitalWrite(LED_BUILTIN, HIGH);
16+
delay(200);
17+
}
18+
19+
int x = 0;
20+
void loop1() {
21+
delay(100);
22+
digitalWrite(LED_BUILTIN, LOW);
23+
delay(100);
24+
Serial.printf("%d\n", x++);
25+
}

libraries/LittleFS/src/LittleFS.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,32 @@ int LittleFSImpl::lfs_flash_prog(const struct lfs_config *c,
182182
lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
183183
LittleFSImpl *me = reinterpret_cast<LittleFSImpl*>(c->context);
184184
uint8_t *addr = me->_start + (block * me->_blockSize) + off;
185-
noInterrupts();
185+
if (!__isFreeRTOS) {
186+
noInterrupts();
187+
}
186188
rp2040.idleOtherCore();
187189
// Serial.printf("WRITE: %p, $d\n", (intptr_t)addr - (intptr_t)XIP_BASE, size);
188190
flash_range_program((intptr_t)addr - (intptr_t)XIP_BASE, (const uint8_t *)buffer, size);
189191
rp2040.resumeOtherCore();
190-
interrupts();
192+
if (!__isFreeRTOS) {
193+
interrupts();
194+
}
191195
return 0;
192196
}
193197

194198
int LittleFSImpl::lfs_flash_erase(const struct lfs_config *c, lfs_block_t block) {
195199
LittleFSImpl *me = reinterpret_cast<LittleFSImpl*>(c->context);
196200
uint8_t *addr = me->_start + (block * me->_blockSize);
197201
// Serial.printf("ERASE: %p, %d\n", (intptr_t)addr - (intptr_t)XIP_BASE, me->_blockSize);
198-
noInterrupts();
202+
if (!__isFreeRTOS) {
203+
noInterrupts();
204+
}
199205
rp2040.idleOtherCore();
200206
flash_range_erase((intptr_t)addr - (intptr_t)XIP_BASE, me->_blockSize);
201207
rp2040.resumeOtherCore();
202-
interrupts();
208+
if (!__isFreeRTOS) {
209+
interrupts();
210+
}
203211
return 0;
204212
}
205213

libraries/Updater/src/Updater.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,16 @@ bool UpdaterClass::_writeBuffer() {
291291
return false;
292292
}
293293
} else {
294-
noInterrupts();
294+
if (!__isFreeRTOS) {
295+
noInterrupts();
296+
}
295297
rp2040.idleOtherCore();
296298
flash_range_erase((intptr_t)_currentAddress - (intptr_t)XIP_BASE, 4096);
297299
flash_range_program((intptr_t)_currentAddress - (intptr_t)XIP_BASE, _buffer, 4096);
298300
rp2040.resumeOtherCore();
299-
interrupts();
301+
if (!__isFreeRTOS) {
302+
interrupts();
303+
}
300304
}
301305
if (!_verify) {
302306
_md5.add(_buffer, _bufferLen);

0 commit comments

Comments
 (0)
0