Raspberry Pi Pico[2] + W5100
Overview
This tutorial shows how Mongoose Library can be used on an RP2040- or RP2350-based board with the addition of a W5100 chip, using Mongoose's built-in TCP/IP stack.
Board options
You can use either a board like the W5100S-EVB-Pico, that has an RP2040 and a W5100S with an Ethernet jack, or a W5100S-EVB-Pico2, that has an RP2350 and a W5100S with an Ethernet jack, or you can use for example a Raspberry Pi Pico or Pico 2 wired to an add-on board with the W5100.
W5100S-EVB-Pico and W5100S-EVB-Pico2
The default SPI pin selection is just for these boards:
W5100 add-on
With boards like these, you have to wire the SPI interface and power connections between the boards:
W5100 | Raspberry Pi Pico [2] | ||
---|---|---|---|
GND | GND | 38 | |
SCLK | GPIO18/SPI0_SCK | 24 | |
SCS | GPIO17/SPI0_CSn | 22 | |
MOSI | GPIO19/SPI0_TX | 25 | |
MISO | GPIO16/SPI0_RX | 21 | |
3.3V | 3V3 | 36 |
With this wiring, the Pico, powered from USB, will provide 3.3V to the add-on board. You can also power this board with a 5V source, which you can also take from the Pico. However, good practices dictate that you add series resistors on every signal connection, as the RP2040 and the W5100 will have different 3.3V power supplies that will not match. So, we recommend you follow the wiring suggested above.
Other RP2040- or RP2350-based boards
If you choose to use any other board, either mimic the wiring above or change this line in main.c
accordingly:
Compilation options
Network operations need a time base to calculate timeouts; this, as well as random number generation, will be provided by the SDK, and Mongoose needs to know how to link to them. We define these and other compilation options in mongoose_config.h
MG_ARCH = MG_ARCH_PICOSDK
- configures Mongoose to work with Raspberry Pi's Pico-SDKMG_ENABLE_TCPIP = 1
- enables the built-in TCP/IP stackMG_ENABLE_DRIVER_W5100
- enables the built-in driver for the W5100MG_ENABLE_PACKED_FS = 1
- enables the embedded filesystem support
Check our Wizard for full source code
SPI low-level functions
We provide a basic set of functions to do transactions, that is, a couple of functions to begin and end the transaction (enable and disable chip select) and a third function to transfer a byte (send one, receive one, simultaneously). These are of course wrappers to SDK functions: