Skip to content

Commit fa37ee6

Browse files
committed
limit disable interrupts to flash calls
1 parent 5e7c132 commit fa37ee6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ports/raspberrypi/common-hal/nvm/ByteArray.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,32 @@ uint32_t common_hal_nvm_bytearray_get_length(const nvm_bytearray_obj_t *self) {
4343
}
4444

4545
static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_t *bytes) {
46-
// disable interrupts to prevent core hang on rp2040
47-
common_hal_mcu_disable_interrupts();
48-
4946
// Write a whole page to flash, buffering it first and then erasing and rewriting it
5047
// since we can only write a whole page at a time.
5148
if (offset == 0 && len == FLASH_PAGE_SIZE) {
49+
// disable interrupts to prevent core hang on rp2040
50+
common_hal_mcu_disable_interrupts();
5251
flash_range_program(RMV_OFFSET(page_addr), bytes, FLASH_PAGE_SIZE);
52+
common_hal_mcu_enable_interrupts();
5353
} else {
5454
uint8_t buffer[FLASH_PAGE_SIZE];
5555
memcpy(buffer, (uint8_t *)page_addr, FLASH_PAGE_SIZE);
5656
memcpy(buffer + offset, bytes, len);
57+
common_hal_mcu_disable_interrupts();
5758
flash_range_program(RMV_OFFSET(page_addr), buffer, FLASH_PAGE_SIZE);
59+
common_hal_mcu_enable_interrupts();
5860
}
59-
common_hal_mcu_enable_interrupts();
61+
6062
}
6163

6264
static void erase_and_write_sector(uint32_t address, uint32_t len, uint8_t *bytes) {
63-
// disable interrupts to prevent core hang on rp2040
64-
common_hal_mcu_disable_interrupts();
65-
6665
// Write a whole sector to flash, buffering it first and then erasing and rewriting it
6766
// since we can only erase a whole sector at a time.
6867
uint8_t buffer[FLASH_SECTOR_SIZE];
6968
memcpy(buffer, (uint8_t *)CIRCUITPY_INTERNAL_NVM_START_ADDR, FLASH_SECTOR_SIZE);
7069
memcpy(buffer + address, bytes, len);
70+
// disable interrupts to prevent core hang on rp2040
71+
common_hal_mcu_disable_interrupts();
7172
flash_range_erase(RMV_OFFSET(CIRCUITPY_INTERNAL_NVM_START_ADDR), FLASH_SECTOR_SIZE);
7273
flash_range_program(RMV_OFFSET(CIRCUITPY_INTERNAL_NVM_START_ADDR), buffer, FLASH_SECTOR_SIZE);
7374
common_hal_mcu_enable_interrupts();

0 commit comments

Comments
 (0)