ESP32: get acquainted, write and launch the first firmware
- From the sandbox
- Tutorial
Hello. A few days ago I got a copy of the ESP32 Demo Board V2, which I immediately joyfully announced at my FB. Of course, getting it now is not very easy: the first batch (600 pieces), which went on sale at Seeed Studio, flew apart in a matter of hours!

But as a developer and hardware integrator of the Open-Source library for Blynk, I often get early access to various devices. Blynk allows you to quickly prototype and build iOS / Android Apps for the Internet of things using drag'n'drop blocks directly on your phone.
The board that fell into my hands looks like this:

ESP32 promises to revolutionize the IoT world again , as its younger brother ESP8266 did in due time (and I sincerely hope that it will). If you have not heard anything about ESP8266 before - read, for example, here and here (well, Google).
What is the new ESP32? Even at first glance it is clear that this is a very powerful platform. For example, Ivan Grokhotkov (developer of Arduino support for ESP8266) published a photo of the DOOM game on ESP32:
CPU: Xtensa Dual-Core 32-bit LX6, 160 MHz or 240 MHz (up to 600 DMIPS)
Memory: 520 KByte SRAM, 448 KByte ROM
Flash on the module: 1, 2, 4 ... 64 MB
Wireless:
Peripheral interfaces:
Security:
In the picture it looks like this:

More detailed (and almost complete) information is on off. Espressif Systems website . ESP32 will be available (at least) in several forms:
» ESP-WROOM-32 module ($ 5?)

Pinout | Datasheet
» AI-Thinker ESP3212 module , similar to the ESP-12F ($ 6.9). There are no SD-card legs on the ESP3212, unlike the WROOM-32.


Eagle Library | KiCAD Library
Chip ESP32-D0WDQ6 ($ 2.8?) | Datasheet

It is worth noting that before the release of ESP32, ESP31B (test version) was available in the form of the Espressif ESP-WROOM-03 module, and on the Internet it is often confused with ESP32.
Caution! Almost all references to ESP32 before 09.2016 are actually about ESP31B, which is not the same at all.
On the offsite you can now find links to two SDKs:
» ESP31_RTOS_SDK - SDK for ESP31B, built on FreeRTOS.
» Espressif IDF (IoT Development Framework) - Official development framework for ESP32.
Although this is not obvious from the description on the site, only the ESP-IDF is suitable for the release version . There are installation instructions for linux , windows , macos .
I have 64-bit Ubuntu Linux. First downloaded the compiler:
A folder should appear
A folder should appear
Espressif has prepared a template project for us, so starting is very simple:
You can try to run a pure template, but it seemed uninteresting to me. I just finished writing
To build a project, you first need to configure the environment:
Now we connect the board, turn on the power, and look at which port it appeared on (I have / dev / ttyUSB3). Launch the configurator:

You need to go into the “Serial flasher config” and install the “Default serial port” on the board port. You can also see other settings.
All save and exit.
We compile:
If all is well, fill in the board:
We connect to the board using Putty (screen, or another terminal emulator). We distort food, and we see:
If you connect the LED to
Another good news is that the ESP32 has a JTAG footed interface
Well, you just have to wait for the availability of ESP32 in stores, stabilization of the SDK (I hope it will be much more stable from the beginning than the ESP8266). The Bluetooth function is also not yet available. Soon (according to my data, very soon) beta support for Arduino IDE and MicroPython should appear , then Espruino and something similar to NodeMCU.
What do you think?

But as a developer and hardware integrator of the Open-Source library for Blynk, I often get early access to various devices. Blynk allows you to quickly prototype and build iOS / Android Apps for the Internet of things using drag'n'drop blocks directly on your phone.
The board that fell into my hands looks like this:

ESP32 promises to revolutionize the IoT world again , as its younger brother ESP8266 did in due time (and I sincerely hope that it will). If you have not heard anything about ESP8266 before - read, for example, here and here (well, Google).
What is the new ESP32? Even at first glance it is clear that this is a very powerful platform. For example, Ivan Grokhotkov (developer of Arduino support for ESP8266) published a photo of the DOOM game on ESP32:
ESP32 Features
CPU: Xtensa Dual-Core 32-bit LX6, 160 MHz or 240 MHz (up to 600 DMIPS)
Memory: 520 KByte SRAM, 448 KByte ROM
Flash on the module: 1, 2, 4 ... 64 MB
Wireless:
- Wi-Fi: 802.11b / g / n / e / i, up to 150 Mbps with HT40
- Bluetooth: v4.2 BR / EDR and BLE
Peripheral interfaces:
- 12-bit SAR ADC up to 18 channels
- 2 × 8-bit DAC
- 10 × touch sensors
- Temperature sensor
- 4 × SPI
- 2 × I²S
- 2 × I²C
- 3 × UART
- 1 host (SD / eMMC / SDIO)
- 1 slave (SDIO / SPI)
- Ethernet MAC with DMA and IEEE 1588 Support
- CAN 2.0
- IR (TX / RX)
- Motor pwm
- LED PWM up to 16 channels
- Hall sensor
- Ultra low power analog pre-amplifier
Security:
- IEEE 802.11 security WFA, WPA / WPA2 and WAPI
- Secure boot
- Flash encryption
- 1024-bit OTP, including up to 768-bit for the task
- Cryptographic engine: AES, SHA-2, RSA, ECC, RNG
In the picture it looks like this:

More detailed (and almost complete) information is on off. Espressif Systems website . ESP32 will be available (at least) in several forms:
» ESP-WROOM-32 module ($ 5?)

Pinout | Datasheet
» AI-Thinker ESP3212 module , similar to the ESP-12F ($ 6.9). There are no SD-card legs on the ESP3212, unlike the WROOM-32.


Eagle Library | KiCAD Library
Chip ESP32-D0WDQ6 ($ 2.8?) | Datasheet

- D : Dual-core
- 0 : No internal flash
- W : Wi-Fi
- D : Dual-mode Bluetooth
- Q : Quad Flat No-leads (QFN) package
- 6 : 6 mm × 6 mm package body size
It is worth noting that before the release of ESP32, ESP31B (test version) was available in the form of the Espressif ESP-WROOM-03 module, and on the Internet it is often confused with ESP32.
Caution! Almost all references to ESP32 before 09.2016 are actually about ESP31B, which is not the same at all.
Setting up a development environment
On the offsite you can now find links to two SDKs:
» ESP31_RTOS_SDK - SDK for ESP31B, built on FreeRTOS.
» Espressif IDF (IoT Development Framework) - Official development framework for ESP32.
Although this is not obvious from the description on the site, only the ESP-IDF is suitable for the release version . There are installation instructions for linux , windows , macos .
I have 64-bit Ubuntu Linux. First downloaded the compiler:
sudo mkdir /opt/Espressif
sudo chmod a+rw /opt/Espressif
cd /opt/Espressif
wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-59.tar.gz
tar -xzf xtensa-esp32-elf-linux64-1.22.0-59.tar.gz
A folder should appear
xtensa-esp32-elf
. Then I downloaded esp-idf (in the same folder /opt/Espressif
):git clone --recursive https://github.com/espressif/esp-idf.git
A folder should appear
esp-idf
.Writing Hello World
Espressif has prepared a template project for us, so starting is very simple:
cd ~
git clone https://github.com/espressif/esp-idf-template.git myapp
cd myapp
You can try to run a pure template, but it seemed uninteresting to me. I just finished writing
main/app_main.c
to blink the LED. Here's what happened.main / app_main.c
#include<stdio.h>#include"rom/gpio.h"#include"esp_system.h"#include"freertos/FreeRTOS.h"#include"freertos/task.h"#define LED_PIN 18#define LOG(msg, ...) printf("[%u] " msg "\n", system_get_time(), ##__VA_ARGS__)voidpingTask(void *pvParameters){
while (1) {
GPIO_OUTPUT_SET(LED_PIN, 0);
LOG("low");
vTaskDelay(1000 / portTICK_PERIOD_MS);
GPIO_OUTPUT_SET(LED_PIN, 1);
LOG("high");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
voidapp_main(){
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
}
We collect and fill on the board
To build a project, you first need to configure the environment:
cd ~/myapp
export PATH=/opt/Espressif/xtensa-esp32-elf/bin:$PATHexport IDF_PATH=/opt/Espressif/esp-idf
Now we connect the board, turn on the power, and look at which port it appeared on (I have / dev / ttyUSB3). Launch the configurator:
make menuconfig

You need to go into the “Serial flasher config” and install the “Default serial port” on the board port. You can also see other settings.
All save and exit.
We compile:
make
If all is well, fill in the board:
make flash
Something like this should appear ...
Flashing project app to 0x10000...
esptool.py v2.0-dev
Connecting...
Changing baud rate to 921600
Changed.
********************************
IS HSPI: 0x00000000 <type'int'>
--------------------------
IS LEGACY: 0x00 <type'int'>
*********************************
SENDING SPI ATTACH COMMAND
--------------
SEND ESP SPI ATTACH CMD
START DOWNLOADING...
Erasing flash...
Unc size 6656 comp size 3900 comp blocks 4
Took 0.09s to erase flash block
Wrote 3900 bytes at 0x00001000 in 0.2 seconds (194.1 kbit/s)...
Hash of data verified.
Erasing flash...
Unc size 378208 comp size 210815 comp blocks 206
Took 1.99s to erase flash block
Wrote 210815 bytes at 0x00010000 in 4.6 seconds (366.2 kbit/s)...
Hash of data verified.
Erasing flash...
Unc size 96 comp size 57 comp blocks 1
Took 0.04s to erase flash block
Wrote 57 bytes at 0x00004000 in 0.1 seconds (5.0 kbit/s)...
Hash of data verified.
Leaving...
We connect to the board using Putty (screen, or another terminal emulator). We distort food, and we see:
Initial initialization
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:QIO, clock div:2
load:0x3ffc0000,len:0load:0x3ffc0000,len:2268load:0x40078000,len:3788load:0x40098000,len:532
entry 0x4009813c
**************************************
* hello espressif ESP32! *
* 2nd boot is running! *
* version (V0.1) *
**************************************
compile time18:10:20
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size : 4MB
PartitionTable:
## Label Usage Type ST Offset Length0 factory factory app 000000010000001000001 rfdata RF data010100110000000400002 wifidata WiFi data01020015000000040000Endofpartitiontable
Loading app partitionatoffset00010000section0: paddr=0x00000020 vaddr=0x00000000size=0x0ffe8 ( 65512)
section1: paddr=0x00010010 vaddr=0x3f400010size=0x086fc ( 34556) mapsection2: paddr=0x00018714 vaddr=0x3ffba950size=0x01248 ( 4680) loadsection3: paddr=0x00019964 vaddr=0x40080000size=0x00400 ( 1024) loadsection4: paddr=0x00019d6c vaddr=0x40080400size=0x1326c ( 78444) loadsection5: paddr=0x0002cfe0 vaddr=0x00000000size=0x03030 ( 12336)
section6: paddr=0x00030018 vaddr=0x400d0018size=0x2c540 (181568) mapstart: 0x4008078c
Initializing heap allocator:
Region 19: 3FFBBB98 len00024468 tag 0
Region 25: 3FFE8000 len00018000 tag 1
Pro cpu up.
Pro cpu startuser code
nvs_flash_init
misc_nvs_load g_misc_nvs=0x3ffbbd04
frc2_timer_task_hdl:3ffbc880, prio:22, stack:2048
tcpip_task_hdlxxx : 3ffbe62c, prio:20,stack:2048
phy_version: 80, Aug 262016, 13:04:06, 0
pp_task_hdl : 3ffc3360, prio:23, stack:8192
[213450] low
[1212827] high
[2212827] low
[3212828] high
[4212828] low
If you connect the LED to
IO18
, it also flashes. So our code works!Debugging
Another good news is that the ESP32 has a JTAG footed interface
IO12, IO13, IO14, IO15
. I will try to use it to debug programs. But more on that in the next article. Well, you just have to wait for the availability of ESP32 in stores, stabilization of the SDK (I hope it will be much more stable from the beginning than the ESP8266). The Bluetooth function is also not yet available. Soon (according to my data, very soon) beta support for Arduino IDE and MicroPython should appear , then Espruino and something similar to NodeMCU.
What do you think?