Compile#

The need to compile the MicroPython interpreter arises frequently, for example to “freeze” pre-compiled Python code into the interpreter or add new features.

Below we briefly outline the steps for compiling MicroPython in ide49.

Note: At the time of writing, compiling for the ESP32 is is not yet available for 64-Bit ARM CPUs (Raspberry PI).

Clone MicroPython#

Download from github or update an existing copy.

%%bash

# $IOT/mp is ide49's default folder for MicroPython source code and customizations
mkdir -p $IOT/mp

cd $IOT/mp
if [ ! -d micropython ]; then
    # clone the repo
    git clone https://github.com/micropython/micropython.git
else
    # update a previously downloaded repo
    cd micropython
    git checkout master
    git pull
    git merge master
fi
Hide code cell output
Already on 'master'
Your branch is up to date with 'origin/master'.
From github.com:micropython/micropython
   e2ca8ab8f..bb7aae557  master     -> origin/master
Updating e2ca8ab8f..bb7aae557
Fast-forward
 ports/stm32/boards/NUCLEO_WB55/mpconfigboard.mk           |  7 -------
 ports/stm32/boards/STM32F769DISC/mpconfigboard.mk         |  3 ---
 tools/autobuild/autobuild.sh                              |  7 ++++---
 tools/autobuild/build-boards.sh                           | 15 ++++++++++-----
 .../{build-stm32-latest.sh => build-stm32-extra.sh}       | 13 ++-----------
 tools/ci.sh                                               |  8 ++++++--
 6 files changed, 22 insertions(+), 31 deletions(-)
 rename tools/autobuild/{build-stm32-latest.sh => build-stm32-extra.sh} (82%)
Already up to date.

mpy-cross#

Follow the instructions at MicroPython github repository. The first step is to compile the MicroPython cross-compiler.

Note: The compiler is installed in a separate container, arm32, accessed via the the %%service magic. Alternatively you can login to the arm32 service at http://iot49.local/arm32 and open a terminal to run commands.

%%service arm32

