Skip to content

Commit

Permalink
Add other Raspberry Pi Pico boards support
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 4, 2024
1 parent b04f08f commit 7576194
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Contributors:
# ZettaScale Zenoh Team, <[email protected]>
#
name: rpi_pico_w
name: rpi_pico

on:
push:
Expand All @@ -21,12 +21,13 @@ on:

jobs:
build:
name: Build on ${{ matrix.os }}
name: Build on ${{ matrix.os }} for ${{ matrix.pico_board }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
pico_board: ["pico", "pico_w", "pico2", "pico2_w"]
steps:
- uses: actions/checkout@v4
- uses: jwlawson/[email protected]
Expand All @@ -48,13 +49,15 @@ jobs:
export FREERTOS_KERNEL_PATH=$HOME/work/FreeRTOS-Kernel/
mkdir -p $FREERTOS_KERNEL_PATH
cd $FREERTOS_KERNEL_PATH
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git --branch V11.1.0 .
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git .
git submodule update --init
- name: Build examples
run: |
export PICO_SDK_PATH=$HOME/work/pico-sdk
export FREERTOS_KERNEL_PATH=$HOME/work/FreeRTOS-Kernel/
cd $HOME/work/zenoh-pico/zenoh-pico/examples/rpi_pico_w
cmake -Bbuild -DWIFI_SSID=wifi_network_ssid -DWIFI_PASSWORD=wifi_network_password
cd $HOME/work/zenoh-pico/zenoh-pico/examples/rpi_pico
cmake -Bbuild -DWIFI_SSID=wifi_network_ssid -DWIFI_PASSWORD=wifi_network_password -DPICO_BOARD="$PICO_BOARD"
cmake --build ./build
env:
PICO_BOARD: ${{ matrix.pico_board}}
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ include(GNUInstallDirs)
option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)
option(WITH_FREERTOS_PLUS_TCP "Build for FreeRTOS RTOS and FreeRTOS-Plus-TCP network stack" OFF)
option(WITH_RPI_PICO_W "Build for Raspberry Pi Pico W" OFF)
option(WITH_RPI_PICO "Build for Raspberry Pi Pico" OFF)
set(ZENOH_DEBUG 0 CACHE STRING "Use this to set the ZENOH_DEBUG variable")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
if(CMAKE_EXPORT_COMPILE_COMMANDS)
Expand Down Expand Up @@ -186,7 +186,7 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
pico_add_compile_definition(ZENOH_FREERTOS_PLUS_TCP)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "PICO") # Raspberry Pi Pico Series
pico_add_compile_definition(ZENOH_RPI_PICO_W)
pico_add_compile_definition(ZENOH_RPI_PICO)
set(CHECK_THREADS "OFF")
else()
message(FATAL_ERROR "zenoh-pico is not yet available on ${CMAKE_SYSTEM_NAME} platform")
Expand Down Expand Up @@ -279,7 +279,7 @@ message(STATUS "Unicast batch max size: ${BATCH_UNICAST_SIZE}")
message(STATUS "Multicast batch max size: ${BATCH_MULTICAST_SIZE}")
message(STATUS "Build for Zephyr RTOS: ${WITH_ZEPHYR}")
message(STATUS "Build for FreeRTOS-Plus-TCP: ${WITH_FREERTOS_PLUS_TCP}")
message(STATUS "Build for Raspberry Pi Pico W: ${WITH_RPI_PICO_W}")
message(STATUS "Build for Raspberry Pi Pico: ${WITH_RPI_PICO}")
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")

if(SKBUILD)
Expand Down Expand Up @@ -341,9 +341,9 @@ if(WITH_ZEPHYR)
elseif(WITH_FREERTOS_PLUS_TCP)
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
elseif(WITH_RPI_PICO_W)
file (GLOB Sources_RPI_Pico_W "src/system/rpi_pico_w/*.c")
list(APPEND Sources ${Sources_RPI_Pico_W})
elseif(WITH_RPI_PICO)
file (GLOB Sources_RPI_Pico "src/system/rpi_pico/*.c")
list(APPEND Sources ${Sources_RPI_Pico})
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
file (GLOB Sources_Unix "src/system/unix/*.c" "src/system/unix/link/*.c")
list(APPEND Sources ${Sources_Unix})
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Currently, zenoh-pico provides support for the following (RT)OSs and protocols:
| **OpenCR** | UDP (unicast and multicast), TCP | IPv4 | WiFi |
| **Emscripten** | Websocket | IPv4, IPv6 | WiFi, Ethernet |
| **FreeRTOS-Plus-TCP** | UDP (unicast), TCP | IPv4 | Ethernet |
|**Raspberry Pi Pico W**| UDP (unicast and multicast), TCP | IPv4 | WiFi, Serial |
| **Raspberry Pi Pico** | UDP (unicast and multicast), TCP | IPv4 | WiFi (for "W" version), Serial |

