Zephyr: WiFi support for ESP32

Created on 16 Jun 2017  Â·  34Comments  Â·  Source: zephyrproject-rtos/zephyr

_Reported by Leandro Pereira:_

WiFi support requires binary blobs that currently assumes it's running on FreeRTOS. Figure out a way to use them on Zephyr.

(Imported from Jira ZEP-2288)

Feature Request ESP32

Most helpful comment

Update:

Feature branch that has functional networking (WiFi) on ESP32 can be found here.

Technical details:

  • This is still based on 2nd stage bootloader from ESP-IDF which does required flash cache setup for XIP enabled application
  • This feature branch has appropriate west manifest file to pick up correct base ESP-IDF repository (based on v4.2 version)
  • Toolchain should be based on revision xtensa-esp32-elf-gcc (crosstool-NG esp-2020r2) 8.2.0
  • All networking application should be functional, just that prj.conf should be added with credentials for WiFi network using CONFIG_WIFI_SSID="myssid" and CONFIG_WIFI_PASSWORD="mypassword"

Official PR (from Espressif) will still take some time but interim please feel free to give this a try and report any issues or feedback.

CC @ExtremeGTX @Skallwar @GautierAtWork

All 34 comments

for anybody who's interested, here is a application that can compile the ESP wifi lib against zephyr, but still quite a long way to go getting wifi running

Adding reference to the #10539

@galak #10539 is unrelated to @locomuco's application -- ESP8266 in that PR is being used as an external chip, running its stock firmware, rather than running Zephyr and driving the radio itself.

Hi, it's been a while... are there any updates on this?

Hi, is there any update on the topic or further information how the status is?

Hello, does zephyr support the wifi on esp32? The sample/net/wifi is compilable for esp32 but after fleshing there is no interaction.

Hello every one,

I tried to build the WiFi example, but I got the following error and note log:

FAILED: zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_esp32.c.obj 
ccache /home/user/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc -DBUILD_VERSION=v2.2.0-rc1-255-gb01cd4c7bbc3 -DKERNEL -D_FORTIFY_SOURCE=2 -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I/home/user/workspace/repositories/zephyr/include -Izephyr/include/generated -I/home/user/workspace/repositories/zephyr/soc/xtensa/esp32 -I/home/user/workspace/repositories/zephyr/soc/xtensa/esp32/include -I/home/user/workspace/repositories/zephyr/ext/lib/fnmatch/. -I/home/user/workspace/repositories/zephyr/modules/hal/esp-idf/zephyr/../components/esp32/include -I/home/user/workspace/repositories/zephyr/modules/hal/esp-idf/zephyr/../components/soc/esp32/include -I/home/user/workspace/repositories/zephyr/modules/hal/xtensa/include -I/home/user/workspace/repositories/zephyr/modules/hal/xtensa/zephyr/soc/esp32 -isystem /home/user/workspace/repositories/zephyr/lib/libc/minimal/include -isystem /home/user/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/include -isystem /home/user/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.2.0/include-fixed -Os -imacros/home/user/workspace/projects/examples/esp32/zephyr/wifi/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -imacros/home/user/workspace/repositories/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/user/workspace/projects/examples/esp32/zephyr/wifi=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/user/workspace/repositories/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/user/workspace/repositories/zephyr=WEST_TOPDIR -ffunction-sections -fdata-sections -mlongcalls -std=c99 -nostdinc -MD -MT zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_esp32.c.obj -MF zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_esp32.c.obj.d -o zephyr/drivers/serial/CMakeFiles/drivers__serial.dir/uart_esp32.c.obj   -c /home/user/workspace/repositories/zephyr/drivers/serial/uart_esp32.c
/home/user/workspace/repositories/zephyr/drivers/serial/uart_esp32.c:458:2: error: request for member 'irq_config_func' in something not a structure or union
  .irq_config_func = uart_esp32_irq_config_func_##idx,
  ^
/home/user/workspace/repositories/zephyr/drivers/serial/uart_esp32.c:486:3: note: in expansion of macro 'ESP32_UART_IRQ_HANDLER_FUNC'
   ESP32_UART_IRQ_HANDLER_FUNC(idx)          \
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/workspace/repositories/zephyr/drivers/serial/uart_esp32.c:541:1: note: in expansion of macro 'ESP32_UART_INIT'
 ESP32_UART_INIT(0);
 ^~~~~~~~~~~~~~~
[113/166] Building C object zephyr/sub...es/subsys__net__ip.dir/net_shell.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/user/workspace/projects/examples/esp32/zephyr/wifi/build

How to proceed?

Hopefully this help in some way.

This is a bug (just a missing comma in line 485 of drivers/serial/uart_esp32.c, line 485 (end of line, missing a comma). I submitted a PR yesterday about it.

Now I am facing the same problem as @Deliver88.

It can be built, thanks to @figual, but when I try to flash the esptool.py says it:
A fatal error occurred: Invalid segment count 17 (max 16). Usually this indicates a linker script problem.

So I tried to force to accept it by increasing the number of segments in the line 1603 in esptool.py from 16 to 17.

After that the board can be flash. But when I open the serial port I see it doesn't boot properly.

The log from serial:

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffb0000,len:180
load:0x3ffb00b4,len:92
load:0x3ffb0110,len:56
load:0x3ffb0148,len:96
load:0x3ffb01a8,len:20
ho 0 tail 12 room 4
load:0x3ffb01bc,len:40
ho 0 tail 12 room 4                                                            
load:0x3ffb01e4,len:64                                                         
load:0x3ffb0240,len:96                                                         
ho 0 tail 12 room 4                                                            
load:0x3ffb02a0,len:304                                                        
load:0x3ffb03d0,len:14380                                                      
load:0x40080000,len:1024                                                       
load:0x40080400,len:256                                                        
load:0x40080500,len:180                                                        
load:0x400805b4,len:184                                                        
load:0x4008066c,len:16                                                         
ho 0 tail 12 room 4                                                            
load:0x4008067c,len:72                                                         
ho 0 tail 12 room 4                                                            
load:0x400806c4,len:66008                                                      
1162 mmu set 00010000, pos 00010000                                            
entry 0x40081140

I could workaround to flash the code by disabling the configuration option CONFIG_NET_LOG from wifi/prj.conf.

The shell works fine, and I really enjoyed using it.

But whenever it tries to use some drive, such as Wi-Fi and I²C, the board get locked.

Adding reference to the #21492

Adding reference to the #21492

HI Jen,
I think we are looking at two different things, the work being done under #21492 etc is a UART driven AT modem driver where as this is relating to using the esp as an MCU rather than a slave modem.

Billy..

Hi. I'm interested on working on this, but I have no idea where to start from. Have you some resources or previous work to help start working on it ?

@Skallwar Since the ESP32 wifi driver is implemented in RIOT, the code there might be a good starting point: https://github.com/RIOT-OS/RIOT/pull/9426/files

I've worked a bit on this and I have a dummy Wifi driver. Right now, ESP-IDF Wifi code is not really reusable, but on the v4.1-beta there is a file with set of stub functions that could be adapted to Zephyr.
I don't know the ETA for this change on a stable release however. When this change will be stable how do I proceed ? I create a pull request to the zephyr esp-idf repo to update it ?

The main reason WiFi isn't supported in Zephyr on the ESP32 is not just the
driver. Zephyr runs entirely on the IRAM, loaded by the first stage
bootloader in ROM. If the driver+libs were to be linked, it wouldn't fit.
You'd need to enable the Flash Cache, which will require a second stage
bootloader (because the code will be overwritten when it's done). There was
some code to do this back when I was working on it, and some people
actually made it work, but I don't know what's the status of it. There
might be some code in some branch in my fork.

On Tue, Jun 30, 2020, 03:32 Esteban Blanc notifications@github.com wrote:

I've worked a bit on this and I have a dummy Wifi driver. Right now,
ESP-IDF Wifi code is not really reusable, but on the v4.1-beta
https://github.com/espressif/esp-idf/releases/tag/v4.1-beta2 there is a
file
https://github.com/espressif/esp-idf/blob/c5cb44d8135a5ec6678259e30468632bc2442288/components/esp_wifi/esp32/esp_adapter.c
with set of stub functions that could be adapted to Zephyr.
I don't know the ETA for this change on a stable release however. When
this change will be stable how do I proceed ? I create a pull request to
the zephyr esp-idf repo https://github.com/zephyrproject-rtos/esp-idf
to update it ?

—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/zephyrproject-rtos/zephyr/issues/3723#issuecomment-651709172,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAADVGMYSZQ4HUNNRLWVWDDRZG5J3ANCNFSM4GAZ4YIA
.

There was some code to do this back when I was working on it, and some people actually made it work, but I don't know what's the status of it

Are we talking of this PR ?

That seems to be it, yeah.

Once this is working -- you probably want to add ESP32 support in mcuboot,
too, to act as the second stage bootloader -- it should be trivial to hook
up the ESP32 WiFi blob with Zephyr's network stack, IIRC.

With some work it should be possible to deconstruct the static library and
write shims to use the crypto API (and select which crypto implementation
to use).

On Tue, Jun 30, 2020, 08:21 Esteban Blanc notifications@github.com wrote:

There was some code to do this back when I was working on it, and some
people actually made it work, but I don't know what's the status of it

Are we talking of this PR
https://github.com/zephyrproject-rtos/zephyr/pull/8783 ?

—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/zephyrproject-rtos/zephyr/issues/3723#issuecomment-651863312,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAADVGNBYZWFTSOWVGAIW3TRZH7H5ANCNFSM4GAZ4YIA
.

That seems to be it, yeah.

Any idea why this has never been merged ?

Once this is working -- you probably want to add ESP32 support in mcuboot, too, to act as the second stage bootloader

The esp-idf bootloader is not sufficient ?

it should be trivial to hook up the ESP32 WiFi blob with Zephyr's network stack, IIRC.

Is it really a blob ? From what I see here it looks like no, but you maybe referring to something else ?

The ESP-IDF bootloader could be used as a starting point, yes, but I think that the ideal situation for Zephyr would be using mcuboot so that the Zephyr tooling could be used.

You have to link with the blobs provided in https://github.com/espressif/esp32-wifi-lib (the "lib" directory is a git submodule pointing to this repo).

@Skallwar

https://github.com/locomuco/zephyr-esp32

this was the follow up to the previously mentioned PR, it was able to enable flash cache and link in the Wifi Blob, it's outdated, but might give good hints in the single commits

The ESP-IDF bootloader could be used as a starting point, yes

I can not boot the hello world example with it, the boot is stuck at boot: Disabling RNG early entropy source... after loading the app. Beside on larger project, the app contains too much segments (here, segment = elf section) and the app will not be loaded.

I will maybe try to work on mcuboot

Update:

Feature branch that has functional networking (WiFi) on ESP32 can be found here.

Technical details:

  • This is still based on 2nd stage bootloader from ESP-IDF which does required flash cache setup for XIP enabled application
  • This feature branch has appropriate west manifest file to pick up correct base ESP-IDF repository (based on v4.2 version)
  • Toolchain should be based on revision xtensa-esp32-elf-gcc (crosstool-NG esp-2020r2) 8.2.0
  • All networking application should be functional, just that prj.conf should be added with credentials for WiFi network using CONFIG_WIFI_SSID="myssid" and CONFIG_WIFI_PASSWORD="mypassword"

Official PR (from Espressif) will still take some time but interim please feel free to give this a try and report any issues or feedback.

CC @ExtremeGTX @Skallwar @GautierAtWork

Great job, Mahavir!

On Thu, Sep 24, 2020, 02:38 Mahavir Jain notifications@github.com wrote:

Update:

Feature branch that has functional networking (WiFi) on ESP32 can be found
here
https://github.com/mahavirj/zephyr/tree/feature/esp32_networking_support_on_zephyr_v2.4.0-rc1
.

Technical details:

  • This is still based on 2nd stage bootloader from ESP-IDF which does
    required flash cache setup for XIP enabled application
  • This feature branch has appropriate west manifest file to pick up
    correct base ESP-IDF repository (based on v4.2 version)
  • Toolchain should be based on revision xtensa-esp32-elf-gcc
    (crosstool-NG esp-2020r2) 8.2.0
  • All networking application should be functional, just that prj.conf
    should be added with credentials for WiFi network using
    CONFIG_WIFI_SSID="myssid" and CONFIG_WIFI_PASSWORD="mypassword"

Official PR (from Espressif) will still take some time but interim please
feel free to give this a try and report any issues or feedback.

CC @ExtremeGTX https://github.com/ExtremeGTX @Skallwar
https://github.com/Skallwar @GautierAtWork
https://github.com/GautierAtWork

—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/zephyrproject-rtos/zephyr/issues/3723#issuecomment-698234652,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAADVGIOLMICXZXAW6FR7BLSHMHQFANCNFSM4GAZ4YIA
.

@mahavirj I tried to test your branch but failed, because the path to the source files in https://github.com/mahavirj/zephyr/blob/feature/esp32_networking_support_on_zephyr_v2.4.0-rc1/drivers/wifi/esp32/CMakeLists.txt#L69 did not match the correct paths in my esp-idf module (I used west and one manual git submodule update --init in esp-idf module). Maybe i did something wrong.
Could you describe the steps necessary to test your branch (especially how to get the correct esp-idf and what variables to set)?

@chrta

Could you describe the steps necessary to test your branch (especially how to get the correct esp-idf and what variables to set)?

Please find instructions here. Let me know if you face any issues.

Please find instructions here. Let me know if you face any issues.

Great, thank you. Now i could proceed a little bit further. My previous error was that i used the wrong hal (the old one not named espressif).
Now i am facing the next issue with the python modules that are required (when i execute "west build"). I am using Ubuntu 20.04 and the build step fails because the necessary python modules are not installed. I try to install them from the requirements.txt file from the hal, but that did not work either.
Can you add instructions how to install the required python modules, or what venv to use when executing the "west build" step?

Maybe you can enable the issues in your github fork and we can continue the discussion there? I do not want to spam this issue too much.

Maybe you can enable the issues in your github fork and we can continue the discussion there?

Done. I have also reached out you on slack channel, in case that is faster.

Just for reference: It works now, after fixing some python issues on my pc and applying https://github.com/espressif/esp-idf/commit/96cfdf3184f5fac4c744fa9b8bc76a3e69fe2b65 to esp-idf. Thank you @mahavirj for your support.

@mahavirj i could confirm that WiFi on ESP32 works with your branch. Thx.

Hi @mahavirj
I was trying out the WiFi support for ESP32 and encountered the following issue: each time I build an app and try to flash it I get an error pointing that no bootloader.bin is present in the build (also no partitions file is generated as well). Tried the CONFIG_BOOTLOADER_ESP_IDF=y option as well, still no bootloader was built.
Opened an issue on your repo as well about it.

@vtothsvk I have this issue also on Windows 10, but you can use Linux for now if you want to try the wifi support.
I will try to find a fix for this issue.

@ExtremeGTX FYI, fix for this is available here. We will ensure that this is part of PR for WiFi support on ESP32.

@mahavirj thanks for the updates! Is there an official PR yet for us to follow?

Was this page helpful?
0 / 5 - 0 ratings