avatarJ3

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4620

Abstract

& <span class="hljs-keyword">b) </span><span class="hljs-keyword">boot </span>app = launcher; . components = modular pieces linked into app; . target = hadware = ESP32; . IDF_PATH = link ESP-IDF project; . Toolchain = for compilation - <span class="hljs-keyword">should </span><span class="hljs-keyword">be </span>on the PATH;</pre></div><p id="4778"><i>Annotation about The <b>CMake-based build system</b>:</i></p><div id="efcf"><pre>There are 2 main <span class="hljs-keyword">build</span> Tools: CMake + Ninja <span class="hljs-keyword">to</span> <span class="hljs-keyword">build</span> a full Application <span class="hljs-keyword">for</span> ESP32 (this post) <span class="hljs-keyword">or</span> GNU Make <span class="hljs-keyword">build</span> <span class="hljs-keyword">system</span> (other post);</pre></div><div id="35ca"><pre>For CMake build system: . The CMake-based build system <span class="hljs-keyword">is</span> a <span class="hljs-keyword">front</span>-<span class="hljs-keyword">end</span> command line tool; . What <span class="hljs-keyword">is</span> idf.py ? idf.py <span class="hljs-keyword">is</span> a top-level config/build command line tool <span class="hljs-keyword">for</span> ESP-IDF; . It easily managing your project builds; . esptool.py = Flasher; . idf.py <span class="hljs-keyword">is</span> a wrapper <span class="hljs-keyword">around</span> CMake <span class="hljs-keyword">for</span> programmer convinience; . idf.py Commands: idf.py menuconfig = <span class="hljs-keyword">to</span> config <span class="hljs-keyword">the</span> app; idf.py build = multiple steps build process; <span class="hljs-keyword">it</span> creaes sub-directories; <span class="hljs-built_in">run</span> Ninja <span class="hljs-keyword">or</span> GNU Make; Building <span class="hljs-keyword">is</span> incremental (no-change; nothing done) idf.py clean = delating build output files except config files; idf.py fullclean = delete build directory recursively; idf.py flash -p PORT -b BAUD RATE = <span class="hljs-keyword">it</span> flashes prog <span class="hljs-keyword">onto</span> chip; idf.py monitor -p PORT -b BAUD RATE = Serial output; . You can combine commands, like this: idf.py -p COM4 flash monitor; . The order <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> important (<span class="hljs-keyword">it</span> automatically will be executed <span class="hljs-keyword">in</span> <span class="hljs-keyword">the</span> correct order); . Python interpreter - ESP-IDF works <span class="hljs-keyword">with</span> Python <span class="hljs-number">2.7</span> <span class="hljs-keyword">or</span> <span class="hljs-number">3.8</span>;</pre></div><p id="a7bb">Here is the layout that the <a href="https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/windows-setup.html#esp-idf-tools-installer">ESP-IDF Tools Installer</a> makes in my machine:</p><figure id="cc61"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*1L-qyzI7WfXVvlYHQdPyJw.png"><figcaption>Fig 3. ESP-IDF official layout 4 Win10:)</figcaption></figure><p id="9ff0">Here is an Espressif recommended <b>ESP-IDF project layout directory </b>(for my custom project I put it inside the Directory <b><i>Examples</i> </b>above and worked fine):</p><figure id="3a1a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*hc2tLAqBa56Yl_iwpLJuzw.png"><figcaption>Fig 4. A project layout simplified for your reference</figcaption></figure><h1 id="45cc">Setup Path to ESP-IDF</h1><div id="031b"><pre>IDF_PATH = C:\Users<span class="hljs-meta">%</span>userprofile<span class="hljs-meta">%</span>\Desktop\esp-idf</pre></div><div id="3bdd"><pre><span class="hljs-attribute">IDF_PYTHON_ENV_PATH</span> = C:\Users%userprofile%.espressif\python_env\idf3.<span class="hljs-number">3</span>_py3.<span class="hljs-number">8</span>_env</pre></div><div id="a5b4"><pre>IDF_TOOLS_PATH = C:\Users<span class="hljs-meta">%</span>userprofile<span class="hljs-meta">%</span>.espressif</pre></div><p id="65b2">Fine, now let’s code o/</p><p id="4ac6">The first example that I will review is the <b>blink </b>project.</p><p id="be88">You can find it at this location: <i>C:\Users</i>%userprofile%<i>\Desktop\esp-idf\examples\get-started\blink</i>.</p><p id="8eac">Here is the <i>blink.c</i> code at <i>\main</i> sub-directory:</p> <figure id="9cd7"> <div> <div>

            <iframe class="gist-iframe" src="/gist/giljr/a4085b4aaa07484511d295362d9e00b6.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">

Options

        </div>
        </div>
    </figure></iframe></div></div></figure><h2 id="a623">1.Menu Configuration</h2><p id="0613">Let’s connect our device to a USB port.</p><p id="b2a2">Go to Device Manager and find the port that your ESP device is attached:</p><figure id="0a75"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*eDM6H0356ODZfMTihXTVFg.png"><figcaption>Fig 5. Mine is <b>COM10</b> — If you have problems with USB Driver, please refer to this <a href="https://readmedium.com/esp-idf-programming-guide-wifi-lora-32-v2-53f89e12c96e">post </a>(Troubleshooting — Driver Bridge section)</figcaption></figure><p id="8bc8">Go to<i> <b>ESP-IDF commands prompt (cmd.exe)</b>:</i></p><figure id="e2b5"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*w_I33WtHU9fnw6pjP5n18g.png"><figcaption>Fig 6. Execute the ESP-IDF prompter</figcaption></figure><p id="dd0a">Now go to directory <i>C:\Users\</i>%userprofile%<i>\Desktop\esp-idf\examples\get-started\blink</i> and type:</p><div id="b5fd"><pre>idf<span class="hljs-selector-class">.py</span> menuconfig</pre></div><figure id="faa3"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*fyMOl5T4uPQWotHKpr-tvQ.png"><figcaption>Fig 7. The first thing to do is to check what GPIO pin is the output — Go to Example Configuration and …</figcaption></figure><figure id="da5f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*PbmcUjrXWk--xxYh4Ye-tQ.png"><figcaption>Fig 8. Choose <b>GPIO25</b> as output — This is the built-in LED for my first board — Then <b>Save</b> and <b>Exit</b>, and you are good to go o/</figcaption></figure><div id="31f7"><pre><span class="hljs-built_in">Type</span> <span class="hljs-keyword">cls</span> to <span class="hljs-keyword">clear</span> the <span class="hljs-keyword">screen</span>.</pre></div><h2 id="52bf">2.Building</h2><p id="cb88">Type:</p><div id="6dff"><pre>idf.py <span class="hljs-keyword">build</span></pre></div><p id="4c7e">This process will take a long time. Please, take a coffee and relax! ☕</p><h2 id="ac9e">3.Flashing firmware onto an ESP32 board at \main sub-directory:</h2><p id="828f">When it finishes type:</p><div id="5b3b"><pre>idf<span class="hljs-selector-class">.py</span> -<span class="hljs-selector-tag">p</span> &lt;PORT_NUMBER&gt; flash monitor</pre></div><figure id="7c19"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*XVSiPKLT-JIycHh2cN9eZg.png"><figcaption>Fig 9. Running blink at the monitor.</figcaption></figure><figure id="f87b"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*-sJi0AuNPUWHHbHPt8ZLcA.gif"><figcaption>Gig 1. The built-in LED flashes @ 1s interval \o/</figcaption></figure><p id="737f">That’s all for now!</p><p id="b96f">In the next episode we won't be shy, let’s get some more stamina, right?</p><p id="6141">Thank you!</p><p id="0cf5"><a href="https://drive.google.com/drive/folders/13YVCv25xzIQdOgt00mhdwd-FWay4GsfX?usp=sharing">Download All Files For This Project</a></p><h2 id="8cb2">Credits &amp; References</h2><p id="6cf4"><a href="https://docs.espressif.com/projects/esp-idf/en/v3.3/api-guides/build-system-cmake.html">https://docs.espressif.com/projects/esp-idf/en/v3.3/api-guides/build-system-cmake.html</a></p><p id="32c4"><a href="https://cmake.org/cmake/help/latest/guide/tutorial/index.html#cmake-tutorial">CMake Tutorial — CMake 3.17.3 Documentation</a></p><p id="8b5a"><a href="https://cmake.org/cmake/help/latest/guide/tutorial/index.html#cmake-tutorial">The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address…</a></p><p id="c5cf"><a href="https://cmake.org/cmake/help/latest/guide/tutorial/index.html#cmake-tutorial">cmake.org</a></p><h1 id="e7ae">Related Post</h1><p id="18a9">00#Episode — ESP_IDF_Series — <a href="https://readmedium.com/esp-idf-programming-guide-wifi-lora-32-v2-53f89e12c96e">ESP-IDF Programming Guide + WiFi LoRa 32 (v2)</a> — How To Get Started</p><p id="5ea9">01#Episode — ESP_IDF_Series — <a href="https://readmedium.com/lora-lpwan-long-range-low-power-wide-area-network-65cfa264d7c6">LoRa LPWAN — Long Range Low Power Wide Area Network</a> — LoRa was developed by Semtech, founder LoRa Alliance</p><p id="db51">02#Episode — ESP_IDF_Series — <a href="https://readmedium.com/esp-idf-programming-guide-wifi-lora-32-v2-idf-py-utility-339b8371bb8f">ESP-IDF Programming Guide + WiFi LoRa 32 (v2) + idf.py utility — How To Really Get Started</a></p><p id="3f81">03#Episode — ESP_IDF_Series — ESP32-IDF — HelloWorld Get Started — How To Get Started (this one:)</p></article></body>

