-->
Page 1 of 6

New Windows terminal/flasher apps & Visual Studio

PostPosted: Wed Dec 17, 2014 10:37 pm
by peteben
Although I was pretty excited after I first got a program to compile on my ESP-01, I quickly became tired of the gymnastics of editing, compiling, flashing, running, changing the jumpers, etc.. I guess I was spoiled with the Arduino environment, and Visual Micro.
So I figured, if they can do it, I can too. And I did, and now you can too. Here is how.

There are several aspects to this setup.

  • Hardware
    I essentially used the Arduino trick of connecting RESET to DTR with a capacitor. This causes the chip to reset when DTR goes low. I also connected DTR to GPIO0 with a diode. Thus, setting DTR low for abour 15ms resets the chip and causes it to go into bootloader mode. I also added 10k pullups to the RESET, GPIO0, GPIO2, CH_PD lines. I have included a schematic.
  • Esptool
    I have used mamalala's makefiles and ESPTOOL.exe to generate the firmware files, even though I use a different esptool to upload. You can find this tool here: viewtopic.php?f=9&t=142. I installed esptool in E:\Espressif\esptool.
    I suspect that the makefiles could be modified to use the Python esptool-py to create the firmware image, but I have not done so.
  • Flasher
    I modified the esptool-py Python script to activate DTR in order to reset the chip into bootloader mode. Pulling DTR low causes the chip to reset, and about 15ms later it looks as if the chip samples GIO0 to determine if it should go into bootloader mode. With DTR and GPIO0 still low, it goes into bootloader mode and turns GPIO0 back into an output, so DTR is pulled back up again. Another change has been made to the flasher app, it uses a named pipe to comunicate with the serial terminal app, in order to get control of the com port. After the flashing is done, control of the com port is returned back to the terminal. This was my first dabbling in Python, so feel free to make changes.
  • Serial Terminal
    I'm lazy, so I went hunting for simple app I could hack. I found it on http://termie.sourceforge.net/. It's a basic serial terminal, written in C#. The source code was clean and easy to modify. I added a new thread that creates and monitors the named pipe that the flasher will talk to. When it receives a request, the terminal just closes the com port until it receives another command to reopen the port.
  • Visual Studio
    With the free Visual Studio 2013 community edition, there is really no reason to be using anything else. You can easily add makefile projects to Visual Studio. You still need to have makefiles :( , but now you no longer need to leave the IDE. You can just select 'build' and the code will compile, then flash, reboot without you having to do anything else.

The files:
ESPAdapter.pdf

Termie.zip

esptool-py.zip




How to setup:

  • First, make sure you have a working makefile that allows you to build and flash.
  • Then, substitute the modified esptool-py.py. Things should still work.
  • Modify your hookup to add the diode, the capacitor, the pullups and the connection to DTR. This should allow you to flash without setting any jumpers.
  • Install Visual Studio 2013 and compile the C# terminal.
  • Use the terminal. It works like just about every other terminal, except this one will get out of the way when you want to flash.
  • Add your project to Visual Studio. Select 'New/Project/Other languages/C++/Makefile project. About the only thing you need to worry about is the actual make command (typically: 'make all flash'). Now everytime you select 'build project', things should happen automatically.

All of this should of course be considered beta. I think the terminal needs a bit more work, especially to handle errors. Eventually it would be nice to get better integration into Visual Studio. I think it may be possible to use Visual Micro for that. They already do it for the Arduino and Chipkit (PIC32) variants of gcc, so it should be possible to add a similar toolset.

Have fun.

Pete

Re: New Windows terminal/flasher apps & Visual Studio

PostPosted: Thu Dec 18, 2014 3:42 am
by uhrheber
peteben wrote:With the free Visual Studio 2013 community edition, there is really no reason to be using anything else.


Except the fact that Visual Studio alone eats up half of the disk space of my old notebook, the only Windows computer I have left.
I think that Visual Studio is overkill, unless you already have it installed. I prefer Code::Blocks.

But nevertheless, great work, and many thanks for your tutorial.
This should work with any IDE that can import makefile projects.

Cheers
Uhrheber

Re: New Windows terminal/flasher apps & Visual Studio

PostPosted: Thu Dec 18, 2014 2:12 pm
by MarekB
Hi Pete,

if you get some time, could you please elaborate on how did you set up the toolchain on windows? There are some information here and there, but I could not find one complete description on how to set things up on Windows (using latest 0.9.3 SDK and without cygwin). Or if there is already something like that, please post a link. Thanks a lot.

Re: New Windows terminal/flasher apps & Visual Studio

PostPosted: Thu Dec 18, 2014 5:43 pm
by peteben
@uhrheber: You're right of course. You can use whatever editor you want. If it helps, I can provide a compiled binary for the terminal app.

@MarekB: Ok. Here is the way I got it working. YMMV.
  • Create a directory to put all your ESP stuff in. I put mine in E:\Projects\Espressif, but obviously yours will be different.
  • Get Python 2.7. Install it where you want. I put it in C:\Python27.
  • You need PySerial (http://pyserial.sourceforge.net/).
  • Get minGW (http://www.mingw.org/). In the package manager, choose mingw-developer-toolkit and mingw-base. This will give you make.exe and some important utilities, like mkdir.exe that the makefiles will need.
  • Get the sdk (http://bbs.espressif.com/viewtopic.php?f=5&t=53). Install it under your chosen directory. Mine is in E:\Projects\Espressif\esp_iot_sdk_v0.9.3
  • Get the pre-built compiler. Pick it up from this page: http://signusx.com/esp8266-windows-compilation-tutorial/. Scroll down a bit you will find a link to the compiler on Google drive. I used the Nov 20 version. Stick it in your chosen directory. Mine is in E:\Projects\Espressif\xtensa-lx106-elf.
  • Get the source code examples from the wiki: https://github.com/esp8266/source-code-examples. Install them in a directory under your chosen project directory. Mine are in E:\Projects\Espressif\source-code-examples-master.
  • Now you need to correctly setup your path. You can of course add things to your global user path, but I like to setup a separate command prompt for things like this. I created a file called Vars.cmd, that sets up the path for working with the ESP toolset:
    Code: Select all@echo off
    PATH=%PATH%;E:\projects\Espressif\xtensa-lx106-elf\bin;E:\MinGW\bin;E:\MinGW\msys\1.0\bin
  • Then I setup a shortcut for a command prompt:%comspec% /k E:\projects\Espressif\VARS.cmd. When I click this I get a command prompt with the proper path already set.
  • For the same reason, I also created a batch file that sets up the path before calling make:
    Code: Select all@echo off
    call e:\projects\espressif\vars.cmd
    make %1 %2 %3 %4 %5
  • So in my project setup, in Visual Studio, I use ESPMAKE instead of make.
  • Check out my Makefile for the Blinky project .
    Makefile.zip
  • Modify the makefile so that it reflects your locations for the tools and sdk. You should be able to compile and flash.
  • Things to watch out for. You need to be careful in your usage of library functions. Use the supplied alternatives like 'os_printf'. If you don't, you may bring in a whole bunch of code from the standard libraries, which won't work. By default, all the library code goes into iram, which is only 32k, so it is easy to overflow that segment by linking in a bunch of stuff from the libraries. Use ICACHE_FLASH_ATTR on your functions to make sure they go into irom instead.
That's about as simple as I can put it. I may be forgetting something, as I messed around for a bit before getting this setup working, but I hope this will set you and other down the right path.

Pete

P.S. I have already made some changes to esptool-py. I will upload them later. Still in learning mode with Python! To be continued.