Skip to content

Commit 123d562

Browse files
authored
Merge pull request #516 from yota22721/pico_w
TCP/TLS client and server connection with FreeRTOS, lwIP
2 parents 885cfd6 + f737462 commit 123d562

33 files changed

+1763
-748
lines changed

RPi-Pico/CMakeLists.txt

Lines changed: 16 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ cmake_minimum_required(VERSION 3.13)
33
# Pull in Pico and FreeRTOS
44
include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake)
55
#include(pico_extras_import_optional.cmake)
6-
#include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
6+
include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
77

88

99
if(PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
10-
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
10+
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0(or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
1111
endif()
1212

1313
project(wolf_pico_examples C CXX ASM)
@@ -31,214 +31,27 @@ endif()
3131
include_directories(config)
3232
include_directories(include)
3333
include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_lwip/include)
34+
include_directories(${PICO_SDK_PATH}/src/rp2_common/hardware_rtc/include)
3435
include_directories(${PICO_SDK_PATH}/lib/lwip/contrib/ports/freertos/include)
3536
include_directories(${PICO_SDK_PATH}/lib/lwip/src/include)
3637
include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_async_context/include)
38+
#include_directories(${PICO_SDK_PATH}/lib/btstack/test/embedded/)
3739

3840
set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT})
41+
set(FREERTOS_KERNEL_PATH $ENV{FREERTOS_KERNEL_PATH})
42+
include_directories(${FREERTOS_KERNEL_PATH}/include/)
43+
include_directories(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/include)
3944
include_directories(${WOLFSSL_ROOT})
4045
### End of Global Include Path
4146

47+
include(wolfssl_import.cmake)
4248

