Skip to content
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

ESP32 support #1344

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

NonPIayerCharacter
Copy link
Contributor

@NonPIayerCharacter NonPIayerCharacter commented Sep 9, 2024

Working: WiFi (AP, STA, scanning), powersave (2 modes + freq scaling), GPIO, LFS, internal temperature, PWM (LEDC), OTA, ADC, WDT, deep sleep (no pindeepsleep).
UART is problematic. Somewhy i2c is not working for all pins, sys_evt task crashes on reboot.
Manual build:
cd sdk/esp-idf

./install.sh

. ./export.sh

cd ../..

make OpenESP32

or others (OpenESP32C2, OpenESP32C3, OpenESP32C6, OpenESP32S2, OpenESP32S3)

@MaxineMuster
Copy link
Contributor

MaxineMuster commented Sep 9, 2024

Thanks for this great idea!

I hope it's o.k. to give some longer feedback?!?

First ended up with some error message

[...snipp...]
Submodule path 'sdk/OpenXR809': checked out '3e8cd2f98075aa89bb1fbafd7871a8bb61360612'
Submodule path 'sdk/esp-idf': checked out 'cc3203dc4f087ab41b434afff1ed7520c6d90993'
Submodule 'components/bootloader/subproject/components/micro-ecc/micro-ecc' (https://github.com/kmackay/micro-ecc.git) registered for path 'sdk/esp-idf/components/bootloader/subproject/components/micro-ecc/micro-ecc'
Submodule 'components/bt/controller/lib_esp32' (https://github.com/espressif/esp32-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32'
Submodule 'components/bt/controller/lib_esp32c2/esp32c2-bt-lib' (https://github.com/espressif/esp32c2-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32c2/esp32c2-bt-lib'
Submodule 'components/bt/controller/lib_esp32c3_family' (https://github.com/espressif/esp32c3-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32c3_family'
Submodule 'components/bt/controller/lib_esp32c5/esp32c5-bt-lib' (https://github.com/espressif/esp32c5-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32c5/esp32c5-bt-lib'
Submodule 'components/bt/controller/lib_esp32c6/esp32c6-bt-lib' (https://github.com/espressif/esp32c6-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32c6/esp32c6-bt-lib'
Submodule 'components/bt/controller/lib_esp32h2/esp32h2-bt-lib' (https://github.com/espressif/esp32h2-bt-lib.git) registered for path 'sdk/esp-idf/components/bt/controller/lib_esp32h2/esp32h2-bt-lib'
Submodule 'components/bt/esp_ble_mesh/lib/lib' (https://github.com/espressif/esp-ble-mesh-lib.git) registered for path 'sdk/esp-idf/components/bt/esp_ble_mesh/lib/lib'
Submodule 'components/bt/host/nimble/nimble' (https://github.com/espressif/esp-nimble.git) registered for path 'sdk/esp-idf/components/bt/host/nimble/nimble'
Submodule 'components/cmock/CMock' (https://github.com/ThrowTheSwitch/CMock.git) registered for path 'sdk/esp-idf/components/cmock/CMock'
Submodule 'components/esp_coex/lib' (https://github.com/espressif/esp-coex-lib.git) registered for path 'sdk/esp-idf/components/esp_coex/lib'
Submodule 'components/esp_phy/lib' (https://github.com/espressif/esp-phy-lib.git) registered for path 'sdk/esp-idf/components/esp_phy/lib'
Submodule 'components/esp_wifi/lib' (https://github.com/espressif/esp32-wifi-lib.git) registered for path 'sdk/esp-idf/components/esp_wifi/lib'
Submodule 'components/heap/tlsf' (https://github.com/espressif/tlsf.git) registered for path 'sdk/esp-idf/components/heap/tlsf'
Submodule 'components/json/cJSON' (https://github.com/DaveGamble/cJSON.git) registered for path 'sdk/esp-idf/components/json/cJSON'
Submodule 'components/lwip/lwip' (https://github.com/espressif/esp-lwip.git) registered for path 'sdk/esp-idf/components/lwip/lwip'
Submodule 'components/mbedtls/mbedtls' (https://github.com/espressif/mbedtls.git) registered for path 'sdk/esp-idf/components/mbedtls/mbedtls'
Submodule 'components/mqtt/esp-mqtt' (https://github.com/espressif/esp-mqtt.git) registered for path 'sdk/esp-idf/components/mqtt/esp-mqtt'
Submodule 'components/openthread/lib' (https://github.com/espressif/esp-thread-lib.git) registered for path 'sdk/esp-idf/components/openthread/lib'
Submodule 'components/openthread/openthread' (https://github.com/espressif/openthread.git) registered for path 'sdk/esp-idf/components/openthread/openthread'
Submodule 'components/protobuf-c/protobuf-c' (https://github.com/protobuf-c/protobuf-c.git) registered for path 'sdk/esp-idf/components/protobuf-c/protobuf-c'
Submodule 'components/spiffs/spiffs' (https://github.com/pellepl/spiffs.git) registered for path 'sdk/esp-idf/components/spiffs/spiffs'
Submodule 'components/unity/unity' (https://github.com/ThrowTheSwitch/Unity.git) registered for path 'sdk/esp-idf/components/unity/unity'
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bootloader/subproject/components/micro-ecc/micro-ecc'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32c2/esp32c2-bt-lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32c3_family'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32c5/esp32c5-bt-lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32c6/esp32c6-bt-lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/controller/lib_esp32h2/esp32h2-bt-lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/esp_ble_mesh/lib/lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/bt/host/nimble/nimble'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/cmock/CMock'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/esp_coex/lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/esp_phy/lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/esp_wifi/lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/heap/tlsf'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/json/cJSON'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/lwip/lwip'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/mbedtls/mbedtls'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/mqtt/esp-mqtt'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/openthread/lib'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/openthread/openthread'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/protobuf-c/protobuf-c'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/spiffs/spiffs'...
Cloning into '/OpenBK7231T_App/sdk/esp-idf/components/unity/unity'...
Submodule path 'sdk/esp-idf/components/bootloader/subproject/components/micro-ecc/micro-ecc': checked out 'fe8ed90abc356347378eb25e2586e90df7be015a'
Submodule path 'sdk/esp-idf/components/bt/controller/lib_esp32': checked out '8112ca2c575c6feb32d755623f097f1b66759490'
fatal: Needed a single revision
Unable to find current origin/master revision in submodule path 'components/bt/controller/lib_esp32c2/esp32c2-bt-lib'
Submodule path 'sdk/OpenBK7231N': checked out '33e07564651527db8b3521371676018d23aa4777'
Submodule path 'sdk/OpenBK7231T': checked out '8b24161c84a85ecec1eb8083a0d3f572dc5bd3eb'
Failed to recurse into submodule path 'sdk/esp-idf'
make: *** [Makefile:34: submodules] Error 1
****************************************

But this seem to have no impact.

install.sh complained about missing ensurepip:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

--> so I needed "sudo apt install python3.10-venv" for this.

install.sh and export.shnow worked.

First "make" failed:

Make Error at [...]/esp_IDF/OpenBK7231T_App/sdk/esp-idf/tools/cmake/component.cmake:225 (message):
  CMake Warning (dev) at idf/build-32/build_properties.temp.cmake:8:

    Syntax Warning in cmake code at column 106

  

    Argument not separated from preceding token by whitespace.

  Call Stack (most recent call first):

    sdk/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:3 (include)

  This warning is for project developers.  Use -Wno-dev to suppress it.

  

  CMake Error at sdk/esp-idf/components/mqtt/CMakeLists.txt:3 (message):

    Missing esp-mqtt submodule.  Please run 'git submodule update --init
    --recursive' in ESP-IDF directory to fix this.

  Call Stack (most recent call first):

    sdk/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:107 (include)
    sdk/esp-idf/tools/cmake/scripts/component_get_requirements.cmake:127 (__component_get_requirements)

And: Several "Git submodule XY is out of date." --> Fixed with "git submodule update --init --recursive".

After this, the error above (Make Error ...) also disappeard.

The only possible device I have is ESP32 (I have some S2 or S3, but no C types), which fails due to flash memory:

[  0%] Generating project_elf_src_esp32.c
[  0%] Built target sections.ld.in
[  0%] Built target memory.ld
Partitions tables occupies 3.1MB of flash (3211264 bytes) which does not fit in configured flash size 2MB. Change the flash size in menuconfig under the 'Serial Flasher Config' menu.

I failed to figure out, where to start menuconfig, to be able to change this.
Just changing the line in Makefile for ESP32 from "2MB" to "4MB" didn't work.

Just for fun I build an C3 image, but hav no possibility to test it...

@divadiow
Copy link
Contributor

divadiow commented Sep 9, 2024

sling me a binary if you want anything tried on this. still in wrapper, crying out for attention

image

@MaxineMuster
Copy link
Contributor

Here are the C2 and C3 binaries I made (but couldn't test)...
dev_20240909_C2+C3.zip

@divadiow
Copy link
Contributor

divadiow commented Sep 9, 2024

ESP Chip Id | 998692 (ESP32-C2 v1.0)
0x1640C8 (QIO)
4096 KB

@openshwprojects
Copy link
Owner

Very good job! Out of curiosity, does it mean that we can also port to ESP8266 easily, or are ESP32 and old ESP8266 fundamentally different?

btw there seems to be a compile error related to some preprocessor condition.

@divadiow
Copy link
Contributor

divadiow commented Sep 9, 2024

cool

image
image

@divadiow
Copy link
Contributor

divadiow commented Sep 9, 2024

oh. I do have a C3 in one of these https://www.aliexpress.com/item/1005006690897107.html for future ref

@NonPIayerCharacter
Copy link
Contributor Author

NonPIayerCharacter commented Sep 9, 2024

Added S2 and S3. Fixed ESP32.
As for ESP8266, Non-OS SDK is out. FreeRTOS SDK is IDF-style, and can even be implemented on top of esp32's HALs.
But, there are differences. ADC will have different implementation, IDF have esp_pm_config_t, 8266 have identical esp_pm_config_esp8266_t and separate esp_pm_config_t. 8266 doesn't have esp_netif_set_default_netif (i will have to test if it is even needed on 32). No temperature sensor on 8266.
And what to do about partitions? Smallest 8266 have 512k flash. 8285 in ESP-02S has only 1M, so what to take as a base? And is it even enough for APP/APP + LFS?

@divadiow
Copy link
Contributor

divadiow commented Sep 9, 2024

cool

ESP8684-ESP32-C2-OBK-BOOT.txt

@openshwprojects
Copy link
Owner

Regarding partitions, I will just say one suggestion - if possible, it would be nice to have the same format as Tasmota, so the OTA in two ways is possible.

@NonPIayerCharacter NonPIayerCharacter marked this pull request as ready for review September 10, 2024 03:28
@MaxineMuster
Copy link
Contributor

Some additional Feedback:

ESP32 now compiles, but start fails:

rst:0x3 (SW_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:0x3fff0030,len:7176                                                                                                 
load:0x40078000,len:15564
ho 0 tail 12 room 4
load:0x40080400,len:4
load:0x40080404,len:3904
entry 0x40080640
I (60) boot: ESP-IDF v5.3.1 2nd stage bootloader
I (60) boot: compile time Sep 10 2024 08:00:48
I (60) boot: Multicore bootloader
I (65) boot: chip revision: v1.0
I (69) boot.esp32: SPI Speed      : 40MHz
I (74) boot.esp32: SPI Mode       : DIO
I (78) boot.esp32: SPI Flash Size : 2MB
I (83) boot: Enabling RNG early entropy source...
E (88) flash_parts: partition 2 invalid - offset 0x190000 size 0x180000 exceeds flash chip size 0x200000
E (98) boot: Failed to verify partition table
E (103) boot: load partition table error!
ets Jun  8 2016 00:22:57

This could be easily overcome by changing flash size in Makefile:

--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,7 @@ OpenESP32:
        IDF_TARGET="esp32" USER_SW_VER=$(APP_VERSION) cmake idf -B idf/build-32 
        IDF_TARGET="esp32" USER_SW_VER=$(APP_VERSION) cmake --build ./idf/build-32 -j $(shell nproc)
        mkdir -p output/$(APP_VERSION)
-       esptool.py -c esp32 merge_bin -o output/$(APP_VERSION)/OpenESP32_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 2MB 0x1000 ./idf/build-32/bootloader/bootloader.bin 0x8000 ./idf/build-32/partition_table/partition-table.bin 0x10000 ./idf/build-32/OpenBeken.bin
+       esptool.py -c esp32 merge_bin -o output/$(APP_VERSION)/OpenESP32_$(APP_VERSION).factory.bin --flash_mode dio --flash_size 4MB 0x1000 ./idf/build-32/bootloader/bootloader.bin 0x8000 ./idf/build-32/partition_table/partition-table.bin 0x10000 ./idf/build-32/OpenBeken.bin
        cp ./idf/build-32/OpenBeken.bin output/$(APP_VERSION)/OpenESP32_$(APP_VERSION).img
 
 .PHONY: OpenESP32C3

Than ESP starts! Thanks a lot.

I tried to play around with DS1820 (after some changes for critical sections didn't work [if I got it right, this will need to know, on which core the tasks run).
usleep seems to work at least for the big test loop (usleep (100000) will sleep exactly 100ms)
But I didn't see any changes on the pin with my logic analyzer. The line is pulled up, but never going down, which I would expect, even if timing is wrong.
Maybe I just made some stupid mistake here or did I miss something on how to use pins??
Can someone confirm, PIN numbering works as expected?
I tried e.g. to make IO 14 a relays, expecting the output to toggle on "switching" on the main page, but it won't.

@MaxineMuster
Copy link
Contributor

After some more tests:
Issues with GPIOs are only present on my ESP32 - it's a DevBoard C with a WROOM-32.

GPIOs work like expected on S2 and S3 boards.

@MaxineMuster
Copy link
Contributor

MaxineMuster commented Sep 10, 2024

Very good! Thank you so much!
It now works also on ESP32, including a "regular" start (used to start in safe mode) and GPIOs working (tested with DS1820)!

@divadiow
Copy link
Contributor

divadiow commented Sep 10, 2024

Tested LED + BMP280 on ESP32-C3 super mini.

can someone please confirm BME/BMP280 operation on a C2? I'm using "startdriver bmpi2c 3 2 1 2 0" because:

// startDriver BMPI2C [CLK] [DATA] [ChannelForTemp] [ChannelForPressure] [ChannelForHumidity] [Addr]
// Adr8bit 0 for 0x77, 1 for 0x76

but not getting any readings. same with BME680 and AHT20/BMP280 combined modules.

@divadiow
Copy link
Contributor

What do the gpio changes in here mean in practicality? 4056bd7

@NonPIayerCharacter
Copy link
Contributor Author

From what i have seen, if gpio_reset_pin, then by default pins are pulled up. We already have hal functions to configure pins as input pup/pdown, so now when using HAL_PIN_Setup_Input, set pull mode as floating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants