espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.75k stars 7.3k forks source link

ESP32 Windows Setup Guide - Correction (IDFGH-953) #200

Closed ghost closed 7 years ago

ghost commented 7 years ago

(Note: this material refers to an older version of IDF. Current Windows setup documentation can be found at http://esp-idf.readthedocs.io/en/latest/get-started/windows-setup.html )

Section One - Creating The Environment

I present to you the simplest method, according to me.

  1. Download MSYS2 installer from: https://msys2.github.io I made all steps on the 32-bit version. I don't test 64-bit MSYS2, You can check at your own risk. (Possible errors) File name: msys2-i686-20161025.exe

  2. Install MSYS2 where You want, but be careful! NEVER USE SPACE CHAR IN THE FILES PATH. After the installation is complete. You can run MSYS2 from setup wizard or msys32/msys2.exe program.

If you do not want to do the rest manually, paste and run this command in MSYS2 console and go to the section two. This option provides additional useful features.

curl -sS https://raw.githubusercontent.com/user/VariousDestiny/master/esp32/esp32-autotoolchain-msys2.sh > /esp32-autotoolchain-msys2.sh && cd / && chmod +x esp32-autotoolchain-msys2.sh && ./esp32-autotoolchain-msys2.sh
  1. Now, you must update your MSYS2. Write these commands. Becouse MSYS2 have got pacman package manager, I used it. If the program asks for approval, type t. You MUST write these 3 commands!

    • Update the package database and pacman: pacman -Sy pacman
    • Update the package database and core system packages: pacman -Syu
    • Update the rest. pacman -Su
  2. Write in MSYS2 console:

    cd /
    mkdir home
    mkdir opt
  3. Now you must join to msys32/home directory, in your windows. In my case, localisation is: C:\msys32\home Now is time to download several files.

    • Download windows_install_prerequisites.sh script from this localisation: https://raw.githubusercontent.com/espressif/esp-idf/master/tools/windows/windows_install_prerequisites.sh
    • Download get-pip.py from: https://bootstrap.pypa.io/get-pip.py
    • The last one file is 'pyserial-3.2.1.tar.gz' or download latest version, from here: https://github.com/pyserial/pyserial/releases If you download another version, remember to change some commands where pyserial is.

Save this three files to msys32/home directory.

user@user MSYS /
$ cd /home

user@user MSYS /home
$ ls
get-pip.py  pyserial-3.2.1.tar.gz  windows_install_prerequisites.sh
  1. Now you must install Python version 2.7. Write in MSYS2 console this: pacman -S python2 and type t, if program ask you about it.

VERY IMPORTANT: you must change Python name. from: python2.7.exe or python2.exe to python.exe.

For compatibility, write this in MSYS2 console:

cd /usr/bin
cp python2.exe python.exe
  1. You need tar program, for unpack the files. Write this in MSYS2 console: pacman -S tar and type t for true.

  2. Now you must run some scripts for the installation of the necessary files. Write this commands:

    cd /home
    ./get-pip.py
    tar -xvf pyserial-3.2.1.tar.gz
    cd pyserial-3.2.1/
    python setup.py install
    cd ..
    ./windows_install_prerequisites.sh

    After all, You must see it:

    
    ************************************************
    MSYS2 environment is now ready to use ESP-IDF.
    Run 'source /etc/profile' to add the toolchain to
    your path. Execute 'msys_shell.cmd' to launch an
    MSYS terminal.

Once ESP-IDF is downloaded/checked out, set the environment variable IDF_PATH in /etc/profile to point to the directory.


All is well.

9. Remove unnecessary files

cd /home rm get-pip.py rm pyserial-3.2.1.tar.gz rm -rf pyserial-3.2.1/ rm windows_install_prerequisites.sh


10. Now, you must download `Espressif IoT Development Framework` and `Template Application`,
commands for this:

cd /home git clone --recursive https://github.com/espressif/esp-idf.git git clone https://github.com/espressif/esp-idf-template.git


11. Write this commands for auto setup `xtensa-esp32-elf` and `esp-idf` path.

cd /home/esp-idf chmod +x add_path.sh echo "export IDF_PATH=\"/home/esp-idf\"" >> /etc/profile.d/esp32_toolchain.sh echo "cd /home/esp-idf" >> /etc/profile.d/esp32_toolchain.sh echo ". add_path.sh > /dev/null" >> /etc/profile.d/esp32_toolchain.sh echo "cd /home" >> /etc/profile.d/esp32_toolchain.sh echo "echo \"MSYS2 console for ESP32\"" >> /etc/profile.d/esp32_toolchain.sh


12. Restart MSYS2 and You are ready for build your first app !

Section Two - Compiling And Flashing Applications
---

For build your first app, follow these steps.

1. Open `esp-idf-template` directory
`cd /home/esp-idf-template`

2. Prepare project, type:
`make menuconfig`

Go to `Serial flasher config` and select for yourself `Flash SPI mode` `Flash SPI speed` `Flash size`
Go back, and select `Optimalization level (Debug)` and change it to `Release`
At the bottom menu, press `Save`, `Ok`, `Exit`.
`Exit` to return.

3. To compile application type:
`make all`

At the end, you can see similar command:

To flash all build output, run 'make flash' or: python /home/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 /home/esp-idf-template/build/bootloader/bootloader.bin 0x10000 /home/esp-idf-template/build/app-template.bin 0x8000 /home/esp-idf-template/build/partitions_singleapp.bin


What is important? Let's see.

Now you must write you app to ESP32-SPI memory, I use `flash_download_tools_v3.4.4` from
`https://espressif.com/en/products/hardware/esp32/resources`
At the bottom in section `Tools`, you can download this program.

`--baud 115200`, you must set baud rate: `115200`
`--flash_mode dio`, set `SPI MODE` as `dio`, or the same that you selected in `menu config`
`--flash_freq 40m`, set `SPI SPEED` 40MHz

Now cherry on the cream.

0x1000 /home/esp-idf-template/build/bootloader/bootloader.bin 0x10000 /home/esp-idf-template/build/app-template.bin 0x8000 /home/esp-idf-template/build/partitions_singleapp.bin


You can see first hex number and then file. For better example, you must select in flash tool file named: `bootloader.bin` and set for this file address `0x1000`.

Select Flash Size, in flash tool you see e.g `8Mbit`;  `8Mbit/8 = 1MB flash`, `128Mbit/8 = 16MB flash`.

Remember about `COM`, you can find it in `Windows Device Manager`.

Enter to `Download Mode` in ESP32, and click `Start` button to flash app to memory.

Or you can use the `make flash` method, but for this you must set in `make menuconfig -> Serial flasher config` the correct port.

A hint: 
in Windows `COM1`=`/dev/ttyS0` in MSYS2 console. `COM2`=`/dev/ttyS1` `COM8`=`/dev/ttyS7`

End
---

I think, it's all. If something is wrong, tell me it!
Good Luck!
projectgus commented 7 years ago

Hi Michal,

Thanks for contributing this set of steps. We're very keen to make the Windows instructions as easy as possible, however it's not precisely clear to me in what way these steps are easier than the official getting started guide.

As a starting point, could you please explain to me the problems you've found with the existing Windows setup guide. I'd like to understand your motivations for writing this document. Then perhaps we can work through them together to find improvements.

occamw commented 7 years ago

Up to Section Two - Compiling And Flashing Applications step2. all seems to be OK. When running step 2. "make menuconfig" following error shows up: zconf.hash.c:166:1: error: conflicting types for ‘kconf_id_lookup’ kconf_id_lookup (register const char str, register size_t len) ^~~~~~~ zconf.hash.c:33:31: note: previous declaration of ‘kconf_id_lookup’ was here static const struct kconf_id kconf_id_lookup(register const char *str, register unsigned int len);

Please help!

occamw commented 7 years ago

The suggestion to update gperf.git is no help!

projectgus commented 7 years ago

@occamw in future, please open a new issue for an new/different error instead of commenting on an existing issue.

zconf.hash.c:33:31: note: previous declaration of ‘kconf_id_lookup’ was here static const struct kconf_id kconf_id_lookup(register const char str, register unsigned int len);

Please help!

The new gperf version 3.1 changed the type signature for ID lookup functions. There is a fix for this coming soon in esp-idf, but in the meantime you can entirely delete this line in zconf.gperf (note this is in a different file to zconf.hash.c, which is autogenerated by gconf from this source file): https://github.com/espressif/esp-idf/blob/master/tools/kconfig/zconf.gperf#L12 ... and it should build correctly.

projectgus commented 7 years ago

zconf.hash.c:33:31: note: previous declaration of ‘kconf_id_lookup’ was here This is fixed in the master branch as of 578e938.

wfbrown53 commented 7 years ago

Worked like a charm. Only issue I saw was having to run the build multiple times to get all the projects built. Seems to all have been built after all that. Thanks for the efforts Michael.

projectgus commented 7 years ago

Hi @michal037 ,

I think the fixes in 5faee6a should take care of the problems you were describing here. If you think there is anything left which doesn't work smoothly with the Windows setup, please open a new issue and let us know about it.

Angus

brownx commented 7 years ago

The Windows setup from http://esp-idf.readthedocs.io/en/latest/windows-setup.html still not complete - at least not the pre-prepared environment. The make for the template project searches for python: _... CC bootloader_start.o AR libmain.a LD bootloader.elf /bin/sh: python: command not found make[1]: [/d/Sources/esp-idf/components/esptool_py/Makefile.projbuild:49: /d/Sources/esp-idf-template/build/bootloader/bootloader.bin] Error 127 make: [/d/Sources/esp-idf/components/bootloader/Makefile.projbuild:31: /d/Sources/esp-idf-template/build/bootloader/bootloader.bin] Error 2_

Tried to add the C:\msys32\mingw32\bin to %PATH% in the environment variables since there I have seen python but solved nothing.

projectgus commented 7 years ago

@brownx there's a mistake in one of the steps, you need to run ...\msys32\mingw32.exe not ...\msys32\msys_shell.cmd. It was only changed in one place not both places in the docs.

Ref: https://github.com/espressif/esp-idf/issues/493#issuecomment-291690881

Documentation fix coming shortly.

Gfast2 commented 7 years ago

@projectgus And it's not msys2.exe neither. (ps: spend about 2h to figure this out)

projectgus commented 7 years ago

Hi @Gfast2,

I'm very sorry to hear that. From what I can see it looks like msys2.exe was incorrectly mentioned in the first post in this issue.

Rather than using the user-submitted guide found above, please use our official documentation here:

http://esp-idf.readthedocs.io/en/latest/get-started/windows-setup.html

it's been improved significantly since this issue was first opened. I've added a note at the top of the issue with a link, as I'm guessing this is turning up in Google searches and the like (major thanks to @michal037 who originally contributed the above steps - a lot of the observations & suggestions shown there have been rolled into the official documentation.)

If you find any shortcomings in the official documentation, please open issues to report them - we'll gladly fix them.

Gfast2 commented 7 years ago

@projectgus All right. Thank you all again for the effort behind the scene! I really appriciate! ps: Since I'd building some industrial level device based on ESP32 right now. Is there some list to showing sold production Product based on this chip?

memory125 commented 5 years ago

It's seemingly we should open the mingw32.exe not msys2.exe while compiling and flashing on Windows.

memory125 commented 5 years ago

@memory125 It was my mistake. I did not notice it then. That's why I tried to figure out why it does not work.

No worries, it works fine now.

diegosantos3 commented 5 years ago

Hi michal037, and thk thk thk thk thk a lot !!! If i not get your post i never will do my project start !!! Ir is very cool man, keep going !!! thk again :)

hussaa1 commented 4 years ago

Hello Michal037,

I really liked your solution for setting up my ESP-IDF after failing to install properly with expressif website tutorials. Although your details are very well explained and documented with clear understanding, I am still not able to compile an app in my environment. The make all process just sits there all day long without compiling. In the end I have to just terminate the process.

Initially I tried to install everything manually and didn't succeed and then I tried to install with the long one off command set that you have provided. Before I tried the long command set, I reinstalled my MSYS2 32bit program in a different location on my Windows 7 32bit machine C:/msys2 directory without any space chars etc.

I am getting this error and don't know what to do. Any suggestions?

$ curl -sS https://raw.githubusercontent.com/michal037/VariousDestiny/master/esp32/esp32-autotoolchain-msys2.sh > /esp32-autotoolchain-msys2.sh && cd / && chmod +x esp32-autotoolchain-msys2.sh && ./esp32-autotoolchain-msys2.sh ./esp32-autotoolchain-msys2.sh: line 1: 404:: command not found

Many thanks

projectgus commented 4 years ago

Hi @hussaa1 & @michal037 ,

Maybe look for a mailing list (if it exists)? To get advice on how to fix it right now.

We don't have a mailing list but there is an active forum: https://esp32.com/

@hussaa1, if following the Get Started Guide for the version of ESP-IDF that you're using is not working then please post there with some details about what you've done and what error(s) you see, and someone should be able to help.

Note that in ESP-IDF V4.0 and newer, we no longer require or recommend MSYS2/MINGW32 for Windows users - the Get Started steps will guide you through a different installation method.