Skip to content

Commit dbaee83

Browse files
committed
ports/rp2: Per-board linker flash config.
Add per-board flash config to avoid silently overwriting user code on vfs init. Make linker FLASH section reflect board size. Add linker APP section for user code. Add linker FILESYSTEM section for vfs. Add per-board config for FLASH + APP sizes: * MICROPY_HW_FLASH_SIZE_BYTES * MICROPY_HW_APP_SIZE_BYTES Preprocess memmap_mp.ld to load flash config. Signed-off-by: Phil Howard <phil@pimoroni.com>
1 parent d75892c commit dbaee83

File tree

27 files changed

+96
-33
lines changed

27 files changed

+96
-33
lines changed

ports/rp2/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ target_sources(${MICROPY_TARGET} PRIVATE
299299
${MICROPY_SOURCE_LIB}
300300
${MICROPY_SOURCE_DRIVERS}
301301
${MICROPY_SOURCE_PORT}
302+
303+
${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld
302304
)
303305

304306
target_link_libraries(${MICROPY_TARGET} micropy_lib_mbedtls)
@@ -350,26 +352,39 @@ target_compile_definitions(${MICROPY_TARGET} PRIVATE
350352
MICROPY_BUILD_TYPE="${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} ${CMAKE_BUILD_TYPE}"
351353
PICO_NO_BI_STDIO_UART=1 # we call it UART REPL
352354
PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1
355+
MICROPY_HW_FLASH_SIZE_BYTES=${MICROPY_HW_FLASH_SIZE_BYTES}
356+
MICROPY_HW_APP_SIZE_BYTES=${MICROPY_HW_APP_SIZE_BYTES}
353357
)
354358

355359
target_link_libraries(${MICROPY_TARGET}
356360
${PICO_SDK_COMPONENTS}
357361
)
358362

363+
target_link_options(${MICROPY_TARGET} PRIVATE
364+
-Wl,--print-memory-usage
365+
)
366+
359367
if (MICROPY_HW_ENABLE_DOUBLE_TAP)
360368
# Enable double tap reset into bootrom.
361369
target_link_libraries(${MICROPY_TARGET}
362370
pico_bootsel_via_double_reset
363371
)
364372
endif()
365373

374+
add_custom_command(
375+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld
376+
COMMAND ${CMAKE_CXX_COMPILER} -E -x c ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld "-DMICROPY_HW_FLASH_SIZE_BYTES=${MICROPY_HW_FLASH_SIZE_BYTES}" "-DMICROPY_HW_APP_SIZE_BYTES=${MICROPY_HW_APP_SIZE_BYTES}" | grep -v '^\#' > ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld
377+
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld
378+
)
379+
366380
# todo this is a bit brittle, but we want to move a few source files into RAM (which requires
367381
# a linker script modification) until we explicitly add macro calls around the function
368382
# defs to move them into RAM.
369383
if (PICO_ON_DEVICE AND NOT PICO_NO_FLASH AND NOT PICO_COPY_TO_RAM)
370-
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_LIST_DIR}/memmap_mp.ld)
384+
pico_set_linker_script(${MICROPY_TARGET} ${CMAKE_CURRENT_BINARY_DIR}/memmap_mp.ld)
371385
endif()
372386

387+
373388
pico_add_extra_outputs(${MICROPY_TARGET})
374389

375390
add_custom_command(TARGET ${MICROPY_TARGET}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# cmake file for Adafruit Feather RP2040
2+
set(MICROPY_HW_FLASH_SIZE_BYTES "8 * 1024 * 1024")
3+
set(MICROPY_HW_APP_SIZE_BYTES "1 * 1024 * 1024")

ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://learn.adafruit.com/adafruit-feather-rp2040-pico/pinouts
33

44
#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040"
5-
#define MICROPY_HW_FLASH_STORAGE_BYTES (7 * 1024 * 1024)
65

76
#define MICROPY_HW_USB_VID (0x239A)
87
#define MICROPY_HW_USB_PID (0x80F2)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# cmake file for Adafruit ItsyBitsy RP2040
2+
set(MICROPY_HW_FLASH_SIZE_BYTES "8 * 1024 * 1024")
3+
set(MICROPY_HW_APP_SIZE_BYTES "1 * 1024 * 1024")
4+

ports/rp2/boards/ADAFRUIT_ITSYBITSY_RP2040/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://learn.adafruit.com/adafruit-itsybitsy-rp2040/pinouts
33

44
#define MICROPY_HW_BOARD_NAME "Adafruit ItsyBitsy RP2040"
5-
#define MICROPY_HW_FLASH_STORAGE_BYTES (7 * 1024 * 1024)
65

76
#define MICROPY_HW_USB_VID (0x239A)
87
#define MICROPY_HW_USB_PID (0x80FE)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# cmake file for Adafruit QT Py RP2040
2+
set(MICROPY_HW_FLASH_SIZE_BYTES "8 * 1024 * 1024")
3+
set(MICROPY_HW_APP_SIZE_BYTES "1 * 1024 * 1024")
4+

ports/rp2/boards/ADAFRUIT_QTPY_RP2040/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://learn.adafruit.com/adafruit-qt-py-2040/pinouts
33

44
#define MICROPY_HW_BOARD_NAME "Adafruit QT Py RP2040"
5-
#define MICROPY_HW_FLASH_STORAGE_BYTES (7 * 1024 * 1024)
65

76
#define MICROPY_HW_USB_VID (0x239A)
87
#define MICROPY_HW_USB_PID (0x80F8)

ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
# cmake file for Arduino Nano RP2040 Connect.
2+
3+
# This is a 16MB board? Was an 8MB firmware size intentional?
4+
# https://github.com/raspberrypi/pico-sdk/blob/master/src/boards/include/boards/arduino_nano_rp2040_connect.h#L76
5+
set(MICROPY_HW_FLASH_SIZE_BYTES "16 * 1024 * 1024")
6+
set(MICROPY_HW_APP_SIZE_BYTES "8 * 1024 * 1024")
7+
28
set(MICROPY_PY_BLUETOOTH 1)
39
set(MICROPY_BLUETOOTH_NIMBLE 1)
410
set(MICROPY_PY_NETWORK_NINAW10 1)

ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/mpconfigboard.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
// Board and hardware specific configuration
44
#define MICROPY_HW_BOARD_NAME "Arduino Nano RP2040 Connect"
5-
#define MICROPY_HW_FLASH_STORAGE_BYTES (8 * 1024 * 1024)
65

76
// Enable networking and sockets.
87
#define MICROPY_PY_NETWORK (1)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# cmake file
2-
1+
# cmake file for Garatronic PYBStick 26
2+
set(MICROPY_HW_FLASH_SIZE_BYTES "1 * 1024 * 1024")
3+
set(MICROPY_HW_APP_SIZE_BYTES "384 * 1024")
34
set(PICO_BOARD pybstick26_rp2040)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy