Skip to content

Commit

Permalink
rp2/network: Add USB Network support in RPI_PICO/USB_NET variant build.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Dec 20, 2024
1 parent 2026ae3 commit d08d6fc
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ports/rp2/boards/RPI_PICO/board.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"product": "Pico",
"thumbnail": "",
"url": "https://www.raspberrypi.com/products/raspberry-pi-pico/",
"variants": {
"USB_NET": "USB Network Adapter"
},
"vendor": "Raspberry Pi"
}
1 change: 1 addition & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# cmake file for Raspberry Pi Pico
set(PICO_BOARD "pico")
set(PICO_PLATFORM "rp2040")

6 changes: 6 additions & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Board and hardware specific configuration
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)

#if MICROPY_PY_LWIP
// Enable networking.
#define MICROPY_PY_NETWORK 1
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "Pico"
#endif
1 change: 1 addition & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigvariant.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(MICROPY_PY_LWIP OFF)
7 changes: 7 additions & 0 deletions ports/rp2/boards/RPI_PICO/mpconfigvariant_USB_NET.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(MICROPY_PY_LWIP ON)

list(APPEND MICROPY_DEF_BOARD
MICROPY_HW_NETWORK_USBNET=1
)
# Board specific version of the frozen manifest
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/../RPI_PICO_W/manifest.py)
8 changes: 8 additions & 0 deletions ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
#define MICROPY_HW_NIC_WIZNET5K
#endif

#if MICROPY_HW_NETWORK_USBNET
extern const struct _mp_obj_type_t mod_network_nic_type_usbnet;
#define MICROPY_HW_NIC_USBNET { MP_ROM_QSTR(MP_QSTR_USBNET), MP_ROM_PTR(&mod_network_nic_type_usbnet) },
#else
#define MICROPY_HW_NIC_USBNET
#endif

#ifndef MICROPY_BOARD_NETWORK_INTERFACES
#define MICROPY_BOARD_NETWORK_INTERFACES
#endif
Expand All @@ -253,6 +260,7 @@ extern const struct _mp_obj_type_t mod_network_nic_type_wiznet5k;
MICROPY_HW_NIC_CYW43 \
MICROPY_HW_NIC_NINAW10 \
MICROPY_HW_NIC_WIZNET5K \
MICROPY_HW_NIC_USBNET \
MICROPY_BOARD_NETWORK_INTERFACES \

// Additional entries for use with pendsv_schedule_dispatch.
Expand Down
5 changes: 5 additions & 0 deletions ports/rp2/mpnetworkport.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#if MICROPY_PY_LWIP

#include "extmod/network_usbd_ncm.h"
#include "shared/runtime/softtimer.h"
#include "lwip/timeouts.h"

Expand Down Expand Up @@ -116,6 +117,10 @@ static void mp_network_soft_timer_callback(soft_timer_entry_t *self) {
#if MICROPY_PY_NETWORK_WIZNET5K
wiznet5k_poll();
#endif

#if MICROPY_HW_NETWORK_USBNET
network_usbd_ncm_service_traffic();
#endif
}

void mod_network_lwip_init(void) {
Expand Down

0 comments on commit d08d6fc

Please sign in to comment.