Skip to content

Commit 5d2b60c

Browse files
committed
Redo RP2040 flash settings
This switches stage2 to C and uses Jinja to change the C code based on flash settings from https://github.com/adafruit/nvm.toml. It produces the fastest settings for the given set of external flashes. Flash size is no longer hard coded so switching flashes with similar capabilities but different sizes should *just work*. This PR also places "ITCM" code in RAM to save the XIP cache for code execution. Further optimization is possible. A blink code.py still requires a number of flash fetches every blink. Fixes #4041
1 parent 2589515 commit 5d2b60c

File tree

31 files changed

+411
-65
lines changed

31 files changed

+411
-65
lines changed

.gitmodules

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,8 @@
173173
url = https://github.com/adafruit/Adafruit_CircuitPython_LC709203F
174174
[submodule "ports/raspberrypi/sdk"]
175175
path = ports/raspberrypi/sdk
176-
url = https://github.com/raspberrypi/pico-sdk.git
176+
url = https://github.com/adafruit/pico-sdk.git
177+
[submodule "data/nvm.toml"]
178+
path = data/nvm.toml
179+
url = https://github.com/adafruit/nvm.toml.git
180+
branch = main

data/nvm.toml

Submodule nvm.toml added at da50547

ports/raspberrypi/Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ INC += -I. \
106106
-I$(BUILD)
107107

108108
# Pico specific configuration
109-
CFLAGS += -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0
109+
CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=1 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0
110110
OPTIMIZATION_FLAGS ?= -O3
111111
# TinyUSB defines
112112
CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024
@@ -169,7 +169,7 @@ SRC_SDK := \
169169
src/rp2_common/hardware_irq/irq.c \
170170
src/rp2_common/hardware_pio/pio.c \
171171
src/rp2_common/hardware_pll/pll.c \
172-
src/rp2_common/hardware_rtc/rtc.c \
172+
src/rp2_common/hardware_rtc/rtc.c \
173173
src/rp2_common/hardware_spi/spi.c \
174174
src/rp2_common/hardware_sync/sync.c \
175175
src/rp2_common/hardware_timer/timer.c \
@@ -270,9 +270,15 @@ $(BUILD)/boot2.bin: $(BUILD)/boot2.elf
270270
$(STEPECHO) "OBJCOPY $<"
271271
$(Q)$(OBJCOPY) -O binary $< $@
272272

273-
$(BUILD)/boot2.elf: $(BOOT2_S_UPPER) | $(BUILD)/
273+
274+
$(BUILD)/stage2.c: stage2.c.jinja gen_stage2.py | $(BUILD)/
275+
$(STEPECHO) "GEN $<"
276+
$(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES)
277+
278+
$(BUILD)/boot2.elf: $(BUILD)/stage2.c
274279
$(STEPECHO) "BOOT $<"
275-
$(Q)$(CC) $(CFLAGS) $(BOOT2_S_CFLAGS) -Isdk/src/rp2_common/boot_stage2/asminclude --specs=nosys.specs -nostartfiles -Wl,-T,sdk/src/rp2_common/boot_stage2/boot_stage2.ld -o $@ $<
280+
$(Q)$(CC) $(CFLAGS) $(BOOT2_S_CFLAGS) -Os -ggdb3 -I. -fPIC --specs=nosys.specs -nostartfiles -Wl,-T,boot_stage2.ld -Wl,-Map=$@.map -o $@ $<
281+
$(Q)$(SIZE) $@
276282

277283
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
278284

@@ -285,7 +291,7 @@ $(BUILD)/firmware.elf: $(OBJ) link.ld
285291

286292
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
287293
$(STEPECHO) "Create $@"
288-
$(Q)$(OBJCOPY) -O binary $^ $@
294+
$(Q)$(OBJCOPY) -O binary -R .dtcm_bss $^ $@
289295

290296
$(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
291297
$(STEPECHO) "Create $@"

ports/raspberrypi/boards/adafruit_feather_rp2040/mpconfigboard.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,3 @@
1212

1313
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
1414
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)
15-
16-
// Flash chip is GD25Q64 connected over QSPI
17-
#define TOTAL_FLASH_SIZE (8 * 1024 * 1024)

ports/raspberrypi/boards/adafruit_feather_rp2040/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ USB_MANUFACTURER = "Adafruit"
66
CHIP_VARIANT = RP2040
77
CHIP_FAMILY = rp2
88

9-
INTERNAL_FLASH_FILESYSTEM = 1
9+
EXTERNAL_FLASH_DEVICES = "GD25Q64C"

ports/raspberrypi/boards/pimoroni_keybow2040/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
2929
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)
3030

31-
#define TOTAL_FLASH_SIZE (2 * 1024 * 1024)
32-
3331
// These pins are unconnected
3432
#define IGNORE_PIN_GPIO2 1
3533
#define IGNORE_PIN_GPIO22 1

ports/raspberrypi/boards/pimoroni_keybow2040/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ USB_MANUFACTURER = "Pimoroni"
66
CHIP_VARIANT = RP2040
77
CHIP_FAMILY = rp2
88

9-
INTERNAL_FLASH_FILESYSTEM = 1
9+
EXTERNAL_FLASH_DEVICES = "W25Q16JV_IQ"
1010

1111
CIRCUITPY__EVE = 1

ports/raspberrypi/boards/pimoroni_picosystem/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
3939
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)
4040

41-
#define TOTAL_FLASH_SIZE (16 * 1024 * 1024)
42-
4341
// These pins are unconnected
4442
#define IGNORE_PIN_GPIO3 1
4543
#define IGNORE_PIN_GPIO10 1

ports/raspberrypi/boards/pimoroni_picosystem/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ USB_MANUFACTURER = "Pimoroni"
66
CHIP_VARIANT = RP2040
77
CHIP_FAMILY = rp2
88

9-
INTERNAL_FLASH_FILESYSTEM = 1
9+
EXTERNAL_FLASH_DEVICES = "W25Q128JV_IQ"
1010

1111
CIRCUITPY__EVE = 1

ports/raspberrypi/boards/pimoroni_tiny2040/mpconfigboard.h

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

88
#define MICROPY_HW_USER_SW (&pin_GPIO23)
99

10-
#define TOTAL_FLASH_SIZE (8 * 1024 * 1024)
11-
1210
// These pins are unconnected
1311
#define IGNORE_PIN_GPIO8 1
1412
#define IGNORE_PIN_GPIO9 1

0 commit comments

Comments
 (0)