31
31
32
32
#include "py/runtime.h"
33
33
#include "src/rp2_common/hardware_flash/include/hardware/flash.h"
34
+ #include "shared-bindings/microcontroller/__init__.h"
34
35
35
36
extern uint32_t __flash_binary_start ;
36
37
static const uint32_t flash_binary_start = (uint32_t )& __flash_binary_start ;
@@ -45,13 +46,19 @@ static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_
45
46
// Write a whole page to flash, buffering it first and then erasing and rewriting it
46
47
// since we can only write a whole page at a time.
47
48
if (offset == 0 && len == FLASH_PAGE_SIZE ) {
49
+ // disable interrupts to prevent core hang on rp2040
50
+ common_hal_mcu_disable_interrupts ();
48
51
flash_range_program (RMV_OFFSET (page_addr ), bytes , FLASH_PAGE_SIZE );
52
+ common_hal_mcu_enable_interrupts ();
49
53
} else {
50
54
uint8_t buffer [FLASH_PAGE_SIZE ];
51
55
memcpy (buffer , (uint8_t * )page_addr , FLASH_PAGE_SIZE );
52
56
memcpy (buffer + offset , bytes , len );
57
+ common_hal_mcu_disable_interrupts ();
53
58
flash_range_program (RMV_OFFSET (page_addr ), buffer , FLASH_PAGE_SIZE );
59
+ common_hal_mcu_enable_interrupts ();
54
60
}
61
+
55
62
}
56
63
57
64
static void erase_and_write_sector (uint32_t address , uint32_t len , uint8_t * bytes ) {
@@ -60,8 +67,11 @@ static void erase_and_write_sector(uint32_t address, uint32_t len, uint8_t *byte
60
67
uint8_t buffer [FLASH_SECTOR_SIZE ];
61
68
memcpy (buffer , (uint8_t * )CIRCUITPY_INTERNAL_NVM_START_ADDR , FLASH_SECTOR_SIZE );
62
69
memcpy (buffer + address , bytes , len );
70
+ // disable interrupts to prevent core hang on rp2040
71
+ common_hal_mcu_disable_interrupts ();
63
72
flash_range_erase (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), FLASH_SECTOR_SIZE );
64
73
flash_range_program (RMV_OFFSET (CIRCUITPY_INTERNAL_NVM_START_ADDR ), buffer , FLASH_SECTOR_SIZE );
74
+ common_hal_mcu_enable_interrupts ();
65
75
}
66
76
67
77
void common_hal_nvm_bytearray_get_bytes (const nvm_bytearray_obj_t * self ,
0 commit comments