Skip to content

Commit 5c38cb8

Browse files
committed
Add Raspberry Pi Pico platform
1 parent e492167 commit 5c38cb8

32 files changed

+3305
-2
lines changed

.github/workflows/rpi_pico.yaml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# Copyright (c) 2024 ZettaScale Technology
3+
#
4+
# This program and the accompanying materials are made available under the
5+
# terms of the Eclipse Public License 2.0 which is available at
6+
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
#
9+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
#
11+
# Contributors:
12+
# ZettaScale Zenoh Team, <[email protected]>
13+
#
14+
name: rpi_pico
15+
16+
on:
17+
push:
18+
branches: [ '**' ]
19+
pull_request:
20+
branches: [ '**' ]
21+
22+
jobs:
23+
build:
24+
name: Build on ${{ matrix.os }} for ${{ matrix.pico_board }}
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os: [ubuntu-latest]
30+
pico_board: ["pico", "pico_w", "pico2", "pico2_w"]
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: jwlawson/[email protected]
34+
- name: Install requirements
35+
run: |
36+
sudo apt update
37+
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential g++ libstdc++-arm-none-eabi-newlib
38+
39+
- name: Install Raspberry Pico SDK
40+
run: |
41+
export PICO_SDK_PATH=$HOME/work/pico-sdk
42+
mkdir -p $PICO_SDK_PATH
43+
cd $PICO_SDK_PATH
44+
git clone https://github.com/raspberrypi/pico-sdk.git --branch 2.1.0 .
45+
git submodule update --init
46+
47+
- name: Install FreeRTOS SDK
48+
run: |
49+
export FREERTOS_KERNEL_PATH=$HOME/work/FreeRTOS-Kernel/
50+
mkdir -p $FREERTOS_KERNEL_PATH
51+
cd $FREERTOS_KERNEL_PATH
52+
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git .
53+
git submodule update --init
54+
55+
- name: Build examples
56+
run: |
57+
export PICO_SDK_PATH=$HOME/work/pico-sdk
58+
export FREERTOS_KERNEL_PATH=$HOME/work/FreeRTOS-Kernel/
59+
cd $HOME/work/zenoh-pico/zenoh-pico/examples/rpi_pico
60+
cmake -Bbuild -DWIFI_SSID=wifi_network_ssid -DWIFI_PASSWORD=wifi_network_password -DPICO_BOARD="$PICO_BOARD"
61+
cmake --build ./build
62+
env:
63+
PICO_BOARD: ${{ matrix.pico_board}}

