RP2040 or RP2350 - W5100S, W5500 or W55RP20 network examples - Azure IoT Cloud functions, Azure IoT SDK, Azure IoT device client, ...
- 1. π― Azure IoT SDK examples
- 2. π Getting started
This project supports the following boards:
- WIZnet Ethernet HAT
- W5100S-EVB-Pico
- W5500-EVB-Pico
- W55RP20-EVB-Pico
- W6100-EVB-Pico
- W6300-EVB-Pico
- W5100S-EVB-Pico2
- W5500-EVB-Pico2
- W6100-EVB-Pico2
- W6300-EVB-Pico2
The development environment was tested on Windows using Visual Studio Code. Please refer to the official Raspberry Pi Pico SDK guide for setup instructions.
The project is compatible with the following WIZnet boards:
Board/Module Name | MCU | Ethernet Chip | Interface | Socket # | TX/RX Buffer | Notes |
---|---|---|---|---|---|---|
WIZnet Ethernet HAT | W5100S | SPI | 4 | 16KB | RP Pico-compatible | |
W5100S-EVB-Pico | RP2040 | W5100S | SPI | 4 | 16KB | |
W5500-EVB-Pico | RP2040 | W5500 | SPI | 8 | 32KB | |
W55RP20-EVB-Pico | RP2040 | W5500 | SPI (PIO) | 8 | 32KB | SiP: RP2040 + W5500 |
W6100-EVB-Pico | RP2040 | W6100 | SPI | 8 | 32KB | Supports IPv4/IPv6 |
W6300-EVB-Pico | RP2040 | W6300 | QSPI (PIO) | 8 | 64KB | Supports IPv4/IPv6 |
W5100S-EVB-Pico2 | RP2350 | W5100S | SPI | 4 | 16KB | |
W5500-EVB-Pico2 | RP2350 | W5500 | SPI | 8 | 32KB | |
W6100-EVB-Pico2 | RP2350 | W6100 | SPI | 8 | 32KB | Supports IPv4/IPv6 |
W6300-EVB-Pico2 | RP2350 | W6300 | QSPI (PIO) | 8 | 64KB | Supports IPv4/IPv6 |
Application | Description |
---|---|
examples | Basic Azure IoT Cloud functions with Azure IoT SDK. (NonOS + WIZnet W5100S, W5500 or W55RP20) |
3rd party SDKs & libraries are in the WIZnet-PICO-AZURE-C\libraries
directory of 'WIZnet-PICO-AZURE-C', the example for connecting Azure IoT Cloud.
SDKs & libraries | Description |
---|---|
ioLibrary_Driver | A library that can control WIZnet's W5x00 series Ethernet chip. |
mbedtls | It supports security algorithms and SSL and TLS connection. |
azure-iot-sdk-c | A collection of C source files consisting of Embedded C (C-SDK) that can be used by embedded applications to securely connect IoT devices to Azure IoT Cloud. |
pico-sdk | It makes a development environment for building software applications for the Pico platform. |
pico-extras | pico-extras has additional libraries that are not yet ready for inclusion the Pico SDK proper, or are just useful but don't necessarily belong in the Pico SDK. |
Each SDKs & libraries consists of submodule.
Please refer to Getting Started with the Raspberry Pi Pico and the README in the pico-sdk for information on getting up and running.
For Pico - W5100S, W5500 or W55RP20 platform, we need to port code, please check porting guide below.
Result of above porting can be found in WIZnet-PICO-AZURE-C\port\azure-iot-sdk-c
directory.
First, set the ethernet chip according to the evaluation board used in the following WIZnet-PICO-AZURE-C/CMakeLists.txt
file.
- WIZnet Ethernet HAT
- W5100S-EVB-Pico
- W5500-EVB-Pico
- W55RP20-EVB-Pico
- W6100-EVB-Pico
- W6300-EVB-Pico
- W5100S-EVB-Pico2
- W5500-EVB-Pico2
- W6100-EVB-Pico2
- W6300-EVB-Pico2
For example, when using WIZnet Ethernet HAT :
# Set board
set(BOARD_NAME WIZnet_Ethernet_HAT)
# set(BOARD_NAME W5100S_EVB_PICO)
# set(BOARD_NAME W5500_EVB_PICO)
# set(BOARD_NAME W55RP20_EVB_PICO)
# set(BOARD_NAME W6100_EVB_PICO)
# set(BOARD_NAME W6300_EVB_PICO)
# set(BOARD_NAME W5100S_EVB_PICO2)
# set(BOARD_NAME W5500_EVB_PICO2)
# set(BOARD_NAME W6100_EVB_PICO2)
# set(BOARD_NAME W6300_EVB_PICO2)
When using W6300-EVB-Pico:
# Set board
# set(BOARD_NAME WIZnet_Ethernet_HAT)
# set(BOARD_NAME W5100S_EVB_PICO)
# set(BOARD_NAME W5500_EVB_PICO)
# set(BOARD_NAME W55RP20_EVB_PICO)
# set(BOARD_NAME W6100_EVB_PICO)
set(BOARD_NAME W6300_EVB_PICO)
# set(BOARD_NAME W5100S_EVB_PICO2)
# set(BOARD_NAME W5500_EVB_PICO2)
# set(BOARD_NAME W6100_EVB_PICO2)
# set(BOARD_NAME W6300_EVB_PICO2)
You can easily configure SPI clock speed of the WIZnet chip in the CMakeLists.txt file. Enter your desired clock speed in the code below and build.
# Set WIZchip Clock Speed
add_definitions(-D_WIZCHIP_SPI_SCLK_SPEED=40) # SPEED MHz
When using W6300, you can configure the QSPI mode by modifying the board selection parameter.
For example, when using QSPI QUAD MODE:
# Set QSPI MODE for W6300
add_definitions(-D_WIZCHIP_QSPI_MODE_=QSPI_QUAD_MODE) # QSPI_QUAD_MODE
# add_definitions(-D_WIZCHIP_QSPI_MODE_=QSPI_DUAL_MODE) # QSPI_DUAL_MODE
# add_definitions(-D_WIZCHIP_QSPI_MODE_=QSPI_SINGLE_MODE) # QSPI_SINGLE_MODE
And find the line similar to this and replace it as your environment:
# Set the project root directory if it's not already defined, as may happen if
# the tests folder is included directly by a parent project, without including
# the top level CMakeLists.txt.
if(NOT DEFINED AZURE_SDK_DIR)
set(AZURE_SDK_DIR ${CMAKE_SOURCE_DIR}/libraries/azure-iot-sdk-c)
message(STATUS "AZURE_SDK_DIR = ${AZURE_SDK_DIR}")
endif()
if(NOT DEFINED WIZNET_DIR)
set(WIZNET_DIR ${CMAKE_SOURCE_DIR}/libraries/ioLibrary_Driver)
message(STATUS "WIZNET_DIR = ${WIZNET_DIR}")
endif()
if(NOT DEFINED MBEDTLS_LIB_DIR)
set(MBEDTLS_LIB_DIR ${CMAKE_SOURCE_DIR}/libraries/mbedtls)
message(STATUS "MBEDTLS_LIB_DIR = ${MBEDTLS_LIB_DIR}")
endif()
if(NOT DEFINED PORT_DIR)
set(PORT_DIR ${CMAKE_SOURCE_DIR}/port)
message(STATUS "PORT_DIR = ${PORT_DIR}")
endif()
In the following WIZnet-PICO-AZURE-C/examples/main.c
source file, find the line similar to this and replace it as you want:
(...)
// The application you wish to use should be uncommented
//
#define APP_TELEMETRY
//#define APP_C2D
//#define APP_CLI_X509
//#define APP_PROV_X509
// The application you wish to use DHCP mode should be uncommented
#define _DHCP
static wiz_NetInfo g_net_info =
{
.mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
.ip = {192, 168, 11, 2}, // IP address
.sn = {255, 255, 255, 0}, // Subnet Mask
.gw = {192, 168, 11, 1}, // Gateway
.dns = {8, 8, 8, 8}, // DNS server
#ifdef _DHCP
.dhcp = NETINFO_DHCP // DHCP enable/disable
#else
// this example uses static IP
.dhcp = NETINFO_STATIC
#endif
};
Copy & Paste proper connection string and key value from the Azure Portal to WIZnet-PICO-AZURE-C/examples/sample_certs.c
:
/* Paste in the your iothub connection string */
const char pico_az_connectionString[] = "[device connection string]";
const char pico_az_x509connectionString[] = "[device connection string]";
const char pico_az_x509certificate[] =
"-----BEGIN CERTIFICATE-----""\n"
"-----END CERTIFICATE-----";
const char pico_az_x509privatekey[] =
"-----BEGIN PRIVATE KEY-----""\n"
"-----END PRIVATE KEY-----";
const char pico_az_id_scope[] = "[ID Scope]";
const char pico_az_COMMON_NAME[] = "[custom-hsm-device]";
const char pico_az_CERTIFICATE[] =
"-----BEGIN CERTIFICATE-----""\n"
"-----END CERTIFICATE-----";
const char pico_az_PRIVATE_KEY[] =
"-----BEGIN PRIVATE KEY-----""\n"
"-----END PRIVATE KEY-----";
Run the following CMake commands from the root of the repository:
mkdir build
cd build
# As your environment, select
cmake .. -G "MSYS Makefiles" ## on MSYS2 (MinGW64) + Windows 10 Platform
# or
cmake .. -G "Visual Studio 15 2017" ## For Visual Studio 2017
# or
cmake .. -G "Visual Studio 16 2019" -A Win32
# or
cmake ..
cd examples
make
Then, copy generated "main.uf2" file into your RP-Pico board. Done!
With Visual Studio Code, each library set as a submodule is automatically patched, but if you do not use Visual Studio Code, each library set as a submodule must be manually patched with the Git commands below in each library directory.
/* Change directory */
// change to the 'ioLibrary_Driver' library directory.
cd [user path]/WIZnet-PICO-AZURE-C/libraries/ioLibrary_Driver
// e.g.
cd D:/RP2040/WIZnet-PICO-AZURE-C/libraries/ioLibrary_Driver
/* Patch */
git apply --ignore-whitespace ../../patches/01_iolibrary_driver_sntp.patch
β» If the board pauses when rebooting using W55RP20-EVB-Pico, patch it as follows.
// Patch cd D:/RP2040/WIZnet-PICO-AZURE-C git apply ./patches/0001_pico_sdk_clocks.patch
π Let's see this doc for iothub_ll_telemetry_sample application
π Let's see this doc for iothub_ll_c2d_sample application
π Let's see this doc for iothub_ll_client_x509_sample application
π Let's see this doc for prov_dev_client_ll_sample application