Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
earlephilhower opened this issue Nov 10, 2023 Discussed in #1795 · 18 comments
Closed

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

earlephilhower opened this issue Nov 10, 2023 Discussed in #1795 · 18 comments
Labels
enhancement New feature or request

Comments

@earlephilhower
Copy link
Owner

Discussed in #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 earlephilhower added the enhancement New feature or request label Nov 10, 2023
@earlephilhower
Copy link
Owner Author

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
Copy link
Contributor

JAndrassy commented Nov 12, 2023

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
Copy link
Contributor

PontusO commented Nov 20, 2023

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

@PontusO
Copy link
Contributor

PontusO commented Nov 20, 2023

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
Copy link
Contributor

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
Copy link
Owner Author

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
Copy link
Contributor

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
Copy link
Contributor

JAndrassy commented Jan 14, 2024

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:

  • the fw has a problem with esp32 pins > 32 and the Nano has pin 33 as ACK.
  • the Nano connects one io of RP2040 to two esp32 pins, SPI and UART. so the SPI CS pin is wired to esp32 UART TX pin too. and the esp32 with the hosted firmware has a pullup on UART TX even the firmware doesn't use UART (I guess the IDF sets the pull-up). The RP2040 was unable to pull down two pulled up io of the esp32.

@JAndrassy
Copy link
Contributor

@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
Copy link
Owner Author

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
Copy link
Contributor

@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
Copy link
Owner Author

@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
Copy link
Contributor

PontusO commented Feb 11, 2024

@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.

@earlephilhower
Copy link
Owner Author

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

@JAndrassy
Copy link
Contributor

you can close it.

@JAndrassy
Copy link
Contributor

JAndrassy commented Mar 24, 2024

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

@JAndrassy
Copy link
Contributor

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

schkovich pushed a commit to schkovich/arduino-pico that referenced this issue May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants