Skip to content
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

tcp/tls client and server connection with FreeRTOS, lwIP #457

Open
wants to merge 4 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
202 changes: 25 additions & 177 deletions RPi-Pico/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
cmake_minimum_required(VERSION 3.13)

# Pull in Pico and FreeRTOS
include(pico_sdk_import.cmake)
include(pico_extras_import_optional.cmake)
#include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)


if(PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0")
message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}")
# Pull in Pico, Pico-examples and FreeRTOS
# Pico Examples is only for referring ico_sdk_import.cmake and pico_extras_import_optional.cmake
set(PICO_BOARD pico_w)
include($ENV{PICO_EXAMPLES_PATH}/pico_sdk_import.cmake)
include($ENV{PICO_EXAMPLES_PATH}/pico_extras_import_optional.cmake)
include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)

set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT})
set(FREERTOS_KERNEL_PATH $ENV{FREERTOS-KERNEL_PATH})

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

project(wolf_pico_examples C CXX ASM)
Expand All @@ -17,182 +21,26 @@ set(CMAKE_CXX_STANDARD 17)
# Initialize the SDK
pico_sdk_init()


### Global Include Path
include_directories(config)
include_directories(include)
include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_lwip/include)
include_directories(${PICO_SDK_PATH}/src/rp2_common/hardware_rtc/include)
include_directories(${PICO_SDK_PATH}/lib/lwip/contrib/ports/freertos/include)
include_directories(${PICO_SDK_PATH}/lib/lwip/src/include)
include_directories(${PICO_SDK_PATH}/src/rp2_common/pico_async_context/include)

set(WOLFSSL_ROOT $ENV{WOLFSSL_ROOT})
#include_directories(${PICO_SDK_PATH}/lib/btstack/test/embedded/)
include_directories(${FREERTOS_KERNEL_PATH}/include/)
include_directories(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/include)
include_directories(${WOLFSSL_ROOT})
### End of Global Include Path


### wolfSSL/wolfCrypt library
file(GLOB_RECURSE WOLFSSL_SRC
"${WOLFSSL_ROOT}/src/*.c"
"${WOLFSSL_ROOT}/wolfcrypt/src/*.c"
)
list(REMOVE_ITEM WOLFSSL_SRC EXCLUDE REGEX
"${WOLFSSL_ROOT}/src/bio.c"
"${WOLFSSL_ROOT}/src/conf.c"
"${WOLFSSL_ROOT}/src/pk.c"
"${WOLFSSL_ROOT}/src/ssl_asn1.c"
"${WOLFSSL_ROOT}/src/ssl_bn.c"
"${WOLFSSL_ROOT}/src/ssl_misc.c"
"${WOLFSSL_ROOT}/src/x509.c"
"${WOLFSSL_ROOT}/src/x509_str.c"
"${WOLFSSL_ROOT}/wolfcrypt/src/evp.c"
"${WOLFSSL_ROOT}/wolfcrypt/src/misc.c"
)

add_library(wolfssl STATIC
${WOLFSSL_SRC}
)

target_compile_definitions(wolfssl PUBLIC
WOLFSSL_USER_SETTINGS
)
### End of wolfSSL/wolfCrypt library


### Test wolfCrypt algorithms
add_executable(testwolfcrypt
src/test_main.c
src/blink.c
${WOLFSSL_ROOT}/wolfcrypt/test/test.c
)

target_link_libraries(testwolfcrypt
wolfssl
pico_stdlib
pico_cyw43_arch_none
pico_rand
)

pico_enable_stdio_usb(testwolfcrypt 1)
pico_enable_stdio_uart(testwolfcrypt 0)

pico_add_extra_outputs(testwolfcrypt)
### End of Test wolfCrypt algorithms


### Benchmark wolfCrypt algorithms
add_executable(benchmark
src/bench_main.c
src/blink.c
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
)

target_link_libraries(benchmark
wolfssl
pico_stdlib
pico_cyw43_arch_none
pico_rand
)

pico_enable_stdio_usb(benchmark 1)
pico_enable_stdio_uart(benchmark 0)

pico_add_extra_outputs(benchmark)
### End of Benchmark wolfCrypt algorithms


### Wifi connection
add_executable(Wifi
src/blink.c
src/wifi.c
src/Wifi_main.c
)

target_compile_definitions(Wifi PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
PICO_CYW43_ARCH_POLL
NO_SYS=1
)

target_link_libraries(Wifi
pico_stdlib
pico_rand
pico_lwip
pico_cyw43_arch
pico_lwip_nosys
pico_async_context_poll
)


pico_enable_stdio_usb(Wifi 1)
pico_enable_stdio_uart(Wifi 0)

pico_add_extra_outputs(Wifi)
### End of Wifi connection


### TCP Client
add_executable(tcp_Client
src/blink.c
src/wifi.c
src/tcp.c
src/tcpClient_main.c
)

target_compile_definitions(tcp_Client PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
PICO_CYW43_ARCH_POLL
NO_SYS=1
)

target_link_libraries(tcp_Client
pico_stdlib
pico_rand
pico_lwip
pico_cyw43_arch
pico_lwip_nosys
pico_async_context_poll
)


pico_enable_stdio_usb(tcp_Client 1)
pico_enable_stdio_uart(tcp_Client 0)

pico_add_extra_outputs(tcp_Client)
### End of TCP Client


### TLS Client
add_executable(tls_Client
src/blink.c
src/wifi.c
src/tcp.c
src/tlsClient_main.c
)

target_compile_definitions(tls_Client PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\"
PICO_CYW43_ARCH_POLL
NO_SYS=1
)

target_link_libraries(tls_Client
pico_stdlib
pico_rand
pico_lwip
pico_cyw43_arch
pico_lwip_nosys
pico_async_context_poll
wolfssl
)
### End of Global Include Path

include(wolfssl_import.cmake)

pico_enable_stdio_usb(tls_Client 1)
pico_enable_stdio_uart(tls_Client 0)
add_subdirectory(testwolfcrypt)
add_subdirectory(benchmark)
add_subdirectory(tcp_client)
add_subdirectory(tcp_server)
add_subdirectory(tls_client)
add_subdirectory(tls_server)

pico_add_extra_outputs(tls_Client)
### End of TLS Client
83 changes: 71 additions & 12 deletions RPi-Pico/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,77 @@
## Getting Started

1. Put wolfSSL source files under this directory.
RPi-Pico/wolfssl
This example includes wolfSSL test, benchmark, Wifi, TCP/TLS client.

2. Setup pico-sdk and set PICO_SDK_PATH
export PICO_SDK_PATH=/your/pico-sdk/path

3. cmake and make
$ cd RPi-Pico
$ mkdir build
$ cd build
$ cmake -DPICO_BOARD=pico_w ..
$ make
### 1. Download files

4. Output is to USB serial
```
$ git clone https://github.com/raspberrypi/pico-sdk
$ git clone https://github.com/raspberrypi/pico-examples
$ git clone hhttps://github.com/FreeRTOS
$ git clone https://github.com/wolfssl/wolfssl
$ git clone https://github.com/wolfssl-jp/RPi-pico-w
```



### 2. Define path

```
$ export PICO_SDK_PATH=/your/pico-sdk/path
$ export PICO_EXAMPLES_PATH=/your/pico-examples/path
$ export FREERTOS_KERNEL_PATH=/your/FreeRTOS-kernel/path
$ export WOLFSSL_ROOT=/your/wolfssl-root/path
```

### 3. cmake and make

```
$ cd wolfssl-examples/RPi-Pico
$ cmake -DPICO_BOARD=pico_w -DWIFI_SSID=your-wifi-ssid\
-DWIFI_PASSWORD=your-wifi-password\
-DTCP_SERVER=ip-addr\
-DDATETIME=yymmddhhmmss .
$ make
```

DATETIME is for certificate validity check. Not need to be very acurrate.

### 4. Target files

- testwolfcrypt.uf2
- benchmark.uf2
- tcp_Client.uf2
- tls_Client.uf2
- tcp_Server.uf2
- tls_Server.uf2

Console output is to USB serial


### 5. Test server

$ git clone https://github.com/wolfssl/wolfssl-examples
$ cd wolfssl-examples/tls
$ make

TCP Server:
$ ./server-tcp

TLS Server:
$ ./server-tls

TCP Client:
$ ./client-tcp xxx.xxx.xxx.xxx

TLS Client:
$ ./client-tls xxx.xxx.xxx.xxx



### References

- Raspberry Pi Pico and Pico W<br>
https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html

- Connecting to the Internet with Raspberry Pi Pico W<br>
https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf
21 changes: 21 additions & 0 deletions RPi-Pico/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_executable(benchmark
../src/bench_main.c
../src/blink.c
${WOLFSSL_ROOT}/wolfcrypt/benchmark/benchmark.c
)

target_link_libraries(benchmark
wolfssl
pico_stdlib
pico_cyw43_arch_none
pico_rand
)

target_compile_definitions(benchmark PRIVATE
WOLFSSL_RPI_PICO
)

pico_enable_stdio_usb(benchmark 1)
pico_enable_stdio_uart(benchmark 1)

pico_add_extra_outputs(benchmark)
Loading