From 7ca686684ea5bffb45764bc3782f54133855a3c9 Mon Sep 17 00:00:00 2001 From: jahr Date: Mon, 5 Apr 2021 22:57:18 +0200 Subject: [PATCH] rp2: Add support for building different board configurations. This change allows to build firmware for different rp2-based boards, following how it is done in other ports like stm32 and esp32. So far only the original Pico and Adafruit Feather RP2040 are added. Board names should match (sans case) those in pico-sdk/src/boards/include/boards/. Usage: Pico firmware can be build either using make as previously (it is the default board) or by `make BOARD=PICO`. Feather is built by `make BOARD=ADAFRUIT_FEATHER_RP2040`. Only the board name and flash drive size is set, pin definition is taken from the appropriate pico-sdk board definition. Firmware is saved in the directory build-BOARD_NAME. --- ports/rp2/CMakeLists.txt | 25 +++++++++++++++++++ ports/rp2/Makefile | 6 +++-- .../mpconfigboard.cmake | 1 + .../ADAFRUIT_FEATHER_RP2040/mpconfigboard.h | 3 +++ ports/rp2/boards/PICO/mpconfigboard.cmake | 1 + ports/rp2/boards/PICO/mpconfigboard.h | 3 +++ ports/rp2/mpconfigport.h | 3 ++- 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.cmake create mode 100644 ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.h create mode 100644 ports/rp2/boards/PICO/mpconfigboard.cmake create mode 100644 ports/rp2/boards/PICO/mpconfigboard.h diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 100a834090..bd3eb74384 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -17,6 +17,30 @@ endif() # Use the local tinyusb instead of the one in pico-sdk set(PICO_TINYUSB_PATH ${MICROPY_DIR}/lib/tinyusb) +# Set the location of this port's directory. +set(MICROPY_PORT_DIR ${CMAKE_SOURCE_DIR}) + +# Set the board if it's not already set. +if(NOT MICROPY_BOARD) + set(MICROPY_BOARD PICO) +endif() + +# Set the PICO_BOARD if it's not already set. +if(NOT PICO_BOARD) + string(TOLOWER ${MICROPY_BOARD} PICO_BOARD) +endif() + +# Set the board directory and check that it exists. +if(NOT MICROPY_BOARD_DIR) + set(MICROPY_BOARD_DIR ${MICROPY_PORT_DIR}/boards/${MICROPY_BOARD}) +endif() +if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake) + message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}") +endif() + +# Include board config +include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake) + # Include component cmake fragments include(${MICROPY_DIR}/py/py.cmake) include(${MICROPY_DIR}/extmod/extmod.cmake) @@ -150,6 +174,7 @@ target_link_libraries(${MICROPY_TARGET} usermod) target_include_directories(${MICROPY_TARGET} PRIVATE ${MICROPY_INC_CORE} ${MICROPY_INC_USERMOD} + ${MICROPY_BOARD_DIR} "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" ) diff --git a/ports/rp2/Makefile b/ports/rp2/Makefile index 3358c4ccae..246f29dd09 100644 --- a/ports/rp2/Makefile +++ b/ports/rp2/Makefile @@ -2,11 +2,13 @@ # # This is a simple wrapper around cmake -BUILD = build +BOARD ?= PICO + +BUILD ?= build-$(BOARD) $(VERBOSE)MAKESILENT = -s -CMAKE_ARGS = +CMAKE_ARGS = -DMICROPY_BOARD=$(BOARD) ifdef USER_C_MODULES CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES} diff --git a/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.cmake b/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.cmake new file mode 100644 index 0000000000..877efa6aba --- /dev/null +++ b/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.cmake @@ -0,0 +1 @@ +# cmake file for Adafruit Feather RP2040 diff --git a/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.h b/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.h new file mode 100644 index 0000000000..5068d35541 --- /dev/null +++ b/ports/rp2/boards/ADAFRUIT_FEATHER_RP2040/mpconfigboard.h @@ -0,0 +1,3 @@ +// Board and hardware specific configuration +#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040" +#define MICROPY_HW_FLASH_STORAGE_BYTES (3072 * 1024) diff --git a/ports/rp2/boards/PICO/mpconfigboard.cmake b/ports/rp2/boards/PICO/mpconfigboard.cmake new file mode 100644 index 0000000000..3a40ca2871 --- /dev/null +++ b/ports/rp2/boards/PICO/mpconfigboard.cmake @@ -0,0 +1 @@ +# cmake file for Raspberry Pi Pico diff --git a/ports/rp2/boards/PICO/mpconfigboard.h b/ports/rp2/boards/PICO/mpconfigboard.h new file mode 100644 index 0000000000..e6623374d0 --- /dev/null +++ b/ports/rp2/boards/PICO/mpconfigboard.h @@ -0,0 +1,3 @@ +// Board and hardware specific configuration +#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico" +#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 6c82d18620..218cd72752 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -31,8 +31,9 @@ #include "hardware/sync.h" #include "pico/binary_info.h" +#include "mpconfigboard.h" + // Board and hardware specific configuration -#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico" #define MICROPY_HW_MCU_NAME "RP2040" #define MICROPY_HW_ENABLE_UART_REPL (0) // useful if there is no USB #define MICROPY_HW_ENABLE_USBDEV (1)