@@ -43,31 +43,32 @@ uint32_t common_hal_nvm_bytearray_get_length(const nvm_bytearray_obj_t *self) {
43
43
}
44
44
45
45
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
-
49
46
// Write a whole page to flash, buffering it first and then erasing and rewriting it
50
47
// since we can only write a whole page at a time.
51
48
if (offset == 0 && len == FLASH_PAGE_SIZE ) {
49
+ // disable interrupts to prevent core hang on rp2040
50
+ common_hal_mcu_disable_interrupts ();
52
51
flash_range_program (RMV_OFFSET (page_addr ), bytes , FLASH_PAGE_SIZE );
52
+ common_hal_mcu_enable_interrupts ();
53
53
} else {
54
54
uint8_t buffer [FLASH_PAGE_SIZE ];
55
55
memcpy (buffer , (uint8_t * )page_addr , FLASH_PAGE_SIZE );
56
56
memcpy (buffer + offset , bytes , len );
57
+ common_hal_mcu_disable_interrupts ();
57
58
flash_range_program (RMV_OFFSET (page_addr ), buffer , FLASH_PAGE_SIZE );
59
+ common_hal_mcu_enable_interrupts ();
58
60
}
59
- common_hal_mcu_enable_interrupts ();
61
+
60
62
}
61
63
62
64
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
-
66
65
// Write a whole sector to flash, buffering it first and then erasing and rewriting it
67
66
// since we can only erase a whole sector at a time.
68
67
uint8_t buffer [FLASH_SECTOR_SIZE ];
69
68
memcpy (buffer , (uint8_t * )CIRCUITPY_INTERNAL_NVM_START_ADDR , FLASH_SECTOR_SIZE );
70
69
memcpy (buffer + address , bytes , len );
70
+ // disable interrupts to prevent core hang on rp2040
71
+ common_hal_mcu_disable_interrupts ();
71
72
flash_range_erase (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), FLASH_SECTOR_SIZE );
72
73
flash_range_program (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), buffer , FLASH_SECTOR_SIZE );
73
74
common_hal_mcu_enable_interrupts ();
0 commit comments