Check the website [zenoh.io](http://zenoh.io) and the [roadmap](https://github.com/eclipse-zenoh/roadmap) for more detailed information.

Expand Down Expand Up @@ -330,7 +330,8 @@ To build and upload the code into the board, run the following command:
platformio run -t upload
```

#### 2.2.6. Raspberry Pi Pico W
#### 2.2.6. Raspberry Pi Pico
Note: tested with `Raspberry Pi Pico W` and `Raspberry Pi Pico 2 W` boards

Ensure your system has the necessary tools and libraries installed. Run the following commands:

Expand All @@ -345,7 +346,7 @@ Set up the Raspberry Pi Pico SDK by cloning the repository:
export PICO_SDK_PATH=$HOME/src/pico-sdk
mkdir -p $PICO_SDK_PATH
cd $PICO_SDK_PATH
git clone https://github.com/raspberrypi/pico-sdk.git --branch 2.1.0 .
git clone https://github.com/raspberrypi/pico-sdk.git .
git submodule update --init
```

Expand All @@ -355,24 +356,25 @@ Clone the FreeRTOS Kernel repository for the project:
export FREERTOS_KERNEL_PATH=$HOME/src/FreeRTOS-Kernel/
mkdir -p $FREERTOS_KERNEL_PATH
cd $FREERTOS_KERNEL_PATH
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git --branch V11.1.0 .
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git .
git submodule update --init
```

Setup and build the examples:
`PICO_BOARD` - Pico board type: pico, pico_w, pico2, pico2_w (default: pico_w)
`WIFI_SSID` - Wi-Fi network SSID
`WIFI_PASSWORD` - Wi-Fi password
`ZENOH_CONFIG_MODE` - client or peer mode (default: client)
`ZENOH_CONFIG_CONNECT` - connect endpoint (only for client mode, optional)
`ZENOH_CONFIG_LISTEN` - listen endpoint (only for peer mode, optional)

```bash
cd examples/rpi_pico_w
cmake -Bbuild -DWIFI_SSID=wifi_network_ssid -DWIFI_PASSWORD=wifi_network_password -DZENOH_CONFIG_MODE=[client|peer] -DZENOH_CONFIG_CONNECT=connect -DZENOH_CONFIG_LISTEN=listen
cd examples/rpi_pico
cmake -Bbuild -DPICO_BOARD="pico" -DWIFI_SSID=wifi_network_ssid -DWIFI_PASSWORD=wifi_network_password -DZENOH_CONFIG_MODE=[client|peer] -DZENOH_CONFIG_CONNECT=connect -DZENOH_CONFIG_LISTEN=listen
cmake --build ./build
```

To flash the Raspberry Pi Pico W board, connect it in bootloader mode (it will appear as a removable drive) and copy the generated .uf2 file onto it.
To flash the Raspberry Pi Pico board, connect it in bootloader mode (it will appear as a removable drive) and copy the generated .uf2 file onto it.

## 3. Running the Examples
The simplest way to run some of the example is to get a Docker image of the **zenoh** router (see [http://zenoh.io/docs/getting-started/quick-test/](http://zenoh.io/docs/getting-started/quick-test/)) and then to run the examples on your machine.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
cmake_minimum_required(VERSION 3.13)

set(PICO_BOARD "pico_w" CACHE STRING "Raspberry Pi Pico board: pico, pico_w, pico2, pico2_w")

set(WIFI_SUPPORT_ENABLED 0)
if(PICO_BOARD STREQUAL "pico_w" OR PICO_BOARD STREQUAL "pico2_w")
set(WIFI_SUPPORT_ENABLED 1)
endif()

# Set options
set(WIFI_SSID "" CACHE STRING "WiFi SSID")
set(WIFI_PASSWORD "" CACHE STRING "WiFi Password")
Expand All @@ -8,6 +15,7 @@ set(ZENOH_CONFIG_MODE "client" CACHE STRING "ZENOH_CONFIG_MODE")
set(ZENOH_CONFIG_CONNECT CACHE STRING "ZENOH_CONFIG_CONNECT")
set(ZENOH_CONFIG_LISTEN CACHE STRING "ZENOH_CONFIG_LISTEN")

message(STATUS "PICO_BOARD: ${PICO_BOARD}")
message(STATUS "WIFI_SSID: ${WIFI_SSID}")
if(WIFI_PASSWORD STREQUAL "")
message(STATUS "WIFI_PASSWORD is empty")
Expand All @@ -27,7 +35,6 @@ configure_file(
set(CMAKE_C_STANDARD 11)

# Include Raspberry Pi Pico SDK
set(PICO_BOARD "pico_w")
if(NOT DEFINED ENV{PICO_SDK_PATH})
message(FATAL_ERROR "PICO_SDK_PATH environment variable is not set. Please set it to the location of the Pico SDK.")
endif()
Expand All @@ -37,7 +44,13 @@ include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
include(FreeRTOS_Kernel_import.cmake)

# Configure project
project(zenohpico_rpi_pico_w_examples C CXX ASM)
project(zenohpico_rpi_pico_examples C CXX ASM)

if(WIFI_SUPPORT_ENABLED)
set(WIFI_LIB pico_cyw43_arch_lwip_sys_freertos)
else()
set(WIFI_LIB "")
endif()

add_compile_definitions(LWIP_TIMEVAL_PRIVATE=0)
pico_sdk_init()
Expand All @@ -46,15 +59,26 @@ pico_sdk_init()
include(../../cmake/helpers.cmake)
set_default_build_type(Release)

if (NOT WIFI_SUPPORT_ENABLED)
declare_cache_var(Z_FEATURE_LINK_TCP 0 STRING "TCP support")
declare_cache_var(Z_FEATURE_LINK_UDP_MULTICAST 0 STRING "UDP multicast support")
declare_cache_var(Z_FEATURE_LINK_UDP_UNICAST 0 STRING "UDP unicast support")
declare_cache_var(Z_FEATURE_SCOUTING_UDP 0 STRING "Scouting support")
endif()

declare_cache_var(Z_FEATURE_LINK_SERIAL 1 STRING "Serial support")

set(BUILD_SHARED_LIBS OFF)
set(WITH_RPI_PICO_W ON)
set(WITH_RPI_PICO ON)

configure_include_project(ZENOHPICO zenohpico zenohpico::lib "../.." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")

target_link_libraries(zenohpico_static
hardware_uart
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
pico_rand
FreeRTOS-Kernel-Heap4
${WIFI_LIB}
)

# Configure build
Expand All @@ -71,8 +95,9 @@ target_include_directories(main PRIVATE
)
target_link_libraries(main
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
pico_rand
FreeRTOS-Kernel-Heap4
${WIFI_LIB}
)

function(add_example name)
Expand All @@ -81,9 +106,10 @@ function(add_example name)
main
hardware_uart
pico_stdlib
pico_cyw43_arch_lwip_sys_freertos
pico_rand
FreeRTOS-Kernel-Heap4
zenohpico::lib
${WIFI_LIB}
)
target_include_directories(${name} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef CONFIG_H
#define CONFIG_H

#define WIFI_SUPPORT_ENABLED @WIFI_SUPPORT_ENABLED@
#define WIFI_SSID "@WIFI_SSID@"
#define WIFI_PASSWORD "@WIFI_PASSWORD@"
#define ZENOH_CONFIG_MODE "@ZENOH_CONFIG_MODE@"
Expand Down
File renamed without changes.
16 changes: 14 additions & 2 deletions examples/rpi_pico_w/main.c → examples/rpi_pico/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <stdio.h>

#include "FreeRTOS.h"
#include "config.h"

#if WIFI_SUPPORT_ENABLED
#include "pico/cyw43_arch.h"
#endif

#include "pico/stdlib.h"
#include "task.h"

Expand All @@ -23,6 +29,7 @@

int app_main();

#if WIFI_SUPPORT_ENABLED
void print_ip_address() {
struct netif *netif = &cyw43_state.netif[CYW43_ITF_STA];
if (netif_is_up(netif)) {
Expand All @@ -33,12 +40,12 @@ void print_ip_address() {
printf("Network interface is down.\n");
}
}
#endif

void main_task(void *params) {
(void)params;

vTaskDelay(pdMS_TO_TICKS(1000));

#if WIFI_SUPPORT_ENABLED
if (cyw43_arch_init()) {
printf("Failed to initialise\n");
return;
Expand All @@ -58,10 +65,15 @@ void main_task(void *params) {
printf("Offline mode\n");
app_main();
}
#else
app_main();
#endif

printf("Terminate.\n");

#if WIFI_SUPPORT_ENABLED
cyw43_arch_deinit();
#endif

vTaskDelete(NULL);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 0 additions & 10 deletions examples/rpi_pico_w/include/config.h

This file was deleted.

10 changes: 5 additions & 5 deletions extra_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"-<system/emscripten/>",
"-<system/espidf/>",
"-<system/freertos_plus_tcp/>",
"-<system/rpi_pico_w/>",
"-<system/rpi_pico/>",
"-<system/mbed/>",
"-<system/unix/>",
"-<system/flipper/>",
Expand All @@ -43,7 +43,7 @@
"-<system/emscripten/>",
"-<system/espidf>",
"-<system/freertos_plus_tcp/>",
"-<system/rpi_pico_w/>",
"-<system/rpi_pico/>",
"-<system/mbed/>",
"-<system/unix/>",
"-<system/flipper/>",
Expand All @@ -60,7 +60,7 @@
"-<system/emscripten/>",
"-<system/espidf>",
"-<system/freertos_plus_tcp/>",
"-<system/rpi_pico_w/>",
"-<system/rpi_pico/>",
"-<system/mbed/>",
"-<system/unix/>",
"-<system/flipper/>",
Expand All @@ -75,7 +75,7 @@
"-<system/arduino/>",
"-<system/emscripten/>",
"-<system/freertos_plus_tcp/>",
"-<system/rpi_pico_w/>",
"-<system/rpi_pico/>",
"-<system/mbed/>",
"-<system/unix/>",
"-<system/flipper/>",
Expand All @@ -91,7 +91,7 @@
"-<system/emscripten/>",
"-<system/espidf/>",
"-<system/freertos_plus_tcp/>",
"-<system/rpi_pico_w/>",
"-<system/rpi_pico/>",
"-<system/unix/>",
"-<system/flipper/>",
"-<system/windows/>",
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define Z_FEATURE_LINK_TCP 1
#define Z_FEATURE_LINK_BLUETOOTH 0
#define Z_FEATURE_LINK_WS 0
#define Z_FEATURE_LINK_SERIAL 1
#define Z_FEATURE_LINK_SERIAL 0
#define Z_FEATURE_SCOUTING_UDP 1
#define Z_FEATURE_LINK_UDP_MULTICAST 1
#define Z_FEATURE_LINK_UDP_UNICAST 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_SYSTEM_RPI_PICO_W_TYPES_H
#define ZENOH_PICO_SYSTEM_RPI_PICO_W_TYPES_H
#ifndef ZENOH_PICO_SYSTEM_RPI_PICO_TYPES_H
#define ZENOH_PICO_SYSTEM_RPI_PICO_TYPES_H

#include <time.h>

#include "FreeRTOS.h"
#include "event_groups.h"
Expand Down Expand Up @@ -76,4 +78,4 @@ typedef struct {
}
#endif

#endif // ZENOH_PICO_SYSTEM_RPI_PICO_W_TYPES_H
#endif // ZENOH_PICO_SYSTEM_RPI_PICO_TYPES_H
4 changes: 2 additions & 2 deletions include/zenoh-pico/system/platform_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
#include "zenoh-pico/system/platform/flipper.h"
#elif defined(ZENOH_FREERTOS_PLUS_TCP)
#include "zenoh-pico/system/platform/freertos_plus_tcp.h"
#elif defined(ZENOH_RPI_PICO_W)
#include "zenoh-pico/system/platform/rpi_pico_w.h"
#elif defined(ZENOH_RPI_PICO)
#include "zenoh-pico/system/platform/rpi_pico.h"
#else
#include "zenoh-pico/system/platform/void.h"
#error "Unknown platform"
Expand Down
Loading

0 comments on commit 7576194

Please sign in to comment.