Skip to content

Commit 041885d

Browse files
authored
Merge pull request #7011 from jepler/pico-w-resize-circuitpy-again
switch flash split to leave 512kB for CIRCUITPY
2 parents c7f6303 + 644d293 commit 041885d

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323

2424
MEMORY
2525
{
26-
FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1788k
26+
FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k
27+
/* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */
2728
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k
2829
SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k
2930
SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k

ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ CIRCUITPY_WIFI = 1
2121

2222
CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0
2323
# Must be accompanied by a linker script change
24-
CFLAGS += -DRESERVED_FLASH='(1792 * 1024)'
24+
CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)'

ports/raspberrypi/link.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
MEMORY
2525
{
2626
FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1020k
27+
/* Followed by: 4kB of NVRAM and at least 1024kB of CIRCUITPY */
2728
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k
2829
SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k
2930
SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k

ports/raspberrypi/mpconfigport.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@
3131

3232
#define MICROPY_PY_SYS_PLATFORM "RP2040"
3333

34+
// Setting a non-default value also requires a non-default link.ld
35+
#ifndef CIRCUITPY_FIRMWARE_SIZE
36+
#define CIRCUITPY_FIRMWARE_SIZE (1020 * 1024)
37+
#endif
38+
3439
#define CIRCUITPY_INTERNAL_NVM_SIZE (4 * 1024)
35-
#define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x100FF000)
40+
// This is the XIP address
41+
#define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x10000000 + CIRCUITPY_FIRMWARE_SIZE)
3642

43+
// This is the flash linear address
44+
#define CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR (CIRCUITPY_FIRMWARE_SIZE + CIRCUITPY_INTERNAL_NVM_SIZE)
3745
#define CIRCUITPY_DEFAULT_STACK_SIZE (24 * 1024)
3846

3947
#define MICROPY_USE_INTERNAL_PRINTF (1)

ports/raspberrypi/supervisor/internal_flash.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
#include "src/rp2_common/hardware_flash/include/hardware/flash.h"
4747
#include "src/common/pico_binary_info/include/pico/binary_info.h"
4848

49-
#if !defined(RESERVED_FLASH)
50-
#define RESERVED_FLASH (1 * 1024 * 1024)
51-
#endif
52-
5349
#if !defined(TOTAL_FLASH_MINIMUM)
5450
#define TOTAL_FLASH_MINIMUM (2 * 1024 * 1024)
5551
#endif
@@ -65,8 +61,8 @@ void supervisor_flash_init(void) {
6561
bi_decl_if_func_used(bi_block_device(
6662
BINARY_INFO_MAKE_TAG('C', 'P'),
6763
"CircuitPython",
68-
RESERVED_FLASH,
69-
TOTAL_FLASH_MINIMUM - RESERVED_FLASH, // This is a minimum. We can't set it dynamically.
64+
CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR,
65+
TOTAL_FLASH_MINIMUM - CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR, // This is a minimum. We can't set it dynamically.
7066
NULL,
7167
BINARY_INFO_BLOCK_DEV_FLAG_READ |
7268
BINARY_INFO_BLOCK_DEV_FLAG_WRITE |
@@ -92,23 +88,23 @@ uint32_t supervisor_flash_get_block_size(void) {
9288
}
9389

9490
uint32_t supervisor_flash_get_block_count(void) {
95-
return (_flash_size - RESERVED_FLASH) / FILESYSTEM_BLOCK_SIZE;
91+
return (_flash_size - CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR) / FILESYSTEM_BLOCK_SIZE;
9692
}
9793

9894
void port_internal_flash_flush(void) {
9995
if (_cache_lba == NO_CACHE) {
10096
return;
10197
}
10298
common_hal_mcu_disable_interrupts();
103-
flash_range_erase(RESERVED_FLASH + _cache_lba, SECTOR_SIZE);
104-
flash_range_program(RESERVED_FLASH + _cache_lba, _cache, SECTOR_SIZE);
99+
flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, SECTOR_SIZE);
100+
flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, _cache, SECTOR_SIZE);
105101
common_hal_mcu_enable_interrupts();
106102
_cache_lba = NO_CACHE;
107103
}
108104

109105
mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) {
110106
memcpy(dest,
111-
(void *)(XIP_BASE + RESERVED_FLASH + block * FILESYSTEM_BLOCK_SIZE),
107+
(void *)(XIP_BASE + CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + block * FILESYSTEM_BLOCK_SIZE),
112108
num_blocks * FILESYSTEM_BLOCK_SIZE);
113109
return 0;
114110
}
@@ -123,7 +119,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
123119

124120
if (_cache_lba != block_address) {
125121
memcpy(_cache,
126-
(void *)(XIP_BASE + RESERVED_FLASH + sector_offset),
122+
(void *)(XIP_BASE + CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset),
127123
SECTOR_SIZE);
128124
_cache_lba = sector_offset;
129125
}
@@ -139,8 +135,8 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32
139135
}
140136
// Make sure we don't have an interrupt while we do flash operations.
141137
common_hal_mcu_disable_interrupts();
142-
flash_range_erase(RESERVED_FLASH + sector_offset, SECTOR_SIZE);
143-
flash_range_program(RESERVED_FLASH + sector_offset, _cache, SECTOR_SIZE);
138+
flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset, SECTOR_SIZE);
139+
flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + sector_offset, _cache, SECTOR_SIZE);
144140
common_hal_mcu_enable_interrupts();
145141
}
146142

0 commit comments

Comments
 (0)