6 Jul 2020

Get Started with ESP8266/ESP32. Setup RTOS & NONOS, IDF SDKs


My setup IDF_PATH --> sudo nano ~/.zshrc

1. Toolchain Setup


ESP8266 toolchain for macOS is available for download from Espressif website:
https://dl.espressif.com/dl/xtensa-lx106-elf-macos-1.22.0-100-ge567ec7-5.2.0.tar.gz
Download this file, then extract it in ~/esp directory:

mkdir -p ~/esp 
cd ~/esp 
tar -xzf ~/Downloads/xtensa-lx106-elf-macos-1.22.0-100-ge567ec7-5.2.0.tar.gz

To use it, you will need to update your PATH environment variable in ~/.zshrc file. To make xtensa-lx106-elf available for all terminal sessions, add the following line to your ~/.zshrc file:

export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin

sudo nano ~/.bash_profile
export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin


ESP32 toolchain for macOS is available for download from Espressif website:
https://dl.espressif.com/dl/xtensa-esp32-elf-gcc8_2_0-esp-2020r1-macos.tar.gz
Download this file, then extract it in ~/esp directory:

mkdir -p ~/esp 
cd ~/esp 
tar -xzf ~/Downloads/xtensa-esp32-elf-gcc8_2_0-esp-2020r1-macos.tar.gz

To use it, you will need to update your PATH environment variable in ~/.zshrc  file. To make xtensa-esp32-elf available for all terminal sessions, add the following line to your ~/.zshrc  file:

export PATH=$HOME/esp/xtensa-esp32-elf/bin:$PATH

sudo nano ~/.bash_profile
export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin


2. Get SDK

~/esp directory to install the prebuilt toolchain, ESP8266_RTOS_SDK and sample applications.

cd ~/esp 
git clone --recursive https://github.com/espressif/ESP8266_RTOS_SDK.git

or

git clone --recursive https://github.com/espressif/ESP8266_NONOS_SDK.git

or

git clone --recursive https://github.com/espressif/esp-idf.git

https://docs.espressif.com/projects/esp-idf/en/v3.3.1/get-started/index.html#setup-path-to-esp-idf

3. Setup Path

The toolchain programs access ESP8266_RTOS_SDK using IDF_PATH environment variable.

Not all shells use .profile. If you have /bin/bash and .bash_profile exists then update this file instead. For zsh, update .zprofile. Other shells may use other profile files (consult the shell’s documentation).

macOS Catalina 10.15.5 uses .zprofile instead of .bash_profile

Open terminal

sudo nano .zshrc

add

export IDF_PATH="~/esp/esp-idf:$IDF_PATH"

or

export IDF_PATH="~/esp/ESP8266_RTOS_SDK:$IDF_PATH"


or

export IDF_PATH="~/esp/ESP8266_NONOS_SDK:$IDF_PATH"

^O (F3) write the current file to disk

Force the .bash_profile to execute. This loads the values immediately without having to reboot. In your Terminal window, run the following command.

source ~/.zshrc

test with

echo $IDF_PATH or printenv IDF_PATH

my .zshrc
export PATH=$PATH:$HOME/esp/xtensa-lx106-elf/bin
export PATH=$PATH:$HOME/esp/xtensa-esp32-elf/bin
export IDF_PATH=~/esp/ESP8266_RTOS_SDK


sudo nano ~/.bash_profile then need add source ~/.bash_profile to .zshrc

sudo nano ~/.profile then always use source ~/.profile
sudo nano ~/.zprofile

4. Install the Required Python Packages

python -m pip install --user -r $IDF_PATH/requirements.txt

5. Start a Project

Copy get-started/hello_world to ~/esp directory:

cd ~/esp 
cp -r $IDF_PATH/examples/get-started/hello_world

6. Connect the board

look up the board 
ls /dev/tty.*

/dev/tty.usbserial-1420
/dev/tty.wchusbserial1420

7. Configure

cd ~/esp/hello_world 
make menuconfig

ERROR No such file or directory ...
source ~/.profile



Navigate to Serial flasher config > Default serial port
to configure the serial port with /dev/tty.wchusbserial1420

8. Build and Flash

make flash

This will compile the application and all the ESP8266_RTOS_SDK components, generate bootloader, partition table, and application binaries, and flash these binaries to your ESP8266 board.

====

make all

It will compile app based on the config.

When make all finishes, it will print a command line to use esptool.py to flash the chip. However you can also do this from make by running:

make flash

This will flash the entire project (app, bootloader and init data bin) to a new chip. The settings for serial port flashing can be configured with make menuconfig.

You don't need to run make all before running make flash, make flash will automatically rebuild anything which needs it.

8.1 Erasing Flash

The make flash target does not erase the entire flash contents. However, it is sometimes useful to set the device back to a totally erased state. 

To erase the entire flash, run:

make erase_flash

9. Serial Monitor

make monitor

=== Troubleshooting ===

The setting may be done manually, each time PC is restarted. Another option is to set up it permanently by defining IDF_PATH in the user profile.

For manually, the command:

export IDF_PATH=~/esp/ESP8266_RTOS_SDK

No comments:

Post a Comment

Popular Posts