Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/net/ntpclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// It creates a UDP connection to request the current time and parse the
// response from a NTP server. The system time is set to NTP time.

//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw || arduino_uno_r4_wifi

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/socket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// nc -lk 8080

//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw || arduino_uno_r4_wifi

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/tcpclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// nc -lk 8080

//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw || arduino_uno_r4_wifi

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/tcpecho/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// $ nc 10.0.0.2 8080 <file >copy ; cmp file copy

//go:build ninafw || wioterminal
//go:build ninafw || wioterminal || arduino_uno_r4_wifi

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/tlsclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security

//go:build ninafw || wioterminal || comboat_fw
//go:build ninafw || wioterminal || comboat_fw || arduino_uno_r4_wifi

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/webclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// }
// ---------------------------------------------------------------------------

//go:build ninafw || wioterminal || comboat_fw
//go:build ninafw || wioterminal || comboat_fw || arduino_uno_r4_wifi

package main

Expand Down
27 changes: 27 additions & 0 deletions netlink/probe/unor4wifi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build arduino_uno_r4_wifi

package probe

import (
"machine"

"tinygo.org/x/drivers/netdev"
"tinygo.org/x/drivers/netlink"
"tinygo.org/x/drivers/unor4wifi"
)

func Probe() (netlink.Netlinker, netdev.Netdever) {

cfg := unor4wifi.Config{
// UART3 is the SCI1 link to the ESP32-S3 AT interface.
Uart: machine.UART3,
Tx: machine.UART3_TX_PIN,
Rx: machine.UART3_RX_PIN,
BaudRate: 115200,
}

dev := unor4wifi.New(&cfg)
netdev.UseNetdev(dev)

return dev, dev
}
3 changes: 3 additions & 0 deletions smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,6 @@ tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb
# network examples (comboat)
tinygo build -size short -o ./build/test.hex -target=elecrow-rp2040 -stack-size 8kb ./examples/net/tlsclient/
tinygo build -size short -o ./build/test.hex -target=elecrow-rp2350 -stack-size 8kb ./examples/net/ntpclient/
# network examples (unor4wifi)
tinygo build -size short -o ./build/test.hex -target=arduino-uno-r4-wifi -stack-size 2kb ./examples/net/tcpclient/
tinygo build -size short -o ./build/test.hex -target=arduino-uno-r4-wifi -stack-size 2kb ./examples/net/ntpclient/
75 changes: 75 additions & 0 deletions unor4wifi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# unor4wifi

WiFi network driver for the Arduino UNO R4 WiFi.

The board has a Renesas RA4M1 main MCU and an ESP32-S3 WiFi module. The
ESP32-S3 runs the Arduino [uno-r4-wifi-usb-bridge][bridge] firmware. The
RA4M1 talks to it over UART (SCI1, `machine.UART3`) with an AT style
protocol. This driver speaks that protocol and implements the
[netlink](../netlink) and [netdev](../netdev) interfaces, so the standard
`net` package works.

Keep the stock bridge firmware on the ESP32-S3. Do not flash the ESP32-S3.

## Supported

- WiFi station mode (`ConnectModeSTA`) with WPA2 or open networks
- WiFi access point mode (`ConnectModeAP`)
- TCP client and TCP server
- UDP
- DNS lookup

## Not supported

- TLS offload in the ESP32-S3. Use the Go `crypto/tls` package instead.
- Socket options (`SetSockOpt` returns `netdev.ErrNotSupported`).
- BLE. The bridge has HCI pass-through commands, but this driver does not
use them.

## Usage

```go
import (
"tinygo.org/x/drivers/netlink"
"tinygo.org/x/drivers/netlink/probe"
)

link, _ := probe.Probe()
err := link.NetConnect(&netlink.ConnectParams{
Ssid: "my-ssid",
Passphrase: "my-passphrase",
})
```

Then use `net.Dial`, `net.Listen` and so on.

The RA4M1 has 256 KB of flash. The `net/http` package does not fit.
Use the `net` package directly, or a small client such as the `ntpclient`
or `tcpclient` examples.

Build with `-target=arduino-uno-r4-wifi -stack-size 2kb`. The RA4M1 has
32 KB of RAM and each goroutine gets a stack of the given size, so a larger
stack size leaves too little heap. The network examples that fit in flash
(`socket`, `tcpclient`, `tcpecho`, `ntpclient`, `tlsclient`, `webclient`)
carry the `arduino_uno_r4_wifi` build tag.

Do not use `io.Copy` with a `net.TCPConn` on this board. It allocates a
32 KB buffer. Use a `Read`/`Write` loop with a small buffer instead.

## Protocol

Commands and response formats are defined in the bridge firmware:

- [commands.h][commands]
- [cmds_wifi_netif.h][netif] (TCP client and server)
- [cmds_wifi_udp.h][udp]

Text responses look like `+CMD:<data>\r\nOK\r\n`. Binary responses from
`+CLIENTRECEIVE` and `+UDPREAD` look like `+CMD:<len>|<len bytes>OK\r\n`.
Payload for `+CLIENTSEND` and `+UDPWRITE` follows the command line as raw
bytes.

[bridge]: https://github.com/arduino/uno-r4-wifi-usb-bridge
[commands]: https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/UNOR4USBBridge/commands.h
[netif]: https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/UNOR4USBBridge/cmds_wifi_netif.h
[udp]: https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/UNOR4USBBridge/cmds_wifi_udp.h
16 changes: 16 additions & 0 deletions unor4wifi/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package unor4wifi

type debug uint8

const (
debugBasic debug = 1 << iota // show fw version, mac addr, etc
debugNetdev // show netdev entry points
debugCmd // show AT cmds

debugOff = 0
debugAll = debugBasic | debugNetdev | debugCmd
)

func debugging(want debug) bool {
return (_debug & want) != 0
}
Loading