platformio / platform-espressif32

Espressif 32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif32
Apache License 2.0
926 stars 626 forks source link

ESP32-C6, espidf, error when using components folder, led_strip,h #1243

Closed andychess closed 11 months ago

andychess commented 11 months ago

I have recently started porting a project to the ESP32-C6. Today I got the followng error which I traced back to an instance of a class that implements the RGB-LED component from espressif.

A fatal error occurred: Contents of segment at SHA256 digest offset 0xb0 are not all zero. Refusing to overwrite.

https://stackoverflow.com/questions/77165764/esp-idf-platformio-build-contents-of-segment-at-sha256-digest-offset-0xb0-are-n

Jason2866 commented 11 months ago

esptool tries to patch the magic header which is rejected because there is a checksum over the whole file which would be invalid by doing this. This happens normally when the provided flash size in settings does not match the real size of the device (the real size is detected from esptool)

andychess commented 11 months ago

I wondered if the flash might have something to do with it, but in that case, why does it happen just on this particular build and not on every one?

Jason2866 commented 11 months ago

There is nothing different in Platformio build process regarding this part for different MCU types. What board do you have defined in Platformio? There are two C6 boards. One with 4MB flash and one with 8MB flash. If you use the board definition with 4MB and your connected board has 8MB you will run in this error. BTW. This behaviour annoyed me too, in my fork i have patched the builder not to add a sha digest, so esptool can patch the header. The only side effect of this patch, there is always a boot message calculated sha does not match stored sha in firmware.

andychess commented 11 months ago

Here is the verbose output:

Bildschirmfoto 2023-12-01 um 14 23 49 Bildschirmfoto 2023-12-01 um 14 48 48
andychess commented 11 months ago

Thanks for your help Jason:-). I forgot to mention that the physical board is the Waveshare ESP32-C6-DEV-KIT-N8. I tried with both devkits in platformio (esp32-c6-devkitm-1 and esp32-c6-devkitc-1) and got the same behaviour with both.

Jason2866 commented 11 months ago

Mhh, strange. Can you try this setup with the board esp32-c6-devkitc-1:

platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.11.11/platform-espressif32.zip
platform_packages = framework-espidf @ https://github.com/tasmota/esp-idf/releases/download/v5.1.2-org/esp-idf-v5.1.2-org.zip

If this is not working set in sdkconfig the option CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y or wait i think the option name has changed to CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.0/tools.html#esptool

andychess commented 11 months ago

Interesting. At first the suggestions above didn't work, but then I reset platform.ini to the original settngs and suddenly it now works.

Whilst looking through the sdkconfig, I did notice this:

Bildschirmfoto 2023-12-01 um 17 51 41

Is the CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y correct?

This is the latest output:

Bildschirmfoto 2023-12-01 um 17 57 15
andychess commented 11 months ago

The only problem now is that the upload isn't working.

Bildschirmfoto 2023-12-01 um 18 10 59
Jason2866 commented 11 months ago

No esptool flashsize should be 8MB for your device. Probably the reason why it failed at first. Why it now does not flash? Idk. Can you post you Platformio.ini? You have configured the C6 before with platformio run -t menuconfig?

Jason2866 commented 11 months ago

You can try my example LittleFS project. https://github.com/Jason2866/Arduino_IDF_LittleFS/tree/test_51 Verified working. Just use as the C6 board the esp32-c6-devkitc-1

andychess commented 11 months ago

I checked menuconfig and the 8MB was set there. I made no changes. Now I get some new error messages:

Bildschirmfoto 2023-12-02 um 12 25 43

Platformio.ini looks like this at the moment:

Bildschirmfoto 2023-12-02 um 12 28 34

I realised that I don't know anywhere near enough about esptool.py. I've been happy so far that it just worked. I found this video from Devcon22 which I would recommend to anyone who hasn't seen it aleady.

https://www.youtube.com/watch?v=GjWGKzu3XTk

Jason2866 commented 11 months ago

Your code is probably to blame. Your c6 env is a bit weird too. No need to specify the MCU type. It is defined in the boards.json. Why fiddling around with c++ version? When running in issues such stuff should be removed. If you have a working setup you can try.

Seeing esptool.py v4.5.1 in your screenshot, you are not using the setup from me. Trying random stuff will not end in a success

andychess commented 11 months ago

Quite a few issues there.

I did use your suggested setup (see above) and this partially worked but wouldn't upload. Then I spotted the problem in the sdkconfig which I think has solved the problem. I just ran menuconfig and saved without making any changes, having checked the flash size was indeed 8MB.

The reference to the MCU comes straight out of the platformio board documentation and I only added the specific references when this problem appeared.

The C++ version is simply there because I write in C++ ;-). The project has been running for over a year and only recently did I start to port to the C6 having been working on the Heltec V3 LoRa board until now.

Anyway. I just cleaned everything, ran menuconfig and can now upload to the board, so the problem seemed to be the incorrect entry in the sdkconfig.

I really appreciate your help in getting to the bottom of this and for the additional information provided.

Jason2866 commented 11 months ago

There are errors in Pio docu too. The entry of MCU is redundant and not needed.

valeros commented 11 months ago

Closing as solved.

ss89 commented 3 months ago

@valeros how was it solved? i'm stumbling across the same issue using esphome, so not really writing any code. refs: https://github.com/esphome/issues/issues/5938