Skip to content

Commit

Permalink
Add wifi driver comboat for Elecrow W5 rp2040 and rp2350 devices (#741)
Browse files Browse the repository at this point in the history
* Add wifi driver comboat for Elecrow W5 rp2040 and rp2350 devices

Combo-AT driver uses AT command set to talk to onboard rtl8720d wifi
device.  The driver supports UDP/TCP/TLS clients in Wifi STA mode.
Support for UDP/TCP servers is not supported, currently.

https://aithinker-combo-guide.readthedocs.io/en/latest/docs/instruction/index.html
https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-set/index.html
https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-examples/index.html

* Add wifi driver comboat for Elecrow W5 rp2040 and rp2350 devices

Combo-AT driver uses AT command set to talk to onboard rtl8720d wifi
device.  The driver supports UDP/TCP/TLS clients in Wifi STA mode.
Support for UDP/TCP servers is not supported, currently.

https://aithinker-combo-guide.readthedocs.io/en/latest/docs/instruction/index.html
https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-set/index.html
https://aithinker-combo-guide.readthedocs.io/en/latest/docs/command-examples/index.html

* switch to comboat_fw build tag for examples/net's that work with comboat driver
  • Loading branch information
scottfeldman authored Feb 21, 2025
1 parent 27a7d50 commit 06dd60f
Show file tree
Hide file tree
Showing 18 changed files with 840 additions and 14 deletions.
711 changes: 711 additions & 0 deletions comboat/comboat.go

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions comboat/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package comboat

import (
"bytes"
"strconv"
)

var errStrings = map[int]string{

// System framework related error codes

0: "success",
1: "The command is not supported (the combo framework contains the command but the current platform has not transplanted or adapted to support it)",
2: "The command parameters contain unsupported operations (the current platform only supports some operations for this command)",
3: "The instruction format is incorrect (this refers to the wrong number of parameters, for example, two parameters are required, but only one parameter is entered)",
4: "Parameter error (the content of the parameter is wrong, for example, a number between 0 and 9 is required, but 10 or xyz is passed in, which is a parameter error)",
5: "Parameter length error (command length exceeds the maximum supported length)",
31: "The current command has not ended and needs to report the status asynchronously. This value is used by the state machine to determine the use of the command and no message is returned.",
32: "Unknown error (or unhandled error type)",

// Common error codes

33: "malloc error",
34: "Failed to read buf",
35: "Failed to write buf",
36: "Configuration error (configuration error loaded from memory, for example, we set port -1 for OTA upgrade, and check port error when executing AT+OTA, then configuration error will be reported)",
37: "Failed to create task",
38: "Flash read and write failure",
39: "Serial port configuration error, unsupported baud rate",
40: "Serial port configuration error, unsupported data bits",
41: "Serial port configuration error, unsupported stop bit",
42: "Serial port configuration error, unsupported parity bit",
43: "Serial port configuration error, unsupported flow control",
44: "Serial port configuration failed",
45: "Wrong username/password",
46: "Low power mode error or unsupported low power mode",
47: "Uninitialized configuration data error (including io mapping data)",
63: "General error code (without other information)",

// Wi-Fi related error codes

64: "Wi-Fi not initialized or initialization failed",
65: "Wi-Fi mode error (unable to connect to Wi-Fi in single AP mode)",
66: "Wi-Fi connection failed",
67: "Wi-Fi connection successful, error in obtaining IP (DHCP)",
68: "Failed to obtain encryption method",
69: "The specified AP was not found.",
70: "Wi-Fi scan start failed",
71: "Wi-Fi scan timeout",
72: "Failed to enable AP hotspot",
73: "Failed to obtain the Wi-Fi information of the router or the AP information that you enabled yourself",
74: "The network card (STA/AP) is not running",
75: "Wi-Fi country code error (unsupported Wi-Fi country code)",
76: "The current network configuration mode is wrong.",
95: "Wi-Fi connection unknown error",

// Socket related error codes

96: "Failed to create socket",
97: "Socket connection failed",
98: "DNS Failure",
99: "The socket status is wrong (for example, TCP is not connected yet)",
100: "Socket type error",
101: "Socket send failed",
102: "Socket receive failed",
103: "Socket monitoring thread creation failed",
104: "Socket bind error",
105: "The current connection cannot be transparently linked (wrong socket type or number)",
106: "PING test failed (all packets lost)",
107: "Wi-Fi country code error (unsupported Wi-Fi country code)",
108: "SSL Config Error",
109: "SSL verification error (usually caused by unsupported SSL encryption type or certificate error)",
127: "Unknown socket error",
}

func getErrStr(errLine []byte) (errStr string) {
errStr = "Can't parse ERROR response"
tokens := bytes.Split(errLine, []byte(":"))
if len(tokens) > 1 {
errCode, err := strconv.Atoi(string(tokens[1]))
if err == nil {
errStr = errStrings[errCode]
}
}
return
}
2 changes: 1 addition & 1 deletion examples/net/http-get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// examples/net/webclient (for HTTP)
// examples/net/tlsclient (for HTTPS)

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

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/http-head/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// examples/net/webclient (for HTTP)
// examples/net/tlsclient (for HTTPS)

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

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/http-post/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// examples/net/webclient (for HTTP)
// examples/net/tlsclient (for HTTPS)

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

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/http-postform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// examples/net/webclient (for HTTP)
// examples/net/tlsclient (for HTTPS)

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

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/mqttclient/natiu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Note: It may be necessary to increase the stack size when using
// paho.mqtt.golang. Use the -stack-size=4KB command line option.

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

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/mqttclient/paho/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Note: It may be necessary to increase the stack size when using
// paho.mqtt.golang. Use the -stack-size=4KB command line option.

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

package main

Expand Down
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
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/snake/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build ninafw || wioterminal
//go:build ninafw || wioterminal || comboat_fw

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/snake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// func. This forces segments to connect and run concurrently, which is a good
// test of the underlying driver's ability to handle concurrent connections.

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

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
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw

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 || pico
//go:build ninafw || wioterminal || challenger_rp2040 || comboat_fw

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
//go:build ninafw || wioterminal || comboat_fw

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
//go:build ninafw || wioterminal || comboat_fw

package main

Expand Down
2 changes: 1 addition & 1 deletion examples/net/websocket/dial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Note: It may be necessary to increase the stack size when using
// "golang.org/x/net/websocket". Use the -stack-size=4KB command line option.

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

package main

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

package probe

import (
"machine"

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

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

cfg := comboat.Config{
BaudRate: 115200,
Uart: machine.UART1,
Tx: machine.UART1_TX_PIN,
Rx: machine.UART1_RX_PIN,
}

combo := comboat.NewDevice(&cfg)
netdev.UseNetdev(combo)

return combo, combo
}
3 changes: 3 additions & 0 deletions smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb
tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
# 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/

0 comments on commit 06dd60f

Please sign in to comment.