cyw43439 Driver

repository·main·Indexed 42 days ago

https://github.com/soypat/cyw43439

A heapless driver for the CYW43439 WiFi+Bluetooth integrated circuit, specifically designed for use with the Raspberry Pi Pico and TinyGo. It provides low-level access to the chip's backplane, WLAN data via SPI, and the Bluetooth HCI interface, including methods like HCIReadWriter(), WriteHCI(), and ReadHCI().

Tokens
9.5K
Snippets
43
Records
63
Agent score
51%

What's inside cyw43439

  1. Analyze CYW43439 SPI signals using a logic analyzer

    main

    The cyw43439-signal-analyze program implements the SPI bus via software bit-banging. It broadcasts the CYW43439 responses to specific mock output pins, allowing you to observe the SPI traffic using a logic analyzer (e.g., Saleae or Digital Analog Discovery).

    In the current implementation, the signals are mapped to the following GPIO pins:

    • Data (Read/Write): machine.GPIO4
    • Clock (CLK): machine.GPIO5
    • Chip Select (CS): machine.GPIO6
    // Mock pins can be any not shared by original implementation.
    // Attach your logic analyzer to these.
    MOCK_DAT = machine.GPIO4
    MOCK_CLK = machine.GPIO5
    MOCK_CS  = machine.GPIO6
  2. Install stringer for enum generation

    main

    The project uses stringer to generate string representations for enums. This is automated via go generate in the repository root. To install the tool, run:

    go install golang.org/x/tools/cmd/stringer@latest
  3. Use legacy seqs networking for 'Automate Your Home Using Go' book examples

    main

    The current version of this repository uses the lneto networking library. If you are following the Automate Your Home Using Go book and wish to use the deprecated seqs library to match the book's examples verbatim, check out the specific commit before lneto support was merged:

    git checkout 0a1d121ea3
  4. Configure WiFi credentials and server address for HTTP Client

    main

    Before flashing the HTTP Client example, you must configure your network credentials and the target server address.

    1. WiFi Credentials: Create a secrets.go file by copying ../common/secrets.go.template. Populate it with your WiFi SSID and password. For open networks, use password="".
    2. Server Address: In ./examples/http-client/main.go, update the server address constant to match your server's address:port combination.
  5. Run the HTTP Client example on Pico W

    main

    This example demonstrates end-to-end network stack initialization and a TCP connection to send an HTTP request to a server on the local network.

    Note: This example is designed for local network communication. To reach an external network over the internet, you must implement DNS and Router management (refer to the ntp example in the repository for guidance).

    # 1. Run the local server
    go run ./examples/server
    
    # 2. Flash the Pico W
    tinygo flash -target=pico -stack-size=8kb -monitor ./examples/http-client/
  6. Flash the CYW43439 Signal Analyze program to a Pico W

    main

    To flash the cyw43439-signal-analyze program onto a Raspberry Pi Pico W using TinyGo, use the tinygo flash command with the pico target and the cy43nopio build tag. This specific build uses a software bit-bang SPI implementation to allow signal analysis.

    tinygo flash -target=pico -tags=cy43nopio ./examples/cyw43439-signal-analyze
  7. Set up WiFi credentials for examples

    main

    Before running WiFi-related examples, you must provide your network credentials in the examples/common directory:

    1. Create a file named ssid.text in examples/common/ and write your SSID into it (do not add a final newline).
    2. Create a file named password.text in examples/common/ and write your WiFi password into it (do not add a final newline). If the password is empty, an open network is assumed.
  8. Understand MTU and Frame Size limits

    main

    When preparing data for transmission, you must respect the hardware's frame size limits. The package defines these constants based on the SDPCM and BDC protocol overhead:

    • MaxFrameSize: The maximum ethernet frame size (including ethernet data) that can be sent through the chip (calculated as 2048 - sdpcmOverhead).
    • MTU: The Maximum Transmission Unit (the maximum ethernet payload size) expected by network stacks like lneto. It is calculated as MaxFrameSize - ethHeaderSize.

    If you attempt to transmit a packet exceeding these limits, you will encounter errTxPacketTooLarge.

  9. Understand driver log levels

    main

    The driver defines specific log levels to categorize output:

    LevelConstant/ValueDescription
    TracelevelTrace (slog.LevelDebug - 2)Extremely verbose diagnostic information.
    DevicedeviceLevel (slog.LevelDebug - 1)Logs originating from the CY43439 hardware itself.
    Debugslog.LevelDebugStandard debug information.
    Infoslog.LevelInfoGeneral operational information.
    Warnslog.LevelWarnWarning conditions.
    Errorslog.LevelErrorError conditions.

    Note: A higher currentLevel in your logger configuration will suppress more verbose logs. For example, if your logger is set to slog.LevelInfo, trace, device, and debug logs will not be printed.

  10. Understand CYW43439 Command Functions

    main

    The CYW43439 bus uses a Function type to identify which block the command is targeting. The available functions are:

    • bus (0b00): All SPI-specific registers.
    • backplane (0b01): Registers and memories belonging to other blocks in the chip (64 bytes max).
    • wlan / dma1 (0b10): DMA channel 1. WLAN packets up to 2048 bytes.
    • dma2 (0b11): DMA channel 2 (optional). Packets up to 2048 bytes.
    • invalid: Used when a command cannot be parsed correctly.
  11. Select operation modes using opMode

    main

    The opMode type is a bitfield used to enable specific hardware functions. You can combine modes using the bitwise OR (|) operator.

    Available modes:

    • ModeWifi (via constant modeWifi)
    • ModeBluetooth (via constant modeBluetooth)

    Example:

    // Enable both WiFi and Bluetooth
    mode := cyw43439.ModeWifi | cyw43439.ModeBluetooth
  12. Understand the cywparse output format

    main

    The tool outputs a line for each parsed transaction. The format follows this pattern:

    [Endian] cmd=0x[Command] addr=0x[Address] fn=[Function] sz=0x[Size] w=[WriteFlag] inc=[AutoInc] [Payload]

    Field Definitions:

    • Endian: BE (Big Endian) or LE (Little Endian).
    • cmd: The full 32-bit command value.
    • addr: The target hardware address.
    • fn: The function identifier (mapped to bus, backplane, wlan, or dma2).
    • sz: The size of the transaction.
    • w: Write flag (1 if it is a write operation, 0 otherwise).
    • inc: Auto-increment flag.
    • Payload: For write operations, a hex-encoded string of the data (grouped by 4 bytes). If -hex-dump is used, a standard Go hex dump follows on a new line.