43-
### wolfSSL/wolfCrypt library
44-
file(GLOB WOLFSSL_SRC
45-
"${WOLFSSL_ROOT}/src/*.c"
46-
"${WOLFSSL_ROOT}/wolfcrypt/src/*.c"
47-
"${WOLFSSL_ROOT}/wolfcrypt/src/port/rpi_pico/*"
48-
)
49-
list(REMOVE_ITEM WOLFSSL_SRC EXCLUDE REGEX
50-
"${WOLFSSL_ROOT}/src/bio.c"
51-
"${WOLFSSL_ROOT}/src/conf.c"
52-
"${WOLFSSL_ROOT}/src/pk.c"
53-
"${WOLFSSL_ROOT}/src/ssl_asn1.c"
54-
"${WOLFSSL_ROOT}/src/ssl_bn.c"
55-
"${WOLFSSL_ROOT}/src/ssl_misc.c"
56-
"${WOLFSSL_ROOT}/src/x509.c"
57-
"${WOLFSSL_ROOT}/src/x509_str.c"
58-
"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c"
59-
"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c"
60-
)
61-
62-
add_library(wolfssl STATIC
63-
${WOLFSSL_SRC}
64-
)
65-
66-
target_compile_definitions(wolfssl PUBLIC
67-
WOLFSSL_USER_SETTINGS
68-
)
69-
if (${PICO_PLATFORM} STREQUAL "rp2350-arm-s")
70-
add_compile_definitions(wolfssl WOLFSSL_SP_ARM_CORTEX_M_ASM)
71-
elseif (${PICO_PLATFORM} STREQUAL "rp2350-riscv")
72-
add_compile_definitions(wolfSSL WOLFSSL_SP_RISCV32)
73-
else()
74-
add_compile_definitions(wolfssl WOLFSSL_SP_ARM_THUMB_ASM)
75-
endif()
76-
77-
target_link_libraries(wolfssl
78-
pico_stdlib
79-
pico_rand
80-
)
81-
### End of wolfSSL/wolfCrypt library
82-
83-
84-
### Test wolfCrypt algorithms
85-
add_executable(testwolfcrypt
86-
src/test_main.c
87-
${WOLFSSL_ROOT}/wolfcrypt/test/test.c
88-
)
89-
90-
target_link_libraries(testwolfcrypt
91-
wolfssl
92-
pico_stdlib
93-
pico_rand
94-
)
95-
96-
if (USE_UART)
97-
pico_enable_stdio_usb(testwolfcrypt 0)
98-
pico_enable_stdio_uart(testwolfcrypt 1)
99-
else()
100-
pico_enable_stdio_usb(testwolfcrypt 1)
101-
pico_enable_stdio_uart(testwolfcrypt 0)
102-
endif()
103-
104-
pico_add_extra_outputs(testwolfcrypt)
105-
### End of Test wolfCrypt algorithms
106-
107-
108-
### Benchmark wolfCrypt algorithms
109-
add_executable(benchmark
110-
src/bench_main.c
111-
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
112-
)
113-
114-
target_link_libraries(benchmark
115-
wolfssl
116-
pico_stdlib
117-
pico_rand
118-
)
119-
120-
if (USE_UART)
121-
pico_enable_stdio_usb(benchmark 0)
122-
pico_enable_stdio_uart(benchmark 1)
123-
else()
124-
pico_enable_stdio_usb(benchmark 1)
125-
pico_enable_stdio_uart(benchmark 0)
126-
endif()
127-
128-
129-
pico_add_extra_outputs(benchmark)
130-
### End of Benchmark wolfCrypt algorithms
131-
132-
133-
if (USE_WIFI)
134-
### Wifi connection
135-
add_executable(Wifi
136-
src/blink.c
137-
src/wifi.c
138-
src/wifi_main.c
139-
)
140-
141-
target_compile_definitions(Wifi PRIVATE
142-
WIFI_SSID=\"${WIFI_SSID}\"
143-
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
144-
PICO_CYW43_ARCH_POLL
145-
NO_SYS=1
146-
)
147-
148-
target_link_libraries(Wifi
149-
pico_stdlib
150-
pico_rand
151-
pico_lwip
152-
pico_cyw43_arch
153-
pico_lwip_nosys
154-
pico_async_context_poll
155-
)
156-
157-
if (USE_UART)
158-
pico_enable_stdio_usb(Wifi 0)
159-
pico_enable_stdio_uart(Wifi 1)
160-
else()
161-
pico_enable_stdio_usb(Wifi 1)
162-
pico_enable_stdio_uart(Wifi 0)
163-
endif()
164-
165-
pico_add_extra_outputs(Wifi)
166-
### End of Wifi connection
167-
endif()
168-
169-
if (USE_WIFI)
170-
### TCP Client
171-
add_executable(tcp_Client
172-
src/blink.c
173-
src/wifi.c
174-
src/tcp.c
175-
src/tcpClient_main.c
176-
)
177-
178-
target_compile_definitions(tcp_Client PRIVATE
179-
WIFI_SSID=\"${WIFI_SSID}\"
180-
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
181-
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
182-
PICO_CYW43_ARCH_POLL
183-
NO_SYS=1
184-
)
185-
186-
target_link_libraries(tcp_Client
187-
pico_stdlib
188-
pico_rand
189-
pico_lwip
190-
pico_cyw43_arch
191-
pico_lwip_nosys
192-
pico_async_context_poll
193-
)
194-
195-
if (USE_UART)
196-
pico_enable_stdio_usb(tcp_Client 0)
197-
pico_enable_stdio_uart(tcp_Client 1)
198-
else()
199-
pico_enable_stdio_usb(tcp_Client 1)
200-
pico_enable_stdio_uart(tcp_Client 0)
49+
add_subdirectory(testwolfcrypt)
50+
add_subdirectory(benchmark)
51+
if (USE_WIFI)
52+
add_subdirectory(wifi)
53+
add_subdirectory(tcp_client)
54+
add_subdirectory(tcp_server)
55+
add_subdirectory(tls_client)
56+
add_subdirectory(tls_server)
20157
endif()
202-
203-
pico_add_extra_outputs(tcp_Client)
204-
### End of TCP Client
205-
endif()
206-
207-
if (USE_WIFI)
208-
### TLS Client
209-
add_executable(tls_Client
210-
src/blink.c
211-
src/wifi.c
212-
src/tcp.c
213-
src/tlsClient_main.c
214-
)
215-
216-
target_compile_definitions(tls_Client PRIVATE
217-
WIFI_SSID=\"${WIFI_SSID}\"
218-
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
219-
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
220-
PICO_CYW43_ARCH_POLL
221-
NO_SYS=1
222-
)
223-
224-
target_link_libraries(tls_Client
225-
pico_stdlib
226-
pico_rand
227-
pico_lwip
228-
pico_cyw43_arch
229-
pico_lwip_nosys
230-
pico_async_context_poll
231-
wolfssl
232-
)
233-
234-
if (USE_UART)
235-
pico_enable_stdio_usb(tls_Client 0)
236-
pico_enable_stdio_uart(tls_Client 1)
237-
else()
238-
pico_enable_stdio_usb(tls_Client 1)
239-
pico_enable_stdio_uart(tls_Client 0)
240-
endif()
241-
242-
pico_add_extra_outputs(tls_Client)
243-
### End of TLS Client
244-
endif()

