[ESP32] How to flash a firmware into ESP32(LOLIN D32 PRO ver.2.0.0) on MacOS?
Goal
- Flash firmware into ESP32
Intro
- Wemos LOLIN D32 PRO
- macOS Mojave 10.14.6
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
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
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
Set up the tools
Execute ESP-IDF Tools installer
cd ~/esp/esp-idf
sh ./install.sh
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
Start an nexample project
Copy an example project to ~/esp directory
cd ~/esp
cp -r $IDF_PATH/examples/get-started/hello_world .
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*
Build the project
idf.py build
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
Monitor
- Check if “hello_world” is indeed running
If you want to stop monitoring, type Ctrl + ]
idf.py -p [PORT_PATH] monitor
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
Menu config
cd ~/esp/hello_world
idf.py menuconfig
Component config -> ESP32-specific
Main XTAL frequency
- Change CONFIG_ESP32_XTAL_FREQ_SEL to 26MHz
댓글남기기