Skip to content

Support for RM2 break out boards #16057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions extmod/modbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,24 @@ MP_DEFINE_CONST_OBJ_TYPE(
// Bluetooth object: General
// ----------------------------------------------------------------------------

// Allow the port to add extra parameters
#ifdef MICROPY_PY_BLUETOOTH_OBJ_INIT_ARGS
#define EXTRA_ARGS MICROPY_PY_BLUETOOTH_OBJ_INIT_ARGS
#else
#define EXTRA_ARGS
#endif

MP_WEAK void bluetooth_ble_obj_init(mp_arg_val_t *args) {
}

static mp_obj_t bluetooth_ble_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
(void)type;
(void)n_args;
(void)n_kw;
(void)all_args;
const mp_arg_t allowed_args[] = {
EXTRA_ARGS
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
bluetooth_ble_obj_init(args);

if (MP_STATE_VM(bluetooth) == MP_OBJ_NULL) {
mp_obj_bluetooth_ble_t *o = m_new0(mp_obj_bluetooth_ble_t, 1);
o->base.type = &mp_type_bluetooth_ble;
Expand Down
27 changes: 24 additions & 3 deletions extmod/network_cyw43.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,35 @@ static void network_cyw43_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
);
}

static mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 1, false);
if (n_args == 0 || mp_obj_get_int(args[0]) == MOD_NETWORK_STA_IF) {
// Allow the port to add extra parameters
#ifdef MICROPY_PY_NETWORK_CYW43_OBJ_INIT_ARGS
#define EXTRA_ARGS MICROPY_PY_NETWORK_CYW43_OBJ_INIT_ARGS
#else
#define EXTRA_ARGS
#endif

MP_WEAK void network_cyw43_obj_init(mp_arg_val_t *args) {
}

static mp_obj_t network_cyw43_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_interface, ARG_last };
const mp_arg_t allowed_args[] = {
{ MP_QSTR_interface, MP_ARG_INT, {.u_int = MOD_NETWORK_STA_IF} },
EXTRA_ARGS
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, all_args + n_args);
mp_arg_parse_all(n_args, all_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

network_cyw43_obj_init(args + ARG_last);
if (args[ARG_interface].u_int == MOD_NETWORK_STA_IF) {
return MP_OBJ_FROM_PTR(&network_cyw43_wl_sta);
} else {
return MP_OBJ_FROM_PTR(&network_cyw43_wl_ap);
}
}
#undef EXTRA_ARGS

