earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
1.99k stars 412 forks source link

Feature Request: lwIP_esp32 with Espressif "esp_hosted" firmware for esp32 #1806

Closed earlephilhower closed 7 months ago

earlephilhower commented 10 months ago

Discussed in https://github.com/earlephilhower/arduino-pico/discussions/1795

Originally posted by **JAndrassy** October 29, 2023 Espressif has for esp32 a fw which makes it a MAC level WiFi adapter. The host MCU then has the TCP/IP stack and a network interface driver for the esp32. This could be used to allow esp32 as WiFi network interface for Pico LwIP. The repository https://github.com/espressif/esp-hosted/tree/master/esp_hosted_fg Arduino uses this for their new Portenta C33 board which has STM32 MCU with esp32-C3 for WiFi with LwIP. Here is the driver https://github.com/arduino/ArduinoCore-renesas/tree/main/libraries/ESPhost/src There are multiple RP2040 boards with esp32 on SPI for WiFi. The Challenger RP2040 WiFi/BLE MkII board, the Arduino Nano Connect cc: @PontusO
earlephilhower commented 10 months ago

Thanks for the info @JAndrassy! I don't have any ESP32+RP2040 boards handy, but I think I've got some OG ESP32s floating around in the junk drawer...

Looks like that firmware also supports a standard Bluetooth HCI implementation. So BTStack might also be persuaded to play nicely with it.

JAndrassy commented 10 months ago

I tested it with Uno R4 with esp32 on SPI. but Uno R4 is in the same platform as the Portenta C33 for which the ESPHosted library was written. It uses HAL SPI. I did a rewrite with Arduino SPI library but for now that is slow or what. It misses the events from esp32. but the ESPHosted library is ugly so maybe not a good starting point. maybe the host example code in the esp-hosted repository is better to start with. I had to rebuild the firmware because the prebuild version used the other SPI (than documented). But it was easy on Linux. The ESP-IDF build tools are very good now.

Arduino has some simple patches to firmware source code to use it with ArduinoBLE library.

PontusO commented 10 months ago

I can send out a couple of boards to anyone wanting to try this out @earlephilhower , @JAndrassy ?

PontusO commented 10 months ago

I noticed the design uses an additional (data ready) pin which differs from the esp-at SPI implementation which our boards are based on. But I guess repurposing the boot select pin would be doable enabling full functionality.

JAndrassy commented 8 months ago

I made some progress. I extracted the ESPHost library from the Renesas Core into a separate repository and I modified it to run on any ARM Arduino. The library has a test in examples. The test does the WiFi related functions like connecting to AP, scan and similar. The test works with this core.

I integrated ESPHost into Arduino Mbed Core networking in form of ESPHosted-EMAC library. It is just a rough draft, but it works. The ESPHostEMAC.cpp shows how to integrate it with LwIP.

earlephilhower commented 8 months ago

That's awesome work! I can tell you've been very busy over the holidays! Will you be leaving those repos up? I've got home renovations taking up most of my "free" time and won't be able to give it a deep dive for a couple weeks.

JAndrassy commented 8 months ago

Will you be leaving those repos up?

of course

maybe I even start drafting the integration here. but first I want to fix the WiFi library in the Mbed Core, which I finally can test.

JAndrassy commented 8 months ago

this weekend I was able to make the esp-hosted firmware with the ESPHost library basic example on my new "Arduino Nano RP2040 Connect". it was a challenge with two major problems:

JAndrassy commented 7 months ago

@PontusO Hello. I want to build the esp-hosted firmware for the Challenger boards so you can test the lwIP_ESPHost library. Please confirm that for both the C3 and C6 the pins are: MISO IO2 CLK IO6 MOSI IO7 SS IO10 HS IO3 and IO9 is connected too

earlephilhower commented 7 months ago

I'm having some issues with the esp-hosted-fg (built using their defaults) on an ESP32C6 board and the LWIP driver here, would appreciate any suggestions on how to debug.

I've double checked the wiring between the RPIPico board and the ESP32-C6 and have everything agreeing AIUI, but other than an initial SPI transaction being dumped I see no other SPI transactions while enabling full core debug.

The ESP32C6 dumps the following config info to serial:

I (471) NETWORK_ADAPTER: *********************************************************************
I (481) NETWORK_ADAPTER:                 ESP-Hosted-FG Firmware version :: 0.0.5                        
I (491) NETWORK_ADAPTER:                 Transport used :: SPI only                      
I (501) NETWORK_ADAPTER: *********************************************************************
I (511) NETWORK_ADAPTER: Supported features are:
I (521) NETWORK_ADAPTER: - WLAN over SPI
I (521) ESP_BT: - BT/BLE
I (521) ESP_BT:    - HCI Over SPI
I (531) ESP_BT:    - BLE only
I (531) NETWORK_ADAPTER: capabilities: 0xe8
I (541) phy_init: phy_version 202,b4b3263,May 17 2023,20:14:14
controller lib commit: [5cacafa]
I (591) NETWORK_ADAPTER: ESP Bluetooth MAC addr: 40:4c:ca:4e:de:1a
I (591) SPI_DRIVER: Using SPI interface
I (591) gpio: GPIO[3]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (601) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (611) SPI_DRIVER: SPI Ctrl:1 mode: 2, InitFreq: 10MHz, ReqFreq: 26MHz
GPIOs: MOSI: 7, MISO: 2, CS: 10, CLK: 6 HS: 3 DR: 4

I (621) SPI_DRIVER: Hosted SPI queue size: Tx:20 Rx:20
I (631) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (641) gpio: GPIO[10]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (651) pp: pp rom version: 5b8dcfa
I (651) net80211: net80211 rom version: 5b8dcfa