CMakeLists.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ include(GNUInstallDirs)
4545
option(BUILD_SHARED_LIBS "Build shared libraries if ON, otherwise build static libraries" ON)
4646
option(WITH_ZEPHYR "Build for Zephyr RTOS" OFF)
4747
option(WITH_FREERTOS_PLUS_TCP "Build for FreeRTOS RTOS and FreeRTOS-Plus-TCP network stack" OFF)
48+
option(WITH_RPI_PICO "Build for Raspberry Pi Pico" OFF)
4849
set(ZENOH_DEBUG 0 CACHE STRING "Use this to set the ZENOH_DEBUG variable")
4950
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
5051
if(CMAKE_EXPORT_COMPILE_COMMANDS)
@@ -90,7 +91,9 @@ if(CMAKE_BUILD_TYPE MATCHES "RELEASE" OR "Release")
9091
add_compile_options(-pipe -O3)
9192
endif()
9293
else()
93-
if(UNIX)
94+
if(CMAKE_SYSTEM_NAME MATCHES "PICO")
95+
add_compile_options(-c -Wall -Wextra -Wno-unused -Wno-strict-prototypes -pipe -g -O0)
96+
elseif(UNIX)
9497
add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wunused -Wstrict-prototypes -pipe -g -O0)
9598
# C99 pedantic doesn't like struct anonymous in unix header
9699
if (NOT CMAKE_C_STANDARD STREQUAL "99")
@@ -182,6 +185,9 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Generic")
182185
elseif(WITH_FREERTOS_PLUS_TCP)
183186
pico_add_compile_definition(ZENOH_FREERTOS_PLUS_TCP)
184187
endif()
188+
elseif(CMAKE_SYSTEM_NAME MATCHES "PICO") # Raspberry Pi Pico Series
189+
pico_add_compile_definition(ZENOH_RPI_PICO)
190+
set(CHECK_THREADS "OFF")
185191
else()
186192
message(FATAL_ERROR "zenoh-pico is not yet available on ${CMAKE_SYSTEM_NAME} platform")
187193
return()
@@ -226,6 +232,7 @@ set(Z_FEATURE_LINK_TCP 1 CACHE STRING "Toggle TCP links")
226232
set(Z_FEATURE_LINK_BLUETOOTH 0 CACHE STRING "Toggle Bluetooth links")
227233
set(Z_FEATURE_LINK_WS 0 CACHE STRING "Toggle WebSocket links")
228234
set(Z_FEATURE_LINK_SERIAL 0 CACHE STRING "Toggle Serial links")
235+
set(Z_FEATURE_LINK_SERIAL_USB 0 CACHE STRING "Toggle Serial USB links")
229236
set(Z_FEATURE_SCOUTING_UDP 1 CACHE STRING "Toggle UDP scouting")
230237
set(Z_FEATURE_LINK_UDP_MULTICAST 1 CACHE STRING "Toggle UDP multicast links")
231238
set(Z_FEATURE_LINK_UDP_UNICAST 1 CACHE STRING "Toggle UDP unicast links")
@@ -244,6 +251,12 @@ if(Z_FEATURE_LIVELINESS AND NOT Z_FEATURE_UNSTABLE_API)
244251
set(Z_FEATURE_LIVELINESS 0 CACHE STRING "Toggle liveliness feature" FORCE)
245252
endif()
246253