ESP32-IDF —HelloWorld Get Started

How To Get Started — ESP_IDF_Series Episode #03

This post will review the code example published by Espressif located at directory <IDF_PATH>\examples\get-started\blink of ESP-IDF installation.

It follows the CMake build system software environment for the hardware-based on the ESP32 chip produced by Expressif.

For official tutorial, please head over to:
(the stable version as of June 2020): 
https://docs.espressif.com/projects/esp-idf/en/stable/)

For Installation of ESP-IDF (Expressif IoT Development Framework) on Windows 10 using the CMake-based build system please take a look at this other post.

These are the steps for an ESP-IDF project:

ESP-IDF
Menu Configuration
Building
Flashing firmware onto an ESP32 board

Let me show you what I have in my atelier:)

Fig 1. WiFi LoRa 32 (v2) is a classic IoT dev-board designed & produced by Heltec Automation(TM), it’s a highly integrated product based on ESP32 + SX127x, it has Wi-Fi, BLE, LoRa functions, also Li-Po battery management system, 0.96″ OLED are also included. It’s my choice :)
Fig 2. 24M Byte (32M bit )Pro ESP32 OLED V2.0 TTGO & For Arduino ESP32 OLED WiFi Modules+Bluetooth Double ESP-32 ESP8266 OLED from AliExpress.com

Material Needed

ESP32 kit board
High quality Type B-Micro USB Cable

The ESP-IDF is an amalgamation of a number of components:

1.ESP32 base library;
2.WiFi Drivers;
3.TCP/IP stack;
4.FreeRTOS stack;
5.Webserver;
6.Driver for sensor(s);
7.Main code tying it all together

Follows some concepts and jargons about ESP-IDF:

. ESP-IDF makes these components explicit & configurable;
. To config project use text-based new system (customizable);
. After config, the build system will compile the project;
. The app is inside a directory with all the support files;
. You can modify project config (sdkconfig file) by typing idf.py menuconfig at prompt;
. 1 project builds 2 apps: a) proj app = exe & b) boot app = launcher;
. components = modular pieces linked into app;
. target = hadware = ESP32;
. IDF_PATH = link ESP-IDF project;
. Toolchain = for compilation - should be on the PATH;

Annotation about The CMake-based build system:

