@@ -43,6 +43,9 @@ 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
+
46
49
// Write a whole page to flash, buffering it first and then erasing and rewriting it
47
50
// since we can only write a whole page at a time.
48
51
if (offset == 0 && len == FLASH_PAGE_SIZE ) {
@@ -53,16 +56,21 @@ static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_
53
56
memcpy (buffer + offset , bytes , len );
54
57
flash_range_program (RMV_OFFSET (page_addr ), buffer , FLASH_PAGE_SIZE );
55
58
}
59
+ common_hal_mcu_enable_interrupts ();
56
60
}
57
61
58
62
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
+
59
66
// Write a whole sector to flash, buffering it first and then erasing and rewriting it
60
67
// since we can only erase a whole sector at a time.
61
68
uint8_t buffer [FLASH_SECTOR_SIZE ];
62
69
memcpy (buffer , (uint8_t * )CIRCUITPY_INTERNAL_NVM_START_ADDR , FLASH_SECTOR_SIZE );
63
70
memcpy (buffer + address , bytes , len );
64
71
flash_range_erase (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), FLASH_SECTOR_SIZE );
65
72
flash_range_program (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), buffer , FLASH_SECTOR_SIZE );
73
+ common_hal_mcu_enable_interrupts ();
66
74
}
67
75
68
76
void common_hal_nvm_bytearray_get_bytes (const nvm_bytearray_obj_t * self ,
@@ -72,8 +80,6 @@ void common_hal_nvm_bytearray_get_bytes(const nvm_bytearray_obj_t *self,
72
80
73
81
bool common_hal_nvm_bytearray_set_bytes (const nvm_bytearray_obj_t * self ,
74
82
uint32_t start_index , uint8_t * values , uint32_t len ) {
75
- // disable interrupts to prevent core hang on rp2040
76
- common_hal_mcu_disable_interrupts ();
77
83
uint8_t values_in [len ];
78
84
common_hal_nvm_bytearray_get_bytes (self , start_index , len , values_in );
79
85
@@ -102,6 +108,5 @@ bool common_hal_nvm_bytearray_set_bytes(const nvm_bytearray_obj_t *self,
102
108
erase_and_write_sector (start_index , len , values );
103
109
}
104
110
105
- common_hal_mcu_enable_interrupts ();
106
111
return true;
107
112
}
0 commit comments