cd $IOT/mp/micropython/mpy-cross
make
Hide code cell output
README.md
bin
ide49
iot-device
iot-kernel
iot49-dev
iot49.org
micropython
micropython_github
micropython_modules
scratch
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build/genhdr
GEN build/genhdr/mpversion.h
GEN build/genhdr/moduledefs.h
GEN build/genhdr/qstr.i.last
GEN build/genhdr/qstr.split
GEN build/genhdr/qstrdefs.collected.h
QSTR updated
GEN build/genhdr/qstrdefs.generated.h
mkdir -p build/py/
mkdir -p build/shared/runtime/
CC ../py/mpstate.c
CC ../py/nlr.c
CC ../py/nlrx86.c
CC ../py/nlrx64.c
CC ../py/nlrthumb.c
CC ../py/nlraarch64.c
CC ../py/nlrpowerpc.c
CC ../py/nlrxtensa.c
CC ../py/nlrsetjmp.c
CC ../py/malloc.c
CC ../py/gc.c
CC ../py/pystack.c
CC ../py/qstr.c
CC ../py/vstr.c
CC ../py/mpprint.c
CC ../py/unicode.c
CC ../py/mpz.c
CC ../py/reader.c
CC ../py/lexer.c
CC ../py/parse.c
CC ../py/scope.c
CC ../py/compile.c
CC ../py/emitcommon.c
CC ../py/emitbc.c
CC ../py/asmbase.c
CC ../py/asmx64.c
CC ../py/emitnx64.c
CC ../py/asmx86.c
CC ../py/emitnx86.c
CC ../py/asmthumb.c
CC ../py/emitnthumb.c
CC ../py/emitinlinethumb.c
CC ../py/asmarm.c
CC ../py/emitnarm.c
CC ../py/asmxtensa.c
CC ../py/emitnxtensa.c
CC ../py/emitinlinextensa.c
CC ../py/emitnxtensawin.c
CC ../py/formatfloat.c
CC ../py/parsenumbase.c
CC ../py/parsenum.c
CC ../py/emitglue.c
CC ../py/persistentcode.c
CC ../py/runtime.c
CC ../py/runtime_utils.c
CC ../py/scheduler.c
CC ../py/nativeglue.c
CC ../py/pairheap.c
CC ../py/ringbuf.c
CC ../py/stackctrl.c
CC ../py/argcheck.c
CC ../py/warning.c
CC ../py/profile.c
CC ../py/map.c
CC ../py/obj.c
CC ../py/objarray.c
CC ../py/objattrtuple.c
CC ../py/objbool.c
CC ../py/objboundmeth.c
CC ../py/objcell.c
CC ../py/objclosure.c
CC ../py/objcomplex.c
CC ../py/objdeque.c
CC ../py/objdict.c
CC ../py/objenumerate.c
CC ../py/objexcept.c
CC ../py/objfilter.c
CC ../py/objfloat.c
CC ../py/objfun.c
CC ../py/objgenerator.c
CC ../py/objgetitemiter.c
CC ../py/objint.c
CC ../py/objint_longlong.c
CC ../py/objint_mpz.c
CC ../py/objlist.c
CC ../py/objmap.c
CC ../py/objmodule.c
CC ../py/objobject.c
CC ../py/objpolyiter.c
CC ../py/objproperty.c
CC ../py/objnone.c
CC ../py/objnamedtuple.c
CC ../py/objrange.c
CC ../py/objreversed.c
CC ../py/objset.c
CC ../py/objsingleton.c
CC ../py/objslice.c
CC ../py/objstr.c
CC ../py/objstrunicode.c
CC ../py/objstringio.c
CC ../py/objtuple.c
CC ../py/objtype.c
CC ../py/objzip.c
CC ../py/opmethods.c
CC ../py/sequence.c
CC ../py/stream.c
CC ../py/binary.c
CC ../py/builtinimport.c
CC ../py/builtinevex.c
CC ../py/builtinhelp.c
CC ../py/modarray.c
CC ../py/modbuiltins.c
CC ../py/modcollections.c
CC ../py/modgc.c
CC ../py/modio.c
CC ../py/modmath.c
CC ../py/modcmath.c
CC ../py/modmicropython.c
CC ../py/modstruct.c
CC ../py/modsys.c
CC ../py/moduerrno.c
CC ../py/modthread.c
CC ../py/vm.c
CC ../py/bc.c
CC ../py/showbc.c
CC ../py/repl.c
CC ../py/smallint.c
CC ../py/frozenmod.c
CC main.c
CC gccollect.c
CC ../shared/runtime/gchelper_generic.c
LINK mpy-cross
   text	   data	    bss	    dec	    hex	filename
 287984	  17128	    896	 306008	  4ab58	mpy-cross

ARM Ports#

The example below is for the stm32 port. The procedure for other ports is similar, follow the instructions for the particular port on the MicroPython github repository.

The arm32 cross compiler is installed in container with the same name. Access it from the IoT Kernel using the %%service magic.

%%service arm32

# submodules
cd $IOT/mp/micropython/ports/stm32
git submodule update --init

In the commands below, replace PYBV11 with the name of your configuration.

%%service arm32