RPi-Pico/README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ export WOLFSSL_ROOT=/path/to/wolfssl/source
3838
export PICO_SDK_PATH=/path/to/pico-sdk
3939
```
4040

41-
### 3. cmake and make
41+
### 3. Set `FREERTOS_KERNEL_PATH`
42+
If you want to use TCP/TLS server or client, You also need to have the [FreeRTOS-Kernel GitHub repository](https://github.com/FreeRTOS/FreeRTOS-Kernel).
43+
```
44+
export FREERTOS_KERNEL_PATH=/path/to/FreeRTOS-Kernel
45+
```
46+
47+
### 4. cmake and make
4248

4349
The following CMAKE options are available:
4450

@@ -53,13 +59,27 @@ To use the RP2350 in RISC-V mode, add `-DPICO_PLATFORM=rp2350-riscv`.
5359

5460
```
5561
$ cd RPi-Pico
56-
$ mkdir build
57-
$ cd build
5862
$ cmake -DPICO_BOARD=pico_w ..
5963
$ make
6064
```
6165

62-
### 4. Upload to the Pico
66+
The build produces the following UF2 images:
67+
68+
- testwolfcrypt.uf2
69+
70+
- benchmark.uf2
71+
72+
- Wifi.uf2
73+
74+
- tcp_Client.uf2
75+
76+
- tls_Client.uf2
77+
78+
- tcp_Server.uf2
79+
80+
- tls_Server.uf2
81+
82+
### 5. Upload to the Pico
6383

6484
Hold the boot button and plug the Pico into your computer, you can then
6585
drag/drop a `.uf2` to the Pico. It will stop becoming a USB mass storage device
@@ -71,7 +91,7 @@ sudo picotool load benchmark.uf2
7191
sudo picotool reboot
7292
```
7393

74-
### 5. Serial output
94+
### 6. Serial output
7595

7696
If you have not set `USE_UART`, once rebooted the USB port will turn into an
7797
"Abstract Control Module" serial port. On Linux this will likely be

RPi-Pico/benchmark/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
add_executable(benchmark
2+
../src/bench_main.c
3+
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
4+
)
5+
6+
target_link_libraries(benchmark
7+
wolfssl
8+
pico_stdlib
9+
pico_rand
10+
)
11+
12+
target_compile_definitions(benchmark PRIVATE
13+
WOLFSSL_RPI_PICO
14+
)
15+
16+
if (USE_UART)
17+
pico_enable_stdio_usb(benchmark 0)
18+
pico_enable_stdio_uart(benchmark 1)
19+
else()
20+
pico_enable_stdio_usb(benchmark 1)
21+
pico_enable_stdio_uart(benchmark 0)
22+
endif()
23+
24+
pico_add_extra_outputs(benchmark)

0 commit comments

Comments
 (0)