/cyw43439

Driver for the Wifi+bluetooth integrated circuit on the pico.

Primary LanguageGoMIT LicenseMIT

cyw43439

Driver for the Wifi+bluetooth integrated circuit on the pico.

Examples

To run the blinky example:

tinygo flash -target=pico -stack-size=8kb -monitor  ./examples/blinky
To run Wifi examples you must first set your wifi credentials:
  1. Clone this repository

  2. Rename examples/common/secrets.go.template to have the .go extension and edit the contents with ssid and pass strings set to your WIFI SSID and Password, respecively. If pass is not set then an open network is assumed.

  3. Run any of the examples in the examples directory

    Example of how to run the DHCP example:

    tinygo flash -target=pico -stack-size=8kb -monitor  ./examples/dhcp

Debugging and heap allocations

The examples use the soypat/seqs networking stack library. One can enable heap debugging by using the debugheaplog build tag:

Example:

tinygo flash -target=pico -stack-size=8kb -monitor -tags=debugheaplog  ./examples/dhcp

This will use a simpler logger implementation within the seqs package that avoids all allocations and will also log heap increments on lines starting with the [ALLOC] text.

Contributions

PRs welcome! Please read most recent developments on this issue before contributing.

FYI

Peripheral side APIs

Examples:

  • APA102 addressable LED strip.
    • Here is the Go driver: well programmed and simple. Follows good practices like storing buffers in-struct as arrays (buf field) to avoid heap allocations and encouraging better CPU memory access patterns.
    • I could not find a high quality C or C++ driver, there seems to be a different driver for each microcontroller. Here's an ESP8266 driver for the APA102 which seemed reasonably well programmed.
  • Wifinina SPI driver for ESP32 wifi with TCP/IP.

Microcontroller side APIs

The CYW43439 driver will have minimal microcontroller side API code, though it does not hurt to read up a little bit on it.

It may be of interest to the reader to know a bit of how one ports microcontroller specific code from C to Go. This code is characterized by the heavy use of volatile memory registers and data structures that map peripheral functionality directly to these segments of volatile memory.

For the case of the RP2040 (the raspberry pi's pico microcontroller) one can find most of microcontroller specific code in the TinyGo machine package- Look for filenames starting with machine_rp2040. In the author's opinion one of the cleanest peripheral API's is the RP2040's I2C driver, which you may find in machine_rp2040_i2c.go in said package.

The C counterparts are in the pico-sdk's rp2_common directory. The I2C counterpart includes the header file with function signatures and type definitions... and more interestingly, the actual code under hardware_i2c/i2c.c. Do note the port is almost direct. Some functions have been grouped differently and have slightly different signatures in the Go version.

The PWM API is much more closely matched between the C and Go version, albeit much simpler.

Go and TinyGo Ethernet/IP/TCP stack comparisons

stack comparison

Install stringer command

go install golang.org/x/tools/cmd/stringer@latest