# compile
cd $IOT/mp/mp/micropython/ports/stm32
make clean BOARD=PYBV11
make BOARD=PYBV11
Hide code cell output
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
rm -rf build-PYBV11 
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
mkdir -p build-PYBV11/genhdr
GEN build-PYBV11/genhdr/pins.h
GEN stmconst build-PYBV11/modstm_qstr.h
GEN build-PYBV11/genhdr/mpversion.h
GEN build-PYBV11/genhdr/moduledefs.h
GEN build-PYBV11/genhdr/pybcdc.inf
GEN build-PYBV11/genhdr/pybcdc_inf.h
GEN build-PYBV11/genhdr/pllfreqtable.h
GEN build-PYBV11/genhdr/qstr.i.last
GEN build-PYBV11/genhdr/qstr.split
GEN build-PYBV11/genhdr/qstrdefs.collected.h
QSTR updated
GEN build-PYBV11/genhdr/qstrdefs.generated.h
GEN build-PYBV11/genhdr/compressed.split
GEN build-PYBV11/genhdr/compressed.collected
Compressed data updated
GEN build-PYBV11/genhdr/compressed.data.h
mkdir -p build-PYBV11/build-PYBV11/
mkdir -p build-PYBV11/drivers/bus/
mkdir -p build-PYBV11/drivers/dht/
mkdir -p build-PYBV11/drivers/memory/
mkdir -p build-PYBV11/extmod/
mkdir -p build-PYBV11/lib/embed/
mkdir -p build-PYBV11/lib/libc/
mkdir -p build-PYBV11/lib/libm/
mkdir -p build-PYBV11/lib/littlefs/
mkdir -p build-PYBV11/lib/mp-readline/
mkdir -p build-PYBV11/lib/netutils/
mkdir -p build-PYBV11/lib/oofatfs/
mkdir -p build-PYBV11/lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/
mkdir -p build-PYBV11/lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/gcc/
mkdir -p build-PYBV11/lib/stm32lib/STM32F4xx_HAL_Driver/Src/
mkdir -p build-PYBV11/lib/timeutils/
mkdir -p build-PYBV11/lib/utils/
mkdir -p build-PYBV11/py/
mkdir -p build-PYBV11/usbdev/class/src/
mkdir -p build-PYBV11/usbdev/core/src/
CC ../../py/mpstate.c
CC ../../py/nlr.c
CC ../../py/nlrx86.c
CC ../../py/nlrx64.c
CC ../../py/nlrthumb.c
CC ../../py/nlraarch64.c
CC ../../py/nlrpowerpc.c
CC ../../py/nlrxtensa.c
CC ../../py/nlrsetjmp.c
CC ../../py/malloc.c
CC ../../py/gc.c
CC ../../py/pystack.c
CC ../../py/qstr.c
CC ../../py/vstr.c
CC ../../py/mpprint.c
CC ../../py/unicode.c
CC ../../py/mpz.c
CC ../../py/reader.c
CC ../../py/lexer.c
CC ../../py/parse.c
CC ../../py/scope.c
CC ../../py/compile.c
CC ../../py/emitcommon.c
CC ../../py/emitbc.c
CC ../../py/asmbase.c
CC ../../py/asmx64.c
CC ../../py/emitnx64.c
CC ../../py/asmx86.c
CC ../../py/emitnx86.c
CC ../../py/asmthumb.c
CC ../../py/emitnthumb.c
CC ../../py/emitinlinethumb.c
CC ../../py/asmarm.c
CC ../../py/emitnarm.c
CC ../../py/asmxtensa.c
CC ../../py/emitnxtensa.c
CC ../../py/emitinlinextensa.c
CC ../../py/emitnxtensawin.c
CC ../../py/formatfloat.c
CC ../../py/parsenumbase.c
CC ../../py/parsenum.c
CC ../../py/emitglue.c
CC ../../py/persistentcode.c
CC ../../py/runtime.c
CC ../../py/runtime_utils.c
CC ../../py/scheduler.c
CC ../../py/nativeglue.c
CC ../../py/pairheap.c
CC ../../py/ringbuf.c
CC ../../py/stackctrl.c
CC ../../py/argcheck.c
CC ../../py/warning.c
CC ../../py/profile.c
CC ../../py/map.c
CC ../../py/obj.c
CC ../../py/objarray.c
CC ../../py/objattrtuple.c
CC ../../py/objbool.c
CC ../../py/objboundmeth.c
CC ../../py/objcell.c
CC ../../py/objclosure.c
CC ../../py/objcomplex.c
CC ../../py/objdeque.c
CC ../../py/objdict.c
CC ../../py/objenumerate.c
CC ../../py/objexcept.c
CC ../../py/objfilter.c
CC ../../py/objfloat.c
CC ../../py/objfun.c
CC ../../py/objgenerator.c
CC ../../py/objgetitemiter.c
CC ../../py/objint.c
CC ../../py/objint_longlong.c
CC ../../py/objint_mpz.c
CC ../../py/objlist.c
CC ../../py/objmap.c
CC ../../py/objmodule.c
CC ../../py/objobject.c
CC ../../py/objpolyiter.c
CC ../../py/objproperty.c
CC ../../py/objnone.c
CC ../../py/objnamedtuple.c
CC ../../py/objrange.c
CC ../../py/objreversed.c
CC ../../py/objset.c
CC ../../py/objsingleton.c
CC ../../py/objslice.c
CC ../../py/objstr.c
CC ../../py/objstrunicode.c
CC ../../py/objstringio.c
CC ../../py/objtuple.c
CC ../../py/objtype.c
CC ../../py/objzip.c
CC ../../py/opmethods.c
CC ../../py/sequence.c
CC ../../py/stream.c
CC ../../py/binary.c
CC ../../py/builtinimport.c
CC ../../py/builtinevex.c
CC ../../py/builtinhelp.c
CC ../../py/modarray.c
CC ../../py/modbuiltins.c
CC ../../py/modcollections.c
CC ../../py/modgc.c
CC ../../py/modio.c
CC ../../py/modmath.c
CC ../../py/modcmath.c
CC ../../py/modmicropython.c
CC ../../py/modstruct.c
CC ../../py/modsys.c
CC ../../py/moduerrno.c
CC ../../py/modthread.c
CC ../../py/vm.c
CC ../../py/bc.c
CC ../../py/showbc.c
CC ../../py/repl.c
CC ../../py/smallint.c
CC ../../py/frozenmod.c
CC ../../extmod/moduasyncio.c
CC ../../extmod/moductypes.c
CC ../../extmod/modujson.c
CC ../../extmod/modumsgpack.c
CC ../../extmod/modure.c
CC ../../extmod/moduzlib.c
CC ../../extmod/moduheapq.c
CC ../../extmod/modutimeq.c
CC ../../extmod/moduhashlib.c
CC ../../extmod/moducryptolib.c
CC ../../extmod/modubinascii.c
CC ../../extmod/virtpin.c
CC ../../extmod/machine_mem.c
CC ../../extmod/machine_pinbase.c
CC ../../extmod/machine_signal.c
CC ../../extmod/machine_pulse.c
CC ../../extmod/machine_i2c.c
CC ../../extmod/machine_spi.c
CC ../../extmod/modbluetooth.c
CC ../../extmod/modussl_axtls.c
CC ../../extmod/modussl_mbedtls.c
CC ../../extmod/modurandom.c
CC ../../extmod/moduselect.c
CC ../../extmod/moduwebsocket.c
CC ../../extmod/modwebrepl.c
CC ../../extmod/modframebuf.c
CC ../../extmod/modfinaliserproxy.c
CC ../../extmod/vfs.c
CC ../../extmod/vfs_blockdev.c
CC ../../extmod/vfs_reader.c
CC ../../extmod/vfs_posix.c
CC ../../extmod/vfs_posix_file.c
CC ../../extmod/vfs_fat.c
CC ../../extmod/vfs_fat_diskio.c
CC ../../extmod/vfs_fat_file.c
CC ../../extmod/vfs_lfs.c
CC ../../extmod/utime_mphal.c
CC ../../extmod/uos_dupterm.c
CC ../../lib/embed/abort_.c
CC ../../lib/utils/printf.c
MPY uasyncio/__init__.py
MPY uasyncio/core.py
MPY uasyncio/event.py
MPY uasyncio/funcs.py
MPY uasyncio/lock.py
MPY uasyncio/stream.py
MPY dht.py
MPY lcd160cr.py
MPY lcd160cr_test.py
MPY onewire.py
GEN build-PYBV11/frozen_content.c
CC build-PYBV11/frozen_content.c
CC ../../lib/libc/string0.c
CC ../../lib/mp-readline/readline.c
CC ../../lib/netutils/netutils.c
CC ../../lib/netutils/trace.c
CC ../../lib/netutils/dhcpserver.c
CC ../../lib/timeutils/timeutils.c
CC ../../lib/utils/gchelper_native.c
CC ../../lib/utils/pyexec.c
CC ../../lib/utils/interrupt_char.c
CC ../../lib/utils/sys_stdio_mphal.c
CC ../../lib/utils/mpirq.c
CC ../../lib/libm/math.c
CC ../../lib/libm/acoshf.c
CC ../../lib/libm/asinfacosf.c
CC ../../lib/libm/asinhf.c
CC ../../lib/libm/atan2f.c
CC ../../lib/libm/atanf.c
CC ../../lib/libm/atanhf.c
CC ../../lib/libm/ef_rem_pio2.c
CC ../../lib/libm/erf_lgamma.c
CC ../../lib/libm/fmodf.c
CC ../../lib/libm/kf_cos.c
CC ../../lib/libm/kf_rem_pio2.c
CC ../../lib/libm/kf_sin.c
CC ../../lib/libm/kf_tan.c
CC ../../lib/libm/log1pf.c
CC ../../lib/libm/nearbyintf.c
CC ../../lib/libm/roundf.c
CC ../../lib/libm/sf_cos.c
CC ../../lib/libm/sf_erf.c
CC ../../lib/libm/sf_frexp.c
CC ../../lib/libm/sf_ldexp.c
CC ../../lib/libm/sf_modf.c
CC ../../lib/libm/sf_sin.c
CC ../../lib/libm/sf_tan.c
CC ../../lib/libm/wf_lgamma.c
CC ../../lib/libm/wf_tgamma.c
CC ../../lib/libm/thumb_vfp_sqrtf.c
CC ../../extmod/modonewire.c
CC ../../drivers/bus/softspi.c
CC ../../drivers/bus/softqspi.c
CC ../../drivers/memory/spiflash.c
CC ../../drivers/dht/dht.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rtc_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sdram.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dcmi.c
CC ../../lib/stm32lib/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c
CC usbdev/core/src/usbd_core.c
CC usbdev/core/src/usbd_ctlreq.c
CC usbdev/core/src/usbd_ioreq.c
CC usbdev/class/src/usbd_cdc_msc_hid.c
CC usbdev/class/src/usbd_msc_bot.c
CC usbdev/class/src/usbd_msc_scsi.c
CC boardctrl.c
CC main.c
CC stm32_it.c
CC usbd_conf.c
CC usbd_desc.c
CC usbd_cdc_interface.c
CC usbd_hid_interface.c
CC usbd_msc_interface.c
CC mphalport.c
CC mpthreadport.c
CC irq.c
CC pendsv.c
CC systick.c
CC softtimer.c
CC powerctrl.c
CC powerctrlboot.c
CC rfcore.c
CC pybthread.c
CC factoryreset.c
CC timer.c
CC led.c
CC pin.c
CC pin_defs_stm32.c
CC pin_named_pins.c
CC bufhelper.c
CC dma.c
CC i2c.c
CC pyb_i2c.c
CC spi.c
CC pyb_spi.c
CC qspi.c
CC uart.c
CC can.c
CC fdcan.c
CC pyb_can.c
CC usb.c
CC wdt.c
CC eth.c
CC gccollect.c
CC help.c
CC machine_adc.c
CC machine_i2c.c
CC machine_spi.c
CC machine_timer.c
CC machine_uart.c
CC modmachine.c
CC modpyb.c
CC modstm.c
CC moduos.c
CC modutime.c
CC modusocket.c
CC network_lan.c
CC modnetwork.c
CC extint.c
CC usrsw.c
CC rng.c
CC rtc.c
CC flash.c
CC flashbdev.c
CC spibdev.c
CC storage.c
CC sdcard.c
CC sdram.c
CC fatfs_port.c
CC lcd.c
CC accel.c
CC servo.c
CC dac.c
CC adc.c
AS ../../lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/gcc/startup_stm32f405xx.s
CC ../../lib/stm32lib/CMSIS/STM32F4xx/Source/Templates/system_stm32f4xx.c
CC system_stm32.c
AS resethandler.s
AS ../../lib/utils/gchelper_m3.s
CC ../../lib/oofatfs/ff.c
CC ../../lib/oofatfs/ffunicode.c
CC ../../lib/littlefs/lfs2.c
CC ../../lib/littlefs/lfs2_util.c
CC build-PYBV11/pins_PYBV11.c
LINK build-PYBV11/firmware.elf
   text	   data	    bss	    dec	    hex	filename
 363636	     16	  27272	 390924	  5f70c	build-PYBV11/firmware.elf
