Skip to content

Commit 83dad37

Browse files
committed
Fixups for #1042
1 parent 02dd32d commit 83dad37

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

ports/nrf/common-hal/microcontroller/__init__.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,9 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
7474
.base = {
7575
.type = &nvm_bytearray_type,
7676
},
77-
.len = CIRCUITPY_INTERNAL_NVM_SIZE,
78-
.start_address = FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE
7977
};
8078
#endif
8179

82-
8380
STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = {
8481
{ MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) },
8582
{ MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) },

ports/nrf/peripherals/nrf/nvm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#define FLASH_PAGE_SIZE (4096)
29+
30+
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
31+
#define CIRCUITPY_INTERNAL_NVM_SIZE (0)
32+
#endif
33+
2834
void nrf_nvm_safe_flash_page_write(uint32_t page_addr, uint8_t *data);

ports/nrf/supervisor/internal_flash.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,21 @@ uint32_t supervisor_flash_get_block_size(void) {
6767
}
6868

6969
uint32_t supervisor_flash_get_block_count(void) {
70-
return ((uint32_t) __fatfs_flash_length - CIRCUITPY_INTERNVAL_NVM_SIZE) / FILESYSTEM_BLOCK_SIZE ;
70+
return ((uint32_t) __fatfs_flash_length - CIRCUITPY_INTERNAL_NVM_SIZE) / FILESYSTEM_BLOCK_SIZE ;
71+
}
72+
73+
void supervisor_flash_flush(void) {
74+
if (_flash_page_addr == NO_CACHE) return;
75+
76+
// Skip if data is the same
77+
if (memcmp(_flash_cache, (void *)_flash_page_addr, FLASH_PAGE_SIZE) != 0) {
78+
nrf_nvm_safe_flash_page_write(_flash_page_addr, _flash_cache);
79+
}
7180
}
7281

7382
mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {
7483
// Must write out anything in cache before trying to read.
75-
nrf_nvm_safe_flash_page_write(_flash_page_addr, _flash_cache);
76-
_flash_page_addr = NO_CACHE;
84+
supervisor_flash_flush();
7785

7886
uint32_t src = lba2addr(block);
7987
memcpy(dest, (uint8_t*) src, FILESYSTEM_BLOCK_SIZE*num_blocks);
@@ -107,3 +115,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
107115

108116
return 0; // success
109117
}
118+
119+
void supervisor_flash_release_cache(void) {
120+
}
121+

ports/nrf/supervisor/internal_flash.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
#include "py/mpconfig.h"
3333

34-
#define FLASH_PAGE_SIZE 0x1000
35-
3634
#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms
3735
#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2)
3836

0 commit comments

Comments
 (0)