My boards.local.txt is:

rpipico.build.extra_flags=-DESPHOST_RESET=D5 -DESPHOST_HANDSHAKE=D7 -DESPHOST_DATA_READY=D6 -DESPHOST_CS=D1 -DESPHOSTSPI=SPI

I've wired as follows:

ESP7 (MOSI) <-> GP3
ESP2 (MISO) <-> GP0
ESP10 (CS)  <-> GP1
ESP6 (CLK)  <-> GP2
ESP3 (HS)   <-> GP7
ESP4 (DR)   <-> GP6
ESP-RST     <-> GP5
ESP-GND     <-> RPIPICO-GND

And configured SPI to use the appropriate pins at the beginning of setup() before any code is executed

  SPI.setRX(0);
  SPI.setCS(1);
  SPI.setSCK(2);
  SPI.setTX(3);

I've started going down the driver code in GDB but it's real slow going. I was wondering if you have any suggestions on where to start, or if there are certain version dependencies or something higher level. Everything is the git head version (your library and the ESP FW)

JAndrassy commented 7 months ago

@earlephilhower your initial log of the fw should end with something like "leaving main()" (the handling tasks started). you build the fw from master branch? the library only works with 0.0.5 tag version and now I see C6 is unknown there

earlephilhower commented 7 months ago

@JAndrassy awesome, thanks for the info!

I had to move to a ESP32-S3 to get that tag release/fg-v0.0.5 to build, and somehow I ended up with a -Werror in the Makefile which meant I needed to fix a couple places in the release where they're checking that a string is not empty by if (object.str) strcpy(dest, obj, str); instead of if (object.str[0]) strcpy(dest, obj, str);`

Those minor diffs, rewiring, and voila! Very nice work.

10:39:06.552 -> Beginning scan at 165024
10:39:08.636 -> Found 22 networks
10:39:08.636 -> 
10:39:08.636 ->                             SSID   ENC     BSSID         CH RSSI
10:39:08.636 ->                         NOBABIES  WPA2 38:2C:4A:90:FA:80  9  -24
10:39:08.636 ->                         NOBABIES  WPA2 AC:84:C6:6C:EF:F3  1  -49
10:39:08.636 ->                         NOBABIES  WPA2 50:D4:F7:FE:A3:4D 11  -69
10:39:08.636 ->                    The Muchachos  WPA2 C4:41:1E:2A:D4:63  1  -80
10:39:08.636 ->                    The Muchachos  WPA2 C4:41:1E:2A:D4:40  7  -80
10:39:08.636 ->                                   WPA2 CA:41:1E:2A:D4:63  1  -81
10:39:08.636 ->                                   WPA2 CA:41:1E:2A:D4:40  7  -81
10:39:08.636 ->                        JamesWifi  WPA2 58:CB:52:D2:6B:01  6  -84
10:39:08.636 ->                           ORBI60  WPA2 10:0C:6B:48:72:B5  4  -85
10:39:08.636 ->                     ORBI60-Guest  WPA2 1A:0C:6B:48:72:B5  4  -86
10:39:08.636 ->                                   WPA2 16:0C:6B:48:72:B5  4  -86
10:39:08.636 ->                        JamesWifi  WPA2 58:CB:52:D2:76:0C  6  -86
10:39:08.636 ->                                   WPA2 8C:85:80:E0:33:F5 11  -86
10:39:08.636 ->                                   WPA2 CA:41:1E:2A:D4:8B 11  -86
10:39:08.636 ->                                   WPA2 76:CD:D6:A6:EC:D4  9  -87
10:39:08.636 ->                                   WPA2 10:0C:6B:50:2D:EB  4  -88
10:39:08.636 ->                                   WPA2 42:84:6A:DD:7C:56  7  -88
10:39:08.636 ->                           ORBI60  WPA2 16:0C:6B:50:2D:EB  4  -89
10:39:08.636 ->                           ORBI31  WPA2 72:CD:D6:A6:EC:D4  9  -89
10:39:08.636 ->                                   WPA2 10:0C:6B:E7:15:73 11  -89
10:39:08.636 ->                        NETGEAR36  WPA2 CC:40:D0:61:B3:89 11  -90
10:39:08.636 ->                        JamesWifi  WPA2 58:CB:52:D2:6C:4B  6  -91
10:39:08.636 -> 
10:39:08.636 -> --- Sleeping ---
PontusO commented 7 months ago

@PontusO Hello. I want to build the esp-hosted firmware for the Challenger boards so you can test the lwIP_ESPHost library. Please confirm that for both the C3 and C6 the pins are: MISO IO2 CLK IO6 MOSI IO7 SS IO10 HS IO3 and IO9 is connected too

@JAndrassy For the C3 board that is correct. The C6 board is connected a bit differently. MISO IO3, MOSI IO7, CLK IO6, SS IO12, HS IO2 and IO9 is also connected.

JAndrassy commented 7 months ago

@PontusO https://github.com/JAndrassy/ESPHost/tree/main/extras/firmware/Challenger2040WiFiBLE https://github.com/JAndrassy/ESPHost/blob/main/README.md#configuration

earlephilhower commented 7 months ago

@JAndrassy any reason to keep this open? You seem to have completed it. 😄

JAndrassy commented 7 months ago

you can close it.

JAndrassy commented 6 months ago

@PontusO the esp-hosted fw configuration for C3 has 30 MHz SPI so use -DESPHOSTSPI_MHZ=30

JAndrassy commented 5 months ago

@PontusO sorry. the upload command in the README had a wrong address for the bootloader. on C3 the bootloader address is 0x0