Tutorial: Using ESP-IDF to flash the ESP32 Thing

Victory! I’ve managed to upload code onto the Sparkfun ESP32 Thing using ESP-IDF. This means that (hopefully) I will be able to make full use of the chip’s capabilities, including (dare I say it?) BLE.

IMG_1337.JPG

For now, I’ll stick with “Hello world!” and LED blinking, though. The Thing has a lovely blue LED on pin 5 that is very useful for testing code and, coincidentally, Espressif provides a Blink example. Perfect!

The process of uploading the code to the ESP32 was a bit difficult for me, either because of a lack of experience or because it is actually difficult. In any case, I wanted to describe the steps I took to flash the ESP32 in case anyone else is having trouble with it.

1. Make sure ESP-IDF is set up.

Make sure that ESP-IDF is set up properly according to the steps on Espressif’s Github page. You don’t need to have Eclipse set up for this – all you need is the msys2 environment and the SDK.

2. Open msys2 and set it up.

Open up the msys2 command shell that came with the ESP-IDF installation (should be found at C:\msys32). First, we need to set the environment variable for the location of the IDF folder. Use this command:

export IDF_PATH="C:/path/to/IDF/folder/esp-idf"

There’s a way to make this run every time msys2 opens, but I haven’t figured it out yet. Next, use cd to move to the directory where your project is (not the IDF folder). For this example, I’m using Espressif’s Blink example project, with a “Hello world!” added in.

3. Configure the project.

Next, use this command:

make menuconfig

This will open a configuration screen that looks like this:

menuconfig

You can change a lot of stuff in here, but we only need to change one thing: the serial port. Navigate to Serial flasher config -> Default serial port. It will be set to /dev/ttyusb0/ or something like that – whatever it is, it doesn’t work. Delete that setting and enter the correct COM port. My ESP32 Thing showed up on COM3.

comport

Press Ok and exit the config using [ESC] [ESC].

4. Building and flashing.

Use make to build the project. The first time you do this, it will take a while. Next, plug in the ESP32 Thing and put it into bootloading mode (press button 0 and then reset, then unpress reset and then unpress button 0). Use this command to start the flashing process:

make app-flash

Do not use make flash – this tells the IDF to flash the bootloader, partition table, and application. Since we already have so much on board with the ESP32 Thing, all we need to flash is the app; this is what make app-flash does.

If everything works, this is what you’ll see:

flash.png

And just like that, we have blinking LEDs!

Since I added a “Hello world!” to the code, the ESP32 also says hello with every LED blink. To view any data that is being logged, use make monitor to create a nice serial output window.

This is a fairly unimpressive test of the ESP32, but hey, one step at a time. Next, I’ll be experimenting with connecting to wifi, hosting a wifi server, and maybe even BLE. Just maybe.

That’s all for now!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s