Jan 5, 2023
[Huy Le]
4 minute read

Frameworks #

There are open community versions of ESP8266, and the ones from ExpressIf

  • ESP Open Source

    • esp-open-sdk
    • esp-open-rtos
      • Using FreeRTOS in the back
  • ESP Close source

    • ESP8266_RTOS_SDK
    • ESP8266_NONOS_SDK

Background #

Methods #

Bare Metal with Open SDK #

RTOS with FreeRTOS #

user_init():: is in the rtos–>core. This is the entry to the system. Part of the user_start_phase2 which takes the user_init_task and then starts the scheduler.

Setting Up #

Dev Environment #

  sudo apt-get install make unrar-free autoconf automake libtool gcc g++ gperf flex bison texinfo gawk ncurses-dev libexpat-dev python-dev python python-serial sed git unzip bash help2man wget bzip2
  • use make to build the open sdk, then setup environment path

  • git clone=the who =esp-open-rtos folder from github

    • set up .gitignore to ignore project folder
  • By doing this, the dev toolchain is always up to date with git and developing is consistent with tags/cscope

Minicom – A Serial Terminal #

Serial terminal for communication with device. Make sure all “Modem and Dialing” parameters are cleared. We are not using the Minicom for modem connections these days. Additionally, turn off hardware control flow and software control flow off. Turn on carriage return and linefeed for it to take single commands upon enter (makes it like the Arduino serial monitor).

Serial Communication #

For flashing and all the general serial communication needs with the command line

Commands Notes [
dmesg "PIPE" grep 'tty' Port dmesg to find ttlUSB#
minicomm --device /dev/ttyUSB3 this will get minicom going [
hexdump -C test.bin "PIPE" head -10 Read hex --port /dev/ttyUSB3 --baud 9600 read_flash 0 12000 test.bin ask esptools to read flash from 0 to 12000, and write to test.bin file --port /dev/ttyUSB3 --baud 9600 chip_id This will get esptools to read the correct port

Working with USB devices #

To work with serial devices you gotta know a few thing about UDEV. Since everything is a file on Linux, we are looking into the /dev/tty* for our devices

When you do ls -l /dev/ttyUSB* it will list all your connected USB devices. Pay close attention to the permission..

crw-rw-rw-. 1 root dialout 188, 0 Jun 26 17:24 /dev/ttyUSB0

Here the group permission is dialout. So.. do you, the $USER have access to that group? If you do, you will have be able to read/write to this device. If you don’t… then let’s do something about it.

groups $USER

will show you all the groups you belong to, do you belong to the dialout group? If not, let’s add you.

sudo usermod -a -G dialout $USER

This will add you to the groups. Try groups $USER again, you should see the dialout group that you just added.

Setting up UDEV rules #

When you plug you device in, the udev rule that are set in /etc/udev are the instruction to setup the devices. You custom rules should be in /etc/udev/rules.d/ directory. There are a lot of things you can do to set up a device, it can be as general as you want to, or as specific.

SUBSYSTEMS=“usb”, OWNER=“root”, GROUP=“dialout”, MODE=“0666”=

This is the content of a 990-usb.rules file. It takes any usb that plugged in and set the owner to root and the group to dialout, and also set the permission of the USB device. Cool eh?

Sanity Project #

This will be a sanity project to make sure all the necessary components are working.

  • Git clone esp-open-sdk

    • Build it to get the toolchain binaries
  • Git clone esp-open-rtos

    • Set up the Makefile to point at the correct toochain binaries
      • The makefile settings are all in and in the root folder
      • It might be useful to check the dmesg | grep tty to see which ttyUSB# the device is connected to and get that updated in the Makefile
  • Download and install minicom

    • Set up minicom to turn off all parameters for “Modem and Dialing”, change the “control flow” and set the “carriage return” and “linefeed”
  • make flash -j4 example/sysparam_editor – make the app with 4 threads and flash it

    • This command should be ran from the root of the “esp-open-rtos”
  • If all is well, you should able to open minicom --device dev/ttyUSB3 and have a console. Type help, and something should pop up!

Troubleshoot #

  • For some reason esp-open-sdk does not build
    • Checklist

      • ☐ - Check that the LIBS environment variable is not set
    • After cleaning up packages sudo apt autoremove, something happened to the C complier

    • Suspecting that something is wrong with the C compiler package

      • I think setting the environment variable LIBS may have caused the error

Reference #

comments powered by Disqus