static mp_obj_t network_cyw43_send_ethernet(mp_obj_t self_in, mp_obj_t buf_in) {
network_cyw43_obj_t *self = MP_OBJ_TO_PTR(self_in);
Expand Down
15 changes: 13 additions & 2 deletions ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ set(MICROPY_SOURCE_QSTR
${CMAKE_BINARY_DIR}/pins_${MICROPY_BOARD}.c
)

if (MICROPY_PY_NETWORK_CYW43)
list(APPEND MICROPY_SOURCE_QSTR
${MICROPY_PORT_DIR}/rp2_init_cyw43.c
)
endif()

set(PICO_SDK_COMPONENTS
boot_bootrom_headers
hardware_adc
Expand Down Expand Up @@ -403,6 +409,7 @@ if (MICROPY_PY_NETWORK_CYW43)

list(APPEND MICROPY_SOURCE_PORT
machine_pin_cyw43.c
rp2_init_cyw43.c
)

target_link_libraries(${MICROPY_TARGET}
Expand Down Expand Up @@ -632,8 +639,12 @@ if(NOT PICO_NUM_EXT_GPIOS)
set(PICO_NUM_EXT_GPIOS 10)
endif()

if(EXISTS "${MICROPY_BOARD_DIR}/pins.csv")
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/pins.csv")
if (NOT PICO_PINS_CSV_NAME)
set(PICO_PINS_CSV_NAME pins.csv)
endif()

if(EXISTS "${MICROPY_BOARD_DIR}/${PICO_PINS_CSV_NAME}")
set(GEN_PINS_BOARD_CSV "${MICROPY_BOARD_DIR}/${PICO_PINS_CSV_NAME}")
set(GEN_PINS_CSV_ARG --board-csv "${GEN_PINS_BOARD_CSV}")
endif()

Expand Down
12 changes: 6 additions & 6 deletions ports/rp2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ ifeq ($(BUILD_VERBOSE),1)
MAKE_ARGS += VERBOSE=1 # Picked up in Makefile generated by CMake
endif

CMAKE_ARGS += -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))"
override CMAKE_ARGS += -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't think it's a good idea to complicate the Makefile by adding override. Combining make and cmake is already tricky enough.

Why exactly is this needed, what were you trying to achieve with it? Can we do it a different way, eg just call cmake directly in such cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the intent is to pass compiler definitions through to a port, effectively skipping the need to change config files? Possibly to optionally build Pico with RM2 support.

We have variants for this, though there are few examples of that in practise. Here's one for switching to a RISCV build: https://github.com/micropython/micropython/tree/master/ports/rp2/boards/SEEED_XIAO_RP2350


ifdef USER_C_MODULES
CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
override CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
endif

ifneq ($(FROZEN_MANIFEST),)
CMAKE_ARGS += -DMICROPY_FROZEN_MANIFEST=${FROZEN_MANIFEST}
override CMAKE_ARGS += -DMICROPY_FROZEN_MANIFEST=${FROZEN_MANIFEST}
endif

ifeq ($(DEBUG),1)
CMAKE_ARGS += -DCMAKE_BUILD_TYPE=Debug
override CMAKE_ARGS += -DCMAKE_BUILD_TYPE=Debug
endif

ifdef BOARD_VARIANT
CMAKE_ARGS += -DMICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
override CMAKE_ARGS += -DMICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
endif

ifdef MICROPY_PREVIEW_VERSION_2
CMAKE_ARGS += -DMICROPY_PREVIEW_VERSION_2=1
override CMAKE_ARGS += -DMICROPY_PREVIEW_VERSION_2=1
endif

HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
Expand Down
7 changes: 7 additions & 0 deletions ports/rp2/boards/RPI_PICO/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is only used if cyw43 is enabled
include("$(PORT_DIR)/boards/manifest.py")

require("bundle-networking")

# Bluetooth
require("aioble")
6 changes: 6 additions & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# cmake file for Raspberry Pi Pico
set(PICO_BOARD "pico")
set(PICO_PLATFORM "rp2040")

if (PICO_CYW43_SUPPORTED)
include(enable_cyw43.cmake)
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
set(PICO_PINS_CSV_NAME pins_cyw43.csv)
endif()
23 changes: 23 additions & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"

#if MICROPY_PY_NETWORK_CYW43
#include "enable_cyw43.h"

// Enable the ability to pass cyw43 pins into WiFi, Bluetooth and Pin constructors
#define CYW43_PIN_WL_DYNAMIC 1
#define CYW43_PIO_CLOCK_DIV_DYNAMIC 1

// Set the default pins to gpios 2-5
#define CYW43_DEFAULT_PIN_WL_REG_ON 2
#define CYW43_DEFAULT_PIN_WL_CS 3
#define CYW43_DEFAULT_PIN_WL_DATA_OUT 4
#define CYW43_DEFAULT_PIN_WL_DATA_IN 4
#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 4
#define CYW43_DEFAULT_PIN_WL_CLOCK 5

// Default pio clock
#define CYW43_PIO_CLOCK_DIV_INT 3

// we have to reduce the flash storage if cyw43 is enabled or else the firmware gets overwritten
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)
#else
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
#endif
31 changes: 31 additions & 0 deletions ports/rp2/boards/RPI_PICO/pins_cyw43.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
GP0,GPIO0
GP1,GPIO1
GP2,GPIO2
GP3,GPIO3
GP4,GPIO4
GP5,GPIO5
GP6,GPIO6
GP7,GPIO7
GP8,GPIO8
GP9,GPIO9
GP10,GPIO10
GP11,GPIO11
GP12,GPIO12
GP13,GPIO13
GP14,GPIO14
GP15,GPIO15
GP16,GPIO16
GP17,GPIO17
GP18,GPIO18
GP19,GPIO19
GP20,GPIO20
GP21,GPIO21
GP22,GPIO22
GP25,GPIO25
GP26,GPIO26
GP27,GPIO27
GP28,GPIO28
LED,GPIO25
WL_GPIO0,EXT_GPIO0
WL_GPIO1,EXT_GPIO1
WL_GPIO2,EXT_GPIO2
7 changes: 7 additions & 0 deletions ports/rp2/boards/RPI_PICO2/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is only used if cyw43 is enabled
include("$(PORT_DIR)/boards/manifest.py")

require("bundle-networking")

# Bluetooth
require("aioble")
6 changes: 6 additions & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ set(PICO_BOARD "pico2")

# To change the gpio count for QFN-80
# set(PICO_NUM_GPIOS 48)

if (PICO_CYW43_SUPPORTED)
include(enable_cyw43.cmake)
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
set(PICO_PINS_CSV_NAME pins_cyw43.csv)
endif()
19 changes: 19 additions & 0 deletions ports/rp2/boards/RPI_PICO2/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico2"
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1024 * 1024)

#if MICROPY_PY_NETWORK_CYW43
#include "enable_cyw43.h"

// Enable the ability to pass cyw43 pins into WiFi, Bluetooth and Pin constructors
#define CYW43_PIN_WL_DYNAMIC 1
#define CYW43_PIO_CLOCK_DIV_DYNAMIC 1

