(resolved) problem with esptool.py

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(resolved) problem with esptool.py

Postby mzimmers » Mon Dec 02, 2019 10:13 pm

Hi all -

Since migrating to V4 of the IDF (under Windows), I've run into an issue using esptool.py. Whereas I used to be able to run a command like this:

Code: Select all

C:\esp32_projects\wifibutton>esptool.py write_flash 0x9000 nvs_reuse.bin
I now have to do it like this:

Code: Select all

C:\esp32_projects\wifibutton>python C:\esp32_toolchain\python_env\idf4.0_py3.7_env\Lib\site-packages\esptool.py write_flash 0x9000 nvs_reuse.bin
Obviously not convenient. If I attempt to run it the old way, it's as though the arguments aren't getting passed through to the script. Did I miss a step in the installation, or is there some workaround I'm not aware of?

Thanks...
Last edited by mzimmers on Thu Dec 12, 2019 10:41 pm, edited 1 time in total.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: problem with esptool.py

Postby ESP_Angus » Wed Dec 04, 2019 3:01 am

Hi mzimmers,

Are you using the IDF Command Prompt, or MSYS2, or something else?

The V4.0 Windows installer setups a Python virtualenv with a dedicated copy of Python and its own set of installed Python modules. If you run the IDF Command Prompt then you'll be inside this Python environment.

The fact that there is a file "idf4.0_py3.7_env\Lib\site-packages\esptool.py" suggests that "pip install esptool" has been run while inside the virtualenv. This is not required by ESP-IDF but it's fine, doesn't harm anything (ESP-IDF will use the copy of esptool inside IDF_PATH/components/esptool_py/esptool).

If you're using IDF Command Prompt, then because esptool was installed with pip in the virtualenv then you should be able to run "esptool.py write_flash 0x9000 nvs_reuse.bin" without needing anything else. If it doesn't work in the virtualenv, try running "pip install esptool" again.

If you're using a different command prompt, the solution may be different. Running "esptool.py" with the default Python environment (ie a normal Command Prompt) may work depending on how the Windows python installation is configured.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem with esptool.py

Postby mzimmers » Wed Dec 04, 2019 3:05 am

Hi Angus - yes, I am running the ESP-IDF Command Prompt. (I was using MYSYS2 when working with V3 of the IDF).

I'll try re-installing esptool again tomorrow and report back.

Thanks...

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem with esptool.py

Postby mzimmers » Wed Dec 04, 2019 2:53 pm

No luck.

When I start up the ESP-IDF Command Prompt, here's what I get:

Code: Select all

Using Python in C:\Users\mzimmers.CYBERDATA\AppData\Local\Programs\Python\Python37\
Python 3.7.3
Using Git in C:\Program Files\Git\bin\
git version 2.21.0.windows.1
Setting IDF_PATH: C:\esp-idf

Adding ESP-IDF tools to PATH...
    C:\esp32_toolchain\tools\xtensa-esp32-elf\esp32-2019r1-8.2.0\xtensa-esp32-elf\bin
    C:\esp32_toolchain\tools\esp32ulp-elf\2.28.51.20170517\esp32ulp-elf-binutils\bin
    C:\esp32_toolchain\tools\cmake\3.13.4\bin
    C:\esp32_toolchain\tools\openocd-esp32\v0.10.0-esp32-20190313\openocd-esp32\bin
    C:\esp32_toolchain\tools\mconf\v4.6.0.0-idf-20190628\
    C:\esp32_toolchain\tools\ninja\1.9.0\
    C:\esp32_toolchain\tools\idf-exe\1.0.1\
    C:\esp32_toolchain\tools\ccache\3.7\
    C:\esp32_toolchain\python_env\idf4.0_py3.7_env\Scripts
    C:\esp-idf\tools

Checking if Python packages are up to date...
Python requirements from C:\esp-idf\requirements.txt are satisfied.

Done! You can now compile ESP-IDF projects.
Go to the project directory and run:

  idf.py build


C:\esp-idf>
And when I try to run esptool.py, here's the (start of) output:

Code: Select all

C:\esp32_projects\wifibutton\mfg>esptool.py write_flash 0x9000 nvs_reuse.bin
esptool.py v2.8
usage: esptool [-h] [--chip {auto,esp8266,esp32}] [--port PORT] [--baud BAUD]
               [--before {default_reset,no_reset,no_reset_no_sync}]
               [--after {hard_reset,soft_reset,no_reset}] [--no-stub]
