So as I hinted from my last post. I have decided to delve right into the world of professional software development. I have started using “Eclipse” as my development platform for my IoT chip – ESP32 by Sparkfun.
To be fair, I didn’t really have a choice. Not all of the features that I need this chip to do have been ported over into the “Arduino” platform yet. I’m sure it eventually will (possibly more than a year, as seen on the prior chip). So, I’m pulling up my big boy pants and learning all the things!
I will be keeping my software open-source. But it will be via the official ESP-IDF. Once I program for this (in C language) I won’t be porting it back into Arduino (Sorry arduino fans).
I thought It could be useful for others who are in the same boat to have some of my frustrations and solutions recorded for all to search. Oh what a time to be alive!
To be clear, this is the Windows version of the setup. If you use Linux or Apple … keep googling. Also, I know there is an official guide found here: http://esp-idf.readthedocs.io/en/latest/index.html … It’s the first thing I tried … but It didn’t work for me … there were a few small things missing (subtle things that a newb like me just didn’t catch).
- First things first, You’ll need to download the Eclipse IDE for C/C++ Developers
- Second, You’ll need the MSYS2 (toolchain setup). Download it from the official ESP-IDF how-to site
- Here’s where I recommend not using the ESP-IDF official instructions. A post similar to mine was started on Jan 2017 by michal037 … the post can be found here: https://github.com/espressif/esp-idf/issues/200. The best part is actually running the code he posts at the top. Section 1 right after step 2 … this code actually will run for a long while. It updates and sets up all the things! … I actually don’t know what it does … but nothing worked until I ran that. You can skip the rest of his post. It just goes into detail, but I skipped it. (Note that this part downloads your IDF, which stands for IoT Development Framework (the cooler version of SDK) … so you may want to setup a GitHub connection to this to keep it updated … if you don’t know what I just said … don’t worry. Skip it for now.
- Last thing you’ll need is a Serial Reading program. Putty is what I used. (click “Serial”, select the Com port you have your ESP32 plugged in (check “device manager” in your windows control panel. Should be under “Ports (COM & LPT)”)
Now you should be set to test the “Terminal” method of flashing a program. Note that you actually have to test this. You can’t just skip this part and think that you can use “Eclipse” right out of the box. Eclipse has some missing configurations that need to be run from the “Terminal”. When I say terminal, I mean the MSYS2 toolchain program. Go ahead an open up the “msys2_shell.cmd” file under the “C:\msys32” location that it was installed (as was recommended).
It runs on BASH. A quick Google search tells me that this stands for Borne Again SHell … And to be fair, if any of you have used a Command line interface (CMD typed in your run box) … it’s quite similar.
navigate to your example (should be here, note the other examples you can use too) “C:\msys32\home\esp-idf\examples\get-started\hello_world”. You can just paste and execute the code below:
*Notice the backward slashes … ya. BASH is a little backwards … remember that. Also note that I’m not making a copy into my own directory … if you update the IDF, your changes will be overwritten!!! you’ve been warned. But to keep it simple, lets just go with it.
now lets setup the menuconfig:
you should see something like this. Navigate to “Serial flasher config —>” enter, then enter on the first item “(/dev/ttyUSB0) Default serial port” … this is where you configure your connected ESP32 device. I found mine under COM4 (your may be different, check your device manager).
The part that I had trouble finding is understanding the difference between COM ports and the Linux equivalent (/DEV/tty). Here is what made me understand it a little more. if your in windows under device manager plugging and unplugging your device shows you which one it is (it’ll appear and disappear). The equivalent of this under your BASH interface is this:
ls stands for list in a “linux” environment … and /dev is where all of your “devices” live … So typing this at the shell while plugged and again while unplugged will show you exactly what you device is named in this environment. It turns out it’s typically the COM# in windows is equivalent to the /dev/ttyS(#-1) in Linux … note that the (#-1) is litterally number minus one. So COM4 = dev/ttyS3 and so on.
This is the only change you need to make to the menuconfig. You can Save and exit now. After you exit, you can check in the directory a new file called sdkconfig.old will have appeared. The program saved the “old” configuration and superseded it with a new “sdkconfig” file. This is part of your build files that will be used to flash your ESP32.
Now, you have done everything necessary. All that is left is to flash. Go back to your program directory (you may already be here if you just exited the menuconfig:
Now all you have to do is type:
and your chip will be flashed with some new software. This is the biggest hurdle. You can actually listen to your chip now using the Putty program.
Now setting up your Eclipse environment. I tried a few different ones from different people around the web … quite a few of them are really bad. Possibly a language barrier or something …
This is the best one I found: http://www.lucadentella.it/en/2016/12/15/esp32-3-eclipse/ this one was the clearest that I could follow. Finish that setup and then come back here.
A note about the “unresolved inclusion” … basically your #include headers, they aren’t being found by eclipse … which is a known bug. but you can fix that manually by finding any “xxxxx.h” file under the ESP-IDF and just including the path in the “C/C++ General – Paths and Symbols – GNU C” location as noted.
Now you may still have an issue with Symbol ‘CONFIG_FREERTOS_HZ’ … I tried adding #include “sdkconfig.h” at the beginning of the main.c file … I tried adding //build/include to the Paths & Symbols at the top … We’ll I can tell you the error eventually went away. But not right away … so I can’t tell what made it go away. All I can say is that it actually doesn’t prevent you from flashing your chip.
After you make your build targets and make a “flash” one. running the flash build target will actually flash your chip. Don’t be fooled by the “Problems tab” that probably shows your CONFIG_FREERTOS_HZ error. Click on a couple tabs over to the “Console” tab. This will show your flash progress and eventually end with “Hard resetting…” which is your que to jump up and say “fuck-ya! I’m good” … that’s right. You did a thing. And, that was a pretty hard thing. Good job dude!
Now go out there and make a custom program!