// Set the default pins to gpios 2-5
#define CYW43_DEFAULT_PIN_WL_REG_ON 2
#define CYW43_DEFAULT_PIN_WL_CS 3
#define CYW43_DEFAULT_PIN_WL_DATA_OUT 4
#define CYW43_DEFAULT_PIN_WL_DATA_IN 4
#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 4
#define CYW43_DEFAULT_PIN_WL_CLOCK 5

// Default pio clock
#define CYW43_PIO_CLOCK_DIV_INT 3
#endif
31 changes: 31 additions & 0 deletions ports/rp2/boards/RPI_PICO2/pins_cyw43.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
GP0,GPIO0
GP1,GPIO1
GP2,GPIO2
GP3,GPIO3
GP4,GPIO4
GP5,GPIO5
GP6,GPIO6
GP7,GPIO7
GP8,GPIO8
GP9,GPIO9
GP10,GPIO10
GP11,GPIO11
GP12,GPIO12
GP13,GPIO13
GP14,GPIO14
GP15,GPIO15
GP16,GPIO16
GP17,GPIO17
GP18,GPIO18
GP19,GPIO19
GP20,GPIO20
GP21,GPIO21
GP22,GPIO22
GP25,GPIO25
GP26,GPIO26
GP27,GPIO27
GP28,GPIO28
LED,GPIO25
WL_GPIO0,EXT_GPIO0
WL_GPIO1,EXT_GPIO1
WL_GPIO2,EXT_GPIO2
8 changes: 1 addition & 7 deletions ports/rp2/boards/RPI_PICO2_W/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ set(PICO_BOARD "pico2_w")
# To change the gpio count for QFN-80
# set(PICO_NUM_GPIOS 48)

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)
include(enable_cyw43.cmake)

# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
19 changes: 2 additions & 17 deletions ports/rp2/boards/RPI_PICO2_W/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico 2 W"
#define MICROPY_HW_FLASH_STORAGE_BYTES (PICO_FLASH_SIZE_BYTES - 1536 * 1024)

// Enable networking.
#define MICROPY_PY_NETWORK 1
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "Pico2W"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "Pico2W"

// CYW43 driver configuration.
#define CYW43_USE_SPI (1)
#define CYW43_LWIP (1)
#define CYW43_GPIO (1)
#define CYW43_SPI_PIO (1)

// For debugging mbedtls - also set
// Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose
// #define MODUSSL_MBEDTLS_DEBUG_LEVEL 1

#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT

int mp_hal_is_pin_reserved(int n);
#define MICROPY_HW_PIN_RESERVED(i) mp_hal_is_pin_reserved(i)
#include "enable_cyw43.h"
8 changes: 1 addition & 7 deletions ports/rp2/boards/RPI_PICO_W/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

set(PICO_BOARD "pico_w")

set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)
include(enable_cyw43.cmake)

# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
20 changes: 2 additions & 18 deletions ports/rp2/boards/RPI_PICO_W/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
// todo: We need something to check our binary size
#define MICROPY_HW_FLASH_STORAGE_BYTES (848 * 1024)

// Enable networking.
#define MICROPY_PY_NETWORK 1
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "PicoW"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "PicoW"

// CYW43 driver configuration.
#define CYW43_USE_SPI (1)
#define CYW43_LWIP (1)
#define CYW43_GPIO (1)
#define CYW43_SPI_PIO (1)

// For debugging mbedtls - also set
// Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose
// #define MODUSSL_MBEDTLS_DEBUG_LEVEL 1

#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT

// If this returns true for a pin then its irq will not be disabled on a soft reboot
int mp_hal_is_pin_reserved(int n);
#define MICROPY_HW_PIN_RESERVED(i) mp_hal_is_pin_reserved(i)
#include "enable_cyw43.h"
7 changes: 7 additions & 0 deletions ports/rp2/enable_cyw43.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(MICROPY_PY_LWIP ON)
set(MICROPY_PY_NETWORK_CYW43 ON)

# Bluetooth
set(MICROPY_PY_BLUETOOTH ON)
set(MICROPY_BLUETOOTH_BTSTACK ON)
set(MICROPY_PY_BLUETOOTH_CYW43 ON)
25 changes: 25 additions & 0 deletions ports/rp2/enable_cyw43.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Enable networking.
#define MICROPY_PY_NETWORK 1

#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "Pico"
#endif

// CYW43 driver configuration.
#define CYW43_USE_SPI (1)
#define CYW43_LWIP (1)
#define CYW43_GPIO (1)
#define CYW43_SPI_PIO (1)

// For debugging mbedtls - also set
// Debug level (0-4) 1=warning, 2=info, 3=debug, 4=verbose
// #define MODUSSL_MBEDTLS_DEBUG_LEVEL 1

#ifndef CYW43_WL_GPIO_COUNT
#define CYW43_WL_GPIO_COUNT 3
#endif

#define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT

int mp_hal_is_pin_reserved(int n);
#define MICROPY_HW_PIN_RESERVED(i) mp_hal_is_pin_reserved(i)
Loading
Loading