The output is the same whether I execute the command with no parameters, or with nonsense parameters.

plusorc
Posts: 36
Joined: Sat Nov 09, 2019 6:27 am

Re: problem with esptool.py

Postby plusorc » Wed Dec 04, 2019 3:24 pm

@mzimmers
Can you test this ?
Put the full address of the Bin file you're flashing .. not the IDF environment
I recently has a similar issue and it was esptool needing the full path of the Bin file


@ESP_Angus
With all due respect , I found the IDF Command in windows is very inconvenient
I wish there is a way to add those to the Path and be able to run idf.py from any directory .
I use vscode and can't find a way to invoke idf.py from vscode , because I have to use the IDF command
If I copy the link of the shortcut , I get "This has to be run from ...."
a message telling that I have to be in the directory to use the idf.py

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem with esptool.py

Postby mzimmers » Wed Dec 04, 2019 6:41 pm

Hi plusorc - thanks for the suggestion. I'm really more interested, however, in getting the command to work the way that Angus says it should. I probably messed up something with my install; I'm hoping that someone might have an idea exactly where to look.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem with esptool.py

Postby mzimmers » Tue Dec 10, 2019 7:57 pm

BTT. Any suggestions? Thanks...

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: problem with esptool.py

Postby ESP_Angus » Wed Dec 11, 2019 3:24 am

Hi mzimmers,

Sorry, I gave you some incorrect information - I thought that "pip install esptool" would install an esptool.py.exe on the PATH, but it's actually "esptool.exe".

I ran through the install steps on a clean VM again. You should be able to run:

Code: Select all

esptool write_flash 0x9000 nvs_reuse.bin
In the ESP-IDF Tools Command Prompt window, and this should work.

(You could also choose to "pip install esptool" inside your global Python install to run esptool.exe from any command prompt window.)


BTW, even though ESP-IDF build system will print full paths to everything:

Code: Select all

C:\Users\gus\.espressif\python_env\idf4.0_py2.7_env\Scripts\python.exe ..\..\..\components\esptool_py\esptool\esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build\bootloader\bootloader.bin 0x8000 build\partition_table\partition-table.bin 0x10000 build\hello-world.bin
You can strip off the first part and run this, if you're in the ESP-IDF Command Prompt then python.exe is on the PATH:

Code: Select all

python.exe ..\..\..\components\esptool_py\esptool\esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build\bootloader\bootloader.bin 0x8000 build\partition_table\partition-table.bin 0x10000 build\hello-world.bin
OR

Code: Select all

python.exe %IDF_PATH%\components\esptool_py\esptool\esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build\bootloader\bootloader.bin 0x8000 build\partition_table\partition-table.bin 0x10000 build\hello-world.bin
(These last two work without the "pip install esptool" step required.)

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: problem with esptool.py

Postby mzimmers » Wed Dec 11, 2019 3:35 pm

Hi, Angus - thanks, that did help. Now: can anything be done about making this command briefer?

Code: Select all

$ python C:\esp-idf\components\nvs_flash\nvs_partition_generator\nvs_partition_gen.py generate nvs_reuse.csv nvs_reuse.bin <size>

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: problem with esptool.py

Postby ESP_Angus » Wed Dec 11, 2019 11:49 pm

mzimmers wrote:
Wed Dec 11, 2019 3:35 pm
Hi, Angus - thanks, that did help. Now: can anything be done about making this command briefer?

Code: Select all

$ python C:\esp-idf\components\nvs_flash\nvs_partition_generator\nvs_partition_gen.py generate nvs_reuse.csv nvs_reuse.bin <size>
Maybe, but it's not straghtforward on Windows. On other OSes it's pretty simple to add C:\esp-idf\components\nvs_flash\nvs_partition_generator\ to your PATH and then you can run nvs_partition_gen.py as a script...

On Windows this depends on what associations are crerated for .py files to launch with on Windows. If you can set them to launch with a Python interpreter that has all of the libraries required (either the python.exe inside the IDF virtualenv, or your global Python if you've installed anything that's needed there) then this will work. But it's outside the scope of ESP-IDF, sorry.

I'd suggest adding a custom target to your project CMakeLists file to run the generator automatically on each build, instead.

Who is online

Users browsing this forum: Baidu [Spider], DrMickeyLauer, ESP_rrtandler and 121 guests