[ESP32] How to flash a firmware into ESP32(LOLIN D32 PRO ver.2.0.0) on MacOS?

[ESP32] How to flash a firmware into ESP32(LOLIN D32 PRO ver.2.0.0) on MacOS?

Goal

  • Flash firmware into ESP32


Intro


Practice

Setup of Toolchain

  • ESP-IDF will use Python
  • ESP-IDF essentially contains API (software libraries and source code) for ESP32 and scripts to operate the Toolchain
  • If, you need to install pip
    sudo easy_install pip
    

Install pyserial

pip install --user pyserial

screenshot001


Install Cmake & Ninja

  • Ninja is a small build system with a focus on speed
  • Ninja’s low-level approach makes it perfect for embedding into more featureful build systems
  • Ninja is used to build Google Chrome, parts of Android, LLVM, and can be used in many other projects due to CMake’s Ninja backend.
  • ccache is optional. However, it is strongly recommended for faster builds
brew install cmake ninja ccache

screenshot003

screenshot003


Get ESP-IDF

  • To build applications for the ESP32, you need the software libraries provided by Espressif in ESP-IDF repository

Create local repository directory and clone

  • If you execute below commands, ~/esp/esp-idf directory will be created
  • You can use any directory, but you will need to adjust paths for the commands respectively
  • Keep in mind that ESP-IDF does not support spaces in paths.
mkdir ~/esp
cd ~/esp
git clone --recursive https://github.com/espressif/esp-idf.git

screenshot004

screenshot005


Set up the tools

Execute ESP-IDF Tools installer

cd ~/esp/esp-idf
sh ./install.sh

screenshot006


Set up the environment variables

  • The installed tools are not yet added to the PATH environment variable
  • To make the tools usable from the command line some environment variables must be set
  • You can just execute script which set up variables or add that script in ./profile or .bash_profile
cd ~/esp/esp-idf
sh ./export.sh

screenshot007


Start an nexample project

Copy an example project to ~/esp directory

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

screenshot008


Connect Your Device

  • Serial ports have the following patterns in their names
OS Pattern
Windows likes __COM1__
Linux starting with __/dev/tty__
macOS starting with __/dev/cu.__
ls /dev/cu*

screenshot009


Build the project

idf.py build

screenshot010


Flash onto the device

  • Flash the binaries that you just built onto your ESP32 board by running
  • -b option is optional and default value is 460800
  • I set up baud as 115200

The option flash automatically builds and flashes the project, so running idf.py build is not necessary

idf.py -p [PORT_PATH] {-b [BAUD]} flash

screenshot011


Monitor

  • Check if “hello_world” is indeed running

    If you want to stop monitoring, type Ctrl + ]

idf.py -p [PORT_PATH] monitor

screenshot012


If the messages were not normal

  • Your board is likely using a 26MHz crystal
  • Most development board designs use 40MHz, so ESP-IDF uses this frequency as a default value


cd ~/esp/hello_world
idf.py menuconfig

screenshot013


Component config -> ESP32-specific

screenshot014

screenshot015


Main XTAL frequency

  • Change CONFIG_ESP32_XTAL_FREQ_SEL to 26MHz

screenshot016

screenshot017



References

댓글남기기

-->