GEN build-PYBV11/firmware0.bin
GEN build-PYBV11/firmware1.bin
GEN build-PYBV11/firmware.dfu
GEN build-PYBV11/firmware.hex

ESP32 Port#

The esp-idf compiler is installed in container with the same name. You can also get a console at http://iot49.local/esp-idf.

%%service esp-idf

# submodules
cd $IOT/mp/mp/micropython/ports/esp32
make submodules
Hide code cell output
setting up IDF ...
git submodule update --init ../../lib/berkeley-db-1.xx
%%service esp-idf

# compile
cd $IOT/mp/mp/micropython/ports/esp32
make BOARD=GENERIC_OTA
Hide code cell output
setting up IDF ...
idf.py -D MICROPY_BOARD=GENERIC_OTA -B build-GENERIC_OTA  build
[1/203] cd /home/iot/micropython/ports/esp32/build-GENERIC_OTA/esp-idf/main && echo -n
[2/4] Performing build step for 'bootloader'
ninja: no work to do.
Executing action: all (aliases: build)
Running ninja in directory /home/iot/micropython/ports/esp32/build-GENERIC_OTA
Executing "ninja all"...

Project build complete. To flash, run this command:
/opt/esp/python_env/idf4.2_py3.7_env/bin/python ../../../../../opt/esp/idf/components/esptool_py/esptool/esptool.py -p (PORT) -b 460800 --before default_reset --after hard_reset --chip esp32  write_flash --flash_mode dio --flash_size detect --flash_freq 40m 0x1000 build-GENERIC_OTA/bootloader/bootloader.bin 0x8000 build-GENERIC_OTA/partition_table/partition-table.bin 0xd000 build-GENERIC_OTA/ota_data_initial.bin 0x10000 build-GENERIC_OTA/micropython.bin
or run 'idf.py -p (PORT) flash'
bootloader  @0x001000    22720  (    5952 remaining)
partitions  @0x008000     3072  (    1024 remaining)
application @0x010000  1448064  (  124800 remaining)
total                  1513600

Find port …

%discover -a
/dev/ttyUSB0
  hwid         USB VID:PID=10C4:EA60 SER=0160B5B8 LOCATION=1-5.2
  manufacturer Silicon Labs
  product      CP2104 USB to UART Bridge Controller
  interface    CP2104 USB to UART Bridge Controller

Update the port to match the output from the previous cell (e.g. /dev/ttyUSB0), then run the next cell to flash the code to the microcontroller.

%%service esp-idf

# flash
cd $IOT/mp/mp/micropython/ports/esp32
make BOARD=GENERIC_OTA PORT=/dev/ttyUSB0 deploy
Hide code cell output
setting up IDF ...
idf.py -D MICROPY_BOARD=GENERIC_OTA -B build-GENERIC_OTA  -p /dev/ttyUSB0 -b 460800 flash
[1/204] cd /home/iot/micropython/ports/esp32/build-GENERIC_OTA/esp-idf/main && echo -n
[2/5] Performing build step for 'bootloader'
ninja: no work to do.
[2/3] cd /opt/esp/idf/components/esptool_py && /opt/esp/tools/cmake/3.16.4/bin/cmake -D IDF_PATH="/opt/esp/idf" -D ESPTOOLPY="/opt/esp/python_env/idf4.2_py3.7_env/bin/python /opt/esp/idf/components/esptool_py/esptool/esptool.py --chip esp32" -D ESPTOOL_ARGS="--before=default_reset --after=hard_reset write_flash @flash_args" -D WORKING_DIRECTORY="/home/iot/micropython/ports/esp32/build-GENERIC_OTA" -P /opt/esp/idf/components/esptool_py/run_esptool.cmake
esptool.py --chip esp32 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x8000 partition_table/partition-table.bin 0xd000 ota_data_initial.bin 0x1000 bootloader/bootloader.bin 0x10000 micropython.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, Coding Scheme None
Crystal is 40MHz
MAC: 30:ae:a4:30:84:34
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Compressed 3072 bytes to 139...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (139 compressed) at 0x00008000 in 0.0 seconds (effective 4847.8 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 31...
Writing at 0x0000d000... (100 %)
Wrote 8192 bytes (31 compressed) at 0x0000d000 in 0.0 seconds (effective 26054.8 kbit/s)...
Hash of data verified.
Compressed 22720 bytes to 14201...
Writing at 0x00001000... (100 %)
Wrote 22720 bytes (14201 compressed) at 0x00001000 in 0.3 seconds (effective 537.2 kbit/s)...
Hash of data verified.
Compressed 1448064 bytes to 960828...
Writing at 0x00010000... (1 %)
Writing at 0x00014000... (3 %)
Writing at 0x00018000... (5 %)
Writing at 0x0001c000... (6 %)
Writing at 0x00020000... (8 %)
Writing at 0x00024000... (10 %)
Writing at 0x00028000... (11 %)
Writing at 0x0002c000... (13 %)
Writing at 0x00030000... (15 %)
Writing at 0x00034000... (16 %)
Writing at 0x00038000... (18 %)
Writing at 0x0003c000... (20 %)
Writing at 0x00040000... (22 %)
Writing at 0x00044000... (23 %)
Writing at 0x00048000... (25 %)
Writing at 0x0004c000... (27 %)
Writing at 0x00050000... (28 %)
Writing at 0x00054000... (30 %)
Writing at 0x00058000... (32 %)
Writing at 0x0005c000... (33 %)
Writing at 0x00060000... (35 %)
Writing at 0x00064000... (37 %)
Writing at 0x00068000... (38 %)
Writing at 0x0006c000... (40 %)
Writing at 0x00070000... (42 %)
Writing at 0x00074000... (44 %)
Writing at 0x00078000... (45 %)
Writing at 0x0007c000... (47 %)
Writing at 0x00080000... (49 %)
Writing at 0x00084000... (50 %)
Writing at 0x00088000... (52 %)
Writing at 0x0008c000... (54 %)
Writing at 0x00090000... (55 %)
Writing at 0x00094000... (57 %)
Writing at 0x00098000... (59 %)
Writing at 0x0009c000... (61 %)
Writing at 0x000a0000... (62 %)
Writing at 0x000a4000... (64 %)
Writing at 0x000a8000... (66 %)
Writing at 0x000ac000... (67 %)
Writing at 0x000b0000... (69 %)
Writing at 0x000b4000... (71 %)
Writing at 0x000b8000... (72 %)
Writing at 0x000bc000... (74 %)
Writing at 0x000c0000... (76 %)
Writing at 0x000c4000... (77 %)
Writing at 0x000c8000... (79 %)
Writing at 0x000cc000... (81 %)
Writing at 0x000d0000... (83 %)
Writing at 0x000d4000... (84 %)
Writing at 0x000d8000... (86 %)
Writing at 0x000dc000... (88 %)
Writing at 0x000e0000... (89 %)
Writing at 0x000e4000... (91 %)
Writing at 0x000e8000... (93 %)
Writing at 0x000ec000... (94 %)
Writing at 0x000f0000... (96 %)
Writing at 0x000f4000... (98 %)
Writing at 0x000f8000... (100 %)
Wrote 1448064 bytes (960828 compressed) at 0x00010000 in 23.1 seconds (effective 501.3 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Executing action: flash
Running ninja in directory /home/iot/micropython/ports/esp32/build-GENERIC_OTA
Executing "ninja flash"...
Done

Verify it’s working …

%discover 
%connect esp32

print("installed modules ...")
help('modules')
esp32  serial:///dev/ttyUSB0  
Connected to esp32 @ serial:///dev/ttyUSB0
installed modules ...
__main__          framebuf          uasyncio/lock     urandom
_boot             gc                uasyncio/stream   ure
_onewire          inisetup          ubinascii         uselect
_thread           machine           ubluetooth        usocket
_uasyncio         math              ucollections      ussl
_webrepl          micropython       ucryptolib        ustruct
apa106            neopixel          uctypes           usys
btree             network           uerrno            utime
builtins          ntptime           uhashlib          utimeq
cmath             onewire           uheapq            uwebsocket
dht               uarray            uio               uzlib
ds18x20           uasyncio/__init__ ujson             webrepl
esp               uasyncio/core     uos               webrepl_setup
esp32             uasyncio/event    upip              websocket_helper
flashbdev         uasyncio/funcs    upip_utarfile
Plus any modules on the filesystem

Unix Port#

%%service arm32

cd $IOT/mp/mp/micropython/ports/unix
make submodules
make

Check it out:

%%bash

cd $IOT/mp/mp/micropython/ports/unix
./micropython -c "import sys; print(sys.platform)"
linux
%%bash

cd $IOT/mp/mp/micropython/ports/unix
./micropython -m upip install micropython-pystone
./micropython -m pystone
Installing to: /home/iot/.micropython/lib/
Warning: micropython.org SSL certificate is not validated
Installing micropython-pystone 3.4.2.post2 from https://micropython.org/pi/pystone/pystone-3.4.2.post2.tar.gz
Pystone(1.2) time for 50000 passes = 0.981
This machine benchmarks at 50968.4 pystones/second