Jason2866 / platform-espressif32

Tasmota Espressif 32: development platform for PlatformIO
Apache License 2.0
57 stars 22 forks source link

Upload Problem With ESP32-H2 #52

Closed rvbc1 closed 10 months ago

rvbc1 commented 10 months ago

Hello,

I've been trying out your IDF5 branch and here's my configuration in platformio.ini:

platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF5
board = esp32-h2-devkitm-1
framework = arduino

Everything seems to be working fine so far (the code compiles), but I encounter an issue when trying to upload the firmware. Here's what I see:

Building in release mode
Retrieving maximum program size build/local/firmware.elf
Checking size build/local/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.2% (used 7132 bytes from 327680 bytes)
Flash: [=         ]   6.4% (used 125960 bytes from 1966080 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Using manually specified: /dev/ttyUSB1
Uploading build/local/firmware.bin
usage: esptool write_flash [-h] [--erase-all]
                           [--flash_freq {keep,80m,60m,48m,40m,30m,26m,24m,20m,16m,15m,12m}]
                           [--flash_mode {keep,qio,qout,dio,dout}]
                           [--flash_size {detect,keep,256KB,512KB,1MB,2MB,2MB-c1,4MB,4MB-c1,8MB,16MB,32MB,64MB,128MB}]
                           [--spi-connection SPI_CONNECTION] [--no-progress]
                           [--verify] [--encrypt]
                           [--encrypt-files <address> <filename> [<address> <filename> ...]]
                           [--ignore-flash-encryption-efuse-setting] [--force]
                           [--compress | --no-compress]
                           <address> <filename> [<address> <filename> ...]
esptool write_flash: error: argument --flash_freq/-ff: invalid choice: '64m' (choose from 'keep', '80m', '60m', '48m', '40m', '30m', '26m', '24m', '20m', '16m', '15m', '12m')
*** [upload] Error 2

In Arduino IDE 2.2.1 and Arduino 3.0.0-alpha2, the compilation and upload process both work fine. Could you possibly help me figure out how to fix this issue? Or could you guide me on where to adjust the settings for esptool to get this working correctly?

rvbc1 commented 10 months ago

Ok, I found a workaround.

I added the following line to platformio.ini:

extra_scripts = pre:modify_upload.py

And created a "modify_upload.py" script:

Import("env")

def before_upload(source, target, env):
    uploader_flags = env['UPLOADERFLAGS']

    try:
        index = uploader_flags.index('--flash_freq') + 1
        uploader_flags[index] = 'keep'
    except ValueError:
        print("Not found '--flash_freq' in flags")

    env.Replace(UPLOADERFLAGS=uploader_flags)

env.AddPreAction("upload", before_upload)

I discovered the "keep" parameter in the Arduino IDE upload command.

Hopefully, this workaround can help others until the upload command issue is resolved. ;)

Jason2866 commented 10 months ago

@rvbc1 I have no H2 to test. So there is high chance there are maybe other bugs which only occurs with a real device connected. Will have a look into, probably similar as the changes needed for the C2. Can you post your used boards.json for the H2 and the Platformio env for?

Have you used the boards.json esp32-h2-devkitm-1? If not the error is in your setup. There is an extra setting needed for the H2 -> img_freq. This setting is provided in the H2 boards.json and it is implemented to use. There is still a chance i made a mistake here. But without using the H2 boards json it will fail.

This is the commit https://github.com/Jason2866/platform-espressif32/commit/37cafcc4745c0764f931fa0c6a26596041ba58ba with the needed changes for the H2 (Adopted for Platformio as it is done for ArduinoIDE in platforms.txt).

The option keep is a bad idea here, it can end in bootloops. The correct value needs to be provided.

Jason2866 commented 10 months ago

Mhh, probably this needs to be changed everywhere https://github.com/Jason2866/platform-espressif32/blob/Arduino/IDF5/builder/main.py#L430

from "--flash_freq", "${__get_board_f_flash(__env__)}", to "--flash_freq", "${__get_board_img_freq(__env__)}",

EDIT: Try

platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/H2
board = esp32-h2-devkitm-1
framework = arduino
rvbc1 commented 10 months ago

Hi,

Thank you so much for your help and dedication in solving this issue. I am indeed using the 'esp32-h2-devkitm-1' setup. After applying your suggested solution (platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/H2), the board programs without any issues. I am aware that the 'keep' parameter might not be the best choice, but I started my tests with this ESP32 H2 board, and while I could program it through the Arduino IDE, PlatformIO was not compatible, which is why I copied this parameter from there.

Thank you once again for your assistance! You mentioned that you do not have access to the H2 board, so if you ever need anything tested, just let me know. I have these boards in stock and would be happy to help out.

Jason2866 commented 10 months ago

Thx, for testing will merge the changes in branch Arduino/IDF5