There are 2 main build Tools: CMake + Ninja to build a full Application for ESP32 (this post) or GNU Make build system (other post);
For CMake build system:
. The CMake-based build system is a front-end command line tool;
. What is idf.py ? idf.py is a top-level config/build command line tool for ESP-IDF;
. It easily managing your project builds;
. esptool.py = Flasher;
. idf.py is a wrapper around CMake for programmer convinience;
. idf.py Commands: 
idf.py menuconfig = to config the app;
idf.py build = multiple steps build process; it creaes sub-directories; run Ninja or GNU Make; Building is incremental (no-change; nothing done)
idf.py clean = delating build output files except config files; 
idf.py fullclean = delete build directory recursively;
idf.py flash -p PORT -b BAUD RATE = it flashes prog onto chip;
idf.py monitor -p PORT -b BAUD RATE = Serial output;
. You can combine commands, like this: idf.py -p COM4 flash monitor;
. The order is not important (it automatically will be executed in the correct order);
. Python interpreter - ESP-IDF works with Python 2.7 or 3.8;

Here is the layout that the ESP-IDF Tools Installer makes in my machine:

Fig 3. ESP-IDF official layout 4 Win10:)

Here is an Espressif recommended ESP-IDF project layout directory (for my custom project I put it inside the Directory Examples above and worked fine):

Fig 4. A project layout simplified for your reference

Setup Path to ESP-IDF

IDF_PATH = 
C:\Users\%userprofile%\Desktop\esp-idf
IDF_PYTHON_ENV_PATH = C:\Users\%userprofile%\.espressif\python_env\idf3.3_py3.8_env
IDF_TOOLS_PATH = 
C:\Users\%userprofile%\.espressif

Fine, now let’s code o/

The first example that I will review is the blink project.

You can find it at this location: C:\Users\%userprofile%\Desktop\esp-idf\examples\get-started\blink.

Here is the blink.c code at \main sub-directory:

1.Menu Configuration

Let’s connect our device to a USB port.

Go to Device Manager and find the port that your ESP device is attached:

Fig 5. Mine is COM10 — If you have problems with USB Driver, please refer to this post (Troubleshooting — Driver Bridge section)

Go to ESP-IDF commands prompt (cmd.exe):

Fig 6. Execute the ESP-IDF prompter

Now go to directory C:\Users\%userprofile%\Desktop\esp-idf\examples\get-started\blink and type:

idf.py menuconfig
Fig 7. The first thing to do is to check what GPIO pin is the output — Go to Example Configuration and …
Fig 8. Choose GPIO25 as output — This is the built-in LED for my first board — Then Save and Exit, and you are good to go o/
Type cls to clear the screen.

2.Building

Type:

idf.py build

This process will take a long time. Please, take a coffee and relax! ☕

3.Flashing firmware onto an ESP32 board at \main sub-directory:

When it finishes type:

idf.py -p <PORT_NUMBER> flash monitor
Fig 9. Running blink at the monitor.
Gig 1. The built-in LED flashes @ 1s interval \o/

That’s all for now!

In the next episode we won't be shy, let’s get some more stamina, right?

Thank you!

Download All Files For This Project

Credits & References

https://docs.espressif.com/projects/esp-idf/en/v3.3/api-guides/build-system-cmake.html

CMake Tutorial — CMake 3.17.3 Documentation

The CMake tutorial provides a step-by-step guide that covers common build system issues that CMake helps address…

cmake.org

Related Post

00#Episode — ESP_IDF_Series — ESP-IDF Programming Guide + WiFi LoRa 32 (v2) — How To Get Started

01#Episode — ESP_IDF_Series — LoRa LPWAN — Long Range Low Power Wide Area Network — LoRa was developed by Semtech, founder LoRa Alliance

02#Episode — ESP_IDF_Series — ESP-IDF Programming Guide + WiFi LoRa 32 (v2) + idf.py utility — How To Really Get Started

03#Episode — ESP_IDF_Series — ESP32-IDF — HelloWorld Get Started — How To Get Started (this one:)

Esp32 Programming
Esp32 Tutorial
Heltec Esp32 Wifi V2
How To Flash Esp32
Hello World
Recommended from ReadMedium