Fast & furious guide to programming the Nano32 (Part 2)

Part 1 of the fast & furious programming guide describes the steps towards getting started to programming the Nano32.

The ESP-IDF uses embedded operating system (e.g. FreeRTOS) that allows the programmer to create multiple tasks and to schedule those tasks. Being able to handle multi-tasks in the background makes the device useful for building multiple IoT applications.

In Part 2, we will look at getting the first program to work: first by editing it, compiling it and then flashing it to the Nano32 board.

  1. Bring up the Eclipse IDE

At the Ubuntu desktop, click on the Eclipse icon.

2. Open the first example program, HelloWorld.c

At the Project Explorer, look for the first example (2010_HelloWorld). Click 2010_HelloWorld > main > HelloWorld.c

3. Examine the program structure:

First, this program will display a message and loop again after a pre-determined delay. The parameters of the message and loop duration are stored in HELLO_MESSAGE and LOOP_DURATION variables.

Using the command-line Terminal, the config table can be invoked by

$ make menuconfig

Go to Example Configuration

In this configuration table, there are two editable config variables.

Select Display message and edit it.

Select Loop duration and edit it also.

Now the display message should read: Hello World! From Nano32 and the loop duration is set to 2000 ms or 2 seconds. Remember to save the new configuration.

4. Check the program again

For this program (or any programe) to work there are two things that should be present:

First, the two functions nvs_flash_init() and system_init() are required at all times nested under function void app_main().

Second, take note that every program should contain a task or else the Nano32 will keep resetting. Also, every task must have an infinite loop and must never exit. In this program, the main_task() function must be present for the Nano32 to work.

_

Third, check that the parameters for xTaskCreate() are properly indicated. For example, if a task involves a print function (printf), at least 1024 bytes of stack will be needed. More about this in the next part of the guide when we discuss about tasks priorities.

5. Compile/Build it

Before the program can be executed, it needs to be compiled. Click on the Build (hammer) icon. This is equivalent to the command line instruction of make all.

To upload or flash the program to the Nano32 board, at the Build Targets box (on the right side), right-click on ‘flash’ > Build Target

Although the Nano32 has an auto-uploading function, there is a need to press and hold the IO0 (flash) button (only when VirtualBox is used as the virtual machine).

6. Run the program

Once the program is completed “flashed” to the board (look for the message ‘Leaving..’, go to the command-line Terminal and run minicom.

$ minicom

Minicom is a text-based serial communication terminal that displays the hello message and loop duration in this example. To start the program running, press on the EN (enable) button on the Nano32.

The Minicom terminal will display the message that was edited earlier at the configuration menu (Hello World! From Nano32) and the number of incremental milliseconds (indicated in the parenthesis) elapsed before looping again.

To exit from Minicom, press ‘Ctrl-A’ to get the message bar below the screen to come on and then press ‘X’ to exit.

Important: Always remember to exit from the Minicom terminal before ‘flashing’ any program!

In the next part of the guide, we will look into creating multiple tasks and prioritising its order of execution.