254+
# Add a warning message if someone tries to enable Z_FEATURE_LINK_SERIAL_USB directly
255+
if(Z_FEATURE_LINK_SERIAL_USB AND NOT Z_FEATURE_UNSTABLE_API)
256+
message(WARNING "Z_FEATURE_LINK_SERIAL_USB can only be enabled when Z_FEATURE_UNSTABLE_API is also enabled. Disabling Z_FEATURE_LINK_SERIAL_USB.")
257+
set(Z_FEATURE_LINK_SERIAL_USB 0 CACHE STRING "Toggle Serial USB links" FORCE)
258+
endif()
259+
247260
add_compile_definitions("Z_BUILD_DEBUG=$<CONFIG:Debug>")
248261
message(STATUS "Building with feature confing:\n\
249262
* UNSTABLE_API: ${Z_FEATURE_UNSTABLE_API}\n\
@@ -277,6 +290,7 @@ message(STATUS "Unicast batch max size: ${BATCH_UNICAST_SIZE}")
277290
message(STATUS "Multicast batch max size: ${BATCH_MULTICAST_SIZE}")
278291
message(STATUS "Build for Zephyr RTOS: ${WITH_ZEPHYR}")
279292
message(STATUS "Build for FreeRTOS-Plus-TCP: ${WITH_FREERTOS_PLUS_TCP}")
293+
message(STATUS "Build for Raspberry Pi Pico: ${WITH_RPI_PICO}")
280294
message(STATUS "Configuring for ${CMAKE_SYSTEM_NAME}")
281295

282296
if(SKBUILD)
@@ -338,6 +352,9 @@ if(WITH_ZEPHYR)
338352
elseif(WITH_FREERTOS_PLUS_TCP)
339353
file (GLOB Sources_Freertos_Plus_TCP "src/system/freertos_plus_tcp/*.c")
340354
list(APPEND Sources ${Sources_Freertos_Plus_TCP})
355+
elseif(WITH_RPI_PICO)
356+
file (GLOB Sources_RPI_Pico "src/system/rpi_pico/*.c")
357+
list(APPEND Sources ${Sources_RPI_Pico})
341358
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin" OR CMAKE_SYSTEM_NAME MATCHES "BSD" OR POSIX_COMPATIBLE)
342359
file (GLOB Sources_Unix "src/system/unix/*.c" "src/system/unix/link/*.c")
343360
list(APPEND Sources ${Sources_Unix})

README.md

+87
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Currently, zenoh-pico provides support for the following (RT)OSs and protocols:
3434
| **OpenCR** | UDP (unicast and multicast), TCP | IPv4 | WiFi |
3535
| **Emscripten** | Websocket | IPv4, IPv6 | WiFi, Ethernet |
3636
| **FreeRTOS-Plus-TCP** | UDP (unicast), TCP | IPv4 | Ethernet |
37+
| **Raspberry Pi Pico** | UDP (unicast and multicast), TCP | IPv4 | WiFi (for "W" version), Serial, USB (CDC) |
3738

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

@@ -329,6 +330,92 @@ To build and upload the code into the board, run the following command:
329330
platformio run -t upload
330331
```
331332

333+
#### 2.2.6. Raspberry Pi Pico
334+
Note: tested with `Raspberry Pi Pico W` and `Raspberry Pi Pico 2 W` boards
335+
336+
Ensure your system has the necessary tools and libraries installed. Run the following commands:
337+
338+
```bash
339+
sudo apt update
340+
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential g++ libstdc++-arm-none-eabi-newlib
341+
```
342+
343+
Set up the Raspberry Pi Pico SDK by cloning the repository:
344+
345+
```bash
346+
export PICO_SDK_PATH=$HOME/src/pico-sdk
347+
mkdir -p $PICO_SDK_PATH
348+
cd $PICO_SDK_PATH
349+
git clone https://github.com/raspberrypi/pico-sdk.git .
350+
git submodule update --init
351+
```
352+
353+
Clone the FreeRTOS Kernel repository for the project:
354+
355+
```bash
356+
export FREERTOS_KERNEL_PATH=$HOME/src/FreeRTOS-Kernel/
357+
mkdir -p $FREERTOS_KERNEL_PATH
358+
cd $FREERTOS_KERNEL_PATH
359+
git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git .
360+
git submodule update --init
361+
```
362+
363+
Setup and build the examples:
364+
- `PICO_BOARD` - Pico board type: pico, pico_w, pico2, pico2_w (default: pico_w)
365+
- `WIFI_SSID` - Wi-Fi network SSID
366+
- `WIFI_PASSWORD` - Wi-Fi password
367+
- `ZENOH_CONFIG_MODE` - client or peer mode (default: client)
368+
- `ZENOH_CONFIG_CONNECT` - connect endpoint (only for client mode, optional)
369+
- `ZENOH_CONFIG_LISTEN` - listen endpoint (only for peer mode, optional)
370+
371+
```bash
372+
cd examples/rpi_pico
373+
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
374+
cmake --build ./build
375+
```
376+
377+
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.
378+
379+
**Serial connection**:
380+
381+
To connect via UART specify pins or predefined device name and baud rate:
382+
383+
e.g.
384+
```
385+
-DZENOH_CONFIG_CONNECT="serial/0.1#baudrate=38400"
386+
-DZENOH_CONFIG_CONNECT="serial/uart1_0#baudrate=38400"
387+
```
388+
389+
Valid PIN combinations and associated device names:
390+
391+
| **PINS** | **Device name** |
392+
|---------:|:---------------:|
393+
| 0.1 | uart0_0 |
394+
| 4.5 | uart1_0 |
395+
| 8.9 | uart1_1 |
396+
| 12.13 | uart0_1 |
397+
| 16.17 | uart0_2 |
398+
399+
400+
**USB Serial connection (experemental)**:
401+
402+
403+
To enable this feature, zenoh-pico should be compiled with `Z_FEATURE_LINK_SERIAL_USB` and `Z_FEATURE_UNSTABLE_API` enabled.
404+
405+
To connect via USB CDC, specify `usb` device:
406+
407+
e.g.
408+
```
409+
-DZENOH_CONFIG_CONNECT="serial/usb#baudrate=112500"
410+
```
411+
412+
On the host Zenoh, specify the USB CDC device:
413+
414+
e.g.
415+
```
416+
zenohd -l serial//dev/ttyACM1#baudrate=112500
417+
```
418+
332419
## 3. Running the Examples
333420
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.
334421

examples/rpi_pico/CMakeLists.txt

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
set(PICO_BOARD "pico_w" CACHE STRING "Raspberry Pi Pico board: pico, pico_w, pico2, pico2_w")
4+
5+
set(WIFI_SUPPORT_ENABLED 0)
6+
if(PICO_BOARD STREQUAL "pico_w" OR PICO_BOARD STREQUAL "pico2_w")
7+
set(WIFI_SUPPORT_ENABLED 1)
8+
endif()
9+
10+
# Set options
11+
set(WIFI_SSID "" CACHE STRING "WiFi SSID")
12+
set(WIFI_PASSWORD "" CACHE STRING "WiFi Password")
13+
14+
set(ZENOH_CONFIG_MODE "client" CACHE STRING "ZENOH_CONFIG_MODE")
15+
set(ZENOH_CONFIG_CONNECT CACHE STRING "ZENOH_CONFIG_CONNECT")
16+
set(ZENOH_CONFIG_LISTEN CACHE STRING "ZENOH_CONFIG_LISTEN")
17+
option(ZENOH_USB_UART "Enable USB UART" OFF)
18+
19+
message(STATUS "PICO_BOARD: ${PICO_BOARD}")
20+
message(STATUS "WIFI_SSID: ${WIFI_SSID}")
21+
if(WIFI_PASSWORD STREQUAL "")
22+
message(STATUS "WIFI_PASSWORD is empty")
23+
else()
24+
message(STATUS "WIFI_PASSWORD is set")
25+
endif()
26+
27+
message(STATUS "ZENOH_CONFIG_MODE: ${ZENOH_CONFIG_MODE}")
28+
message(STATUS "ZENOH_CONFIG_CONNECT: ${ZENOH_CONFIG_CONNECT}")
29+
message(STATUS "ZENOH_CONFIG_LISTEN: ${ZENOH_CONFIG_LISTEN}")
30+
message(STATUS "ZENOH_USB_UART: ${ZENOH_USB_UART}")
31+
32+
configure_file(
33+
"${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in"
34+
"${CMAKE_CURRENT_SOURCE_DIR}/include/config.h"
35+
)
36+
37+
set(CMAKE_C_STANDARD 11)
38+
39+
# Include Raspberry Pi Pico SDK
40+
if(NOT DEFINED ENV{PICO_SDK_PATH})
41+
message(FATAL_ERROR "PICO_SDK_PATH environment variable is not set. Please set it to the location of the Pico SDK.")
42+
endif()
43+
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
44+
45+
# Include FreeRTOS SDK
46+
include(FreeRTOS_Kernel_import.cmake)
47+
48+
# Configure project
49+
project(zenohpico_rpi_pico_examples C CXX ASM)
50+
51+
if(WIFI_SUPPORT_ENABLED)
52+
set(WIFI_LIB pico_cyw43_arch_lwip_sys_freertos)
53+
else()
54+
set(WIFI_LIB "")
55+
endif()
56+
57+
if(ZENOH_USB_UART)
58+
set(USB_LIBS
59+
tinyusb_host
60+
tinyusb_device
61+
tinyusb_board
62+
)
63+
set(USB_INCLUDE
64+
${CMAKE_CURRENT_LIST_DIR}/include/tusb
65+
)
66+
else()
67+
set(USB_LIBS "")
68+
set(USB_INCLUDE "")
69+
endif()
70+
71+
add_compile_definitions(LWIP_TIMEVAL_PRIVATE=0)
72+
pico_sdk_init()
73+
74+
# Include Zenoh Pico library
75+
include(../../cmake/helpers.cmake)
76+
set_default_build_type(Release)
77+
78+
if (NOT WIFI_SUPPORT_ENABLED)
79+
declare_cache_var(Z_FEATURE_LINK_TCP 0 STRING "TCP support")
80+
declare_cache_var(Z_FEATURE_LINK_UDP_MULTICAST 0 STRING "UDP multicast support")
81+
declare_cache_var(Z_FEATURE_LINK_UDP_UNICAST 0 STRING "UDP unicast support")
82+
declare_cache_var(Z_FEATURE_SCOUTING_UDP 0 STRING "Scouting support")
83+
endif()
84+
85+
declare_cache_var(Z_FEATURE_LINK_SERIAL 1 STRING "Serial support")
86+
if(ZENOH_USB_UART)
87+
declare_cache_var(Z_FEATURE_LINK_SERIAL_USB 1 STRING "Serial USB support")
88+
else()
89+
declare_cache_var(Z_FEATURE_LINK_SERIAL_USB 0 STRING "Serial USB support")
90+
endif()
91+
92+
set(BUILD_SHARED_LIBS OFF)
93+
set(WITH_RPI_PICO ON)
94+
95+
configure_include_project(ZENOHPICO zenohpico zenohpico::lib "../.." zenohpico "https://github.com/eclipse-zenoh/zenoh-pico" "")
96+
97+
target_link_libraries(zenohpico_static
98+
hardware_uart
99+
pico_stdlib
100+
pico_rand
101+
FreeRTOS-Kernel-Heap4
102+
${WIFI_LIB}
103+
${USB_LIBS}
104+
)
105+
106+
# Configure build
107+
target_include_directories(zenohpico_static PRIVATE
108+
${CMAKE_CURRENT_LIST_DIR}
109+
${CMAKE_CURRENT_LIST_DIR}/include
110+
${USB_INCLUDE}
111+
)
112+
113+
add_library(main STATIC main.c)
114+
115+
target_include_directories(main PRIVATE
116+
${CMAKE_CURRENT_LIST_DIR}
117+
${CMAKE_CURRENT_LIST_DIR}/include
118+
)
119+
target_link_libraries(main
120+
pico_stdlib
121+
pico_rand
122+
FreeRTOS-Kernel-Heap4
123+
${WIFI_LIB}
124+
)
125+
126+
function(add_example name)
127+
add_executable(${name} ${name}.c)
128+
target_link_libraries(${name}
129+
main
130+
hardware_uart
131+
pico_stdlib
132+
pico_rand
133+
FreeRTOS-Kernel-Heap4
134+
zenohpico::lib
135+
${WIFI_LIB}
136+
${USB_LIBS}
137+
)
138+
target_include_directories(${name} PRIVATE
139+
${CMAKE_CURRENT_LIST_DIR}
140+
${CMAKE_CURRENT_LIST_DIR}/include
141+
${USB_INCLUDE}
142+
)
143+
if(ZENOH_USB_UART)
144+
pico_enable_stdio_uart(${name} 1)
145+
pico_enable_stdio_usb(${name} 0)
146+
else()
147+
pico_enable_stdio_uart(${name} 0)
148+
pico_enable_stdio_usb(${name} 1)
149+
endif()
150+
pico_add_extra_outputs(${name})
151+
endfunction()
152+
153+
#add_example(z_get)
154+
add_example(z_pub)
155+
#add_example(z_pub_st)
156+
#add_example(z_pub_thr)
157+
#add_example(z_pull)
158+
#add_example(z_put)
159+
#add_example(z_queryable)
160+
#add_example(z_scout)
161+
#add_example(z_sub)
162+
#add_example(z_sub_st)
163+
#add_example(z_sub_thr)

0 commit comments

Comments
 (0)