-
1Create Micropython build env on OSX 10.15.6
Reference: https://docs.espressif.com/projects/esp-idf/en/v3.3.2/get-started/macos-setup.html
Prerequisites:
Python3 and git ( I use brew ). Python should already be in your path.
esptool ( pip3 install esptool )
After flashing the firmware - Ampy is used to run the initial configuration scripts.
--- Create two directories for the devtools.
cd ~ mkdir ~/esp mkdir ~/Micropython cd ~/esp git clone -b v3.3.2 --recursive https://github.com/espressif/esp-idf.git
--- Add the newly installed IDF path to your environment. I use .bash_profile
export PATH="$PATH:$HOME/esp/xtensa-esp32-elf/bin" export IDF_PATH=($HOME)/esp/esp-idf
Dont forget to source the env file to activate the new settings:
source ~/.bash_profile
--- Install the python requirements for the ESP-IDFpython3 -m pip install --user -r $IDF_PATH/requirements.txt
--- Clone the micropython repository
cd ~/Micropython git clone https://github.com/micropython/micropython.git
-
2Configuring the ESP32 port for build
Reference: https://github.com/micropython/micropython/tree/master
--- Build the cross-compiler
cd ~/Micropython/micropython/mpy-cross make
--- Modfy the Makefile
cd ~/Micropython/micropython/ports/esp32
Edit the Makefile to have these variables set for the desired build
ESPIDF ?=$(HOME)/esp/esp-idf
BOARD ?= GENERIC_SPIRAM--- Modify the partition file partitions.csv
The below is how the file should look. You should only have to change the last line, at the end from 0x200000 to 0x600000
# Notes: the offset of the partition table itself is set in # $ESPIDF/components/partition_table/Kconfig.projbuild and the # offset of the factory/ota_0 partition is set in makeimg.py # Name, Type, SubType, Offset, Size, Flags nvs, data, nvs, 0x9000, 0x6000, phy_init, data, phy, 0xf000, 0x1000, factory, app, factory, 0x10000, 0x180000, vfs, data, fat, 0x200000, 0x600000,
--- Run make
make
A sub-directory will be created with the compile output ( including the firmware.bin )build-GENERIC_SPIRAM
-
3Device flashing
--- Erase the flash, if needed
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART erase_flash
--- Install the firmware.bin file onto the device
esptool.py --chip esp32 --port /dev/cu.SLAB_USBtoUART --baud 460800 write_flash -z 0x1000 firmware.bin
-
4Filesystem resize
--- connect to the device with ampy and run the script below. Do not copy to the device to run.( the filesystem is remade - so this will destroy anything in the filesystem! )
import os def df(): s = os.statvfs('//') return ('{0} MB'.format((s[0]*s[3])/1048576)) def free(full=False): F = gc.mem_free() A = gc.mem_alloc() T = F+A P = '{0:.2f}%'.format(F/T*100) if not full: return P else : return ('Total:{0} Free:{1} ({2})'.format(T,F,P)) print('disk free: ', df()) print('memory free: ', free()) os.umount('/') os.VfsFat.mkfs(bdev) os.mount(bdev, '/') print('disk free: ', df()) print('memory free: ', free())
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.