Using WiFi in the Raspberry Pi Pico (Part 1)

 The Raspbery Pi Pico W adds to the Pico the ability to do network communication using WiFi (and, maybe, Bluetooth in the future). For starters, I will focus on C/C++ programming. The first steps in learning about the way WiFi is implemented and how to use it are the SDK documentation and the official examples. For those who want an easier and faster path, there is also MicroPython support.


My first Pico W!


The WiFi chip used in the Pico W (CYW43439 ) is a MAC (Media Access Control) layer solution. This means that it implements the physical layer with its addressing (the MAC address) and the way devices share a common communication medium.

For most practical uses we need other layers above the MAC. Theses layers are implemented in the RP2040 software. In these days, the most used network protocol is TCP/IP.

The support for WiFi and TCP/IP in the RP2040 C/C++ SDK is done by three parts:

  • pico_cyw43_arch: this part connects the other two so they can (potentially) be replaced by compatible alternative implementations. It also manages the LED that is connected to the WiFi chip.
  • the TCP/IP stack: lwIP is used by the SDK.
  • cyw43_driver: this is the driver for the chip used in the Pico.
Both the driver and the TCP/IP stack have routines that must be called periodically. The SDK has two versions of the pico_cyw43_arch that implement different solutions for this:
  • 'poll': here it is the application responsibility to periodically call the cyw43_arch_poll routine. The communication functions are not interrupt or multiple core safe, you need to enclose them with calls to  cyw43_arch_lwip_begin() and cyw43_arch_lwip_end() in the non-interrupt code.
  • 'thread_safe_background': this is a more sophisticated option where things are done automatically in background an the functions are interrupt and multiple core safe. There is an specific version of this for use with FreeRTOS.
If all you want is to control the LED that is now connected to the CYW43439, and need no WiFi communication, there is a third version of pico_cyw43_arch just for this.

Comments

Popular posts from this blog