Wiznet makers

ruilixin6

Published July 29, 2026 ©

29 UCC

0 VAR

0 Contests

0 Followers

0 Following

Embedded 101: MicroPython Execution Principles & Project Architecture Quick Overview

This article illustrates the merits of MicroPython, its source structure, code execution flow and multiple supported hardware ports.

COMPONENTS
PROJECT DESCRIPTION

【Preliminary Note】The original hardware example in this article was written based on the RP2040. The actual hardware used in this hands-on demonstration features the W55RP20 as the main controller chip. The circuit logic and UF2 flashing operation principles are universally applicable, with only the main controller model differing. The original chip model mentioned in the circuit descriptions below is provided for reference purposes only.

1. Why use MicroPython to build our project

1.1 Reduce Development Difficulty

MicroPython comes with pre-built, proven hardware systems and low-level driver libraries, which allows us to focus our programming efforts on application-layer development instead of building a project from the absolute ground up. This greatly cuts down the time spent on low-level hardware design and software debugging, while also significantly lowering the technical barrier to entry for embedded development.

1.2 High Portability

When programming with traditional C/C++, it is often necessary to use SDK packages or driver functions provided by chip vendors, such as ST's CubeIDE and NXP's PE. While these tools can greatly reduce the difficulty of development, the tools from different manufacturers vary, and their library functions are incompatible, making it extremely difficult to directly port programs developed with these tools.
However, the emergence of MicroPython enables us to complete the application layer transplantation without re-implementing the underlying functions. As MicroPython itself is a scripting language that has little correlation with hardware, coupled with the concise syntax of the Python language itself, program transplantation and upgrading become extremely easy.

1.3 Openness

MicroPython and Pyboard adopt the relatively permissive MIT license. The MIT license, just like the BSD license, is a permissive Licensing Agreement, under which the author only reserves the copyright without imposing any other restrictions. Anyone is free to use, modify and publish it, and can also apply it to commercial products free of charge.
You only need to include a statement of the original Licensing Agreement in your distribution, whether you publish it in binary form or in source code form.
The open nature of MicroPython has enabled it to achieve tremendous growth in just a few years, with a large number of engineers and enthusiasts around the world learning and using it.
Figure 1.3 Architecture Description of the MicroPython Project

2. Introduction to MicroPython Project Architecture

We can compare the project architecture of MicroPython to "a customizable set of embedded Python development building blocks": the core blocks are the universal Python functions available for all devices, while the device-specific blocks are the platform code adapted to hardware. This design not only ensures the versatility of MicroPython but also enables flexible adaptation to various microcontrollers and systems. Before diving into the architecture, let's first understand several core concepts:
Cross-compiler: Simply put, it refers to compiling code on Computer A that can run on Device B (for example, compiling MicroPython bytecode that can run on Raspberry Pi Pico on a Windows PC), which avoids the trouble of compiling directly on microcontrollers with limited resources.
Port: Also referred to as "porting", it is the dedicated adaptation code written by MicroPython for different hardware platforms (such as ESP32, RP2040, STM32) — just as the same set of games needs to be adapted for mobile and PC versions, a port is the "hardware platform-specific version" of MicroPython.
Bytecode: An intermediate code (not direct machine code) that Python code is converted into before execution, which can be run directly by the MicroPython virtual machine, featuring both light weight and cross-platform compatibility.
RTOS (Real-Time Operating System): a compact operating system for embedded devices that manages hardware resources and handles multi-tasking (e. g. Zephyr RTOS).
The project code of MicroPython is divided into different directories according to the logic of "common core + platform adaptation + auxiliary tools", and each directory has a clear functional division. The specific architecture composition is as follows:
py/ -- Core Python implementation, including compiler, runtime, and core libraries
mpy-cross/ — MicroPython cross compiler, used to convert scripts into pre-compiled bytecode
ports/ -- Platform-specific code for the various ports and architectures that MicroPython runs on
lib/ -- Submodule for external dependencies
test/ -- Test frameworks and test scripts
docs/ -- User documentation in Sphinx reStructuredText format, which is used to generate online documentation
extmod/ -- Additional (non-core) modules implemented in C
tools/ -- Various tools, including the pyboard. py module
example/ -- Some sample Python scripts
drivers/ -- Software-implemented hardware drivers, which are Python modules (C + Python) implemented in standard C based on the py architecture, slightly different from the SDK provided by the chip itself and featuring relatively high compatibility.
minimal port provides a very basic example of a MicroPython port, which can be compiled into a standalone Linux binary as well as for ARM Cortex M4. If you want to port MicroPython to another microcontroller, start here. Additionally, the "bare-arm" port is an example of an absolutely minimal configuration, used to track the code size of the core runtime and virtual machine.
Figure 2.4 Structure Diagram of MicroPython Project Port Code
In addition, the following ports are also available in this repository:
cc3200 —— Texas Instruments CC3200 (including PyCom WiPy);
esp32—— 乐鑫 ESP32 SoC(包括 ESP32S2、ESP32S3、ESP32C3);
esp8266 —— Espressif ESP8266 SoC;
mimxrt——NXP m.iMX RT(包括 Teensy 4.x);
nrf——Nordic Semiconductor nRF51 和 nRF52;
pic16bit——Microchip PIC 16 位;
powerpc——IBM PowerPC(包括 Microwatt);
qemu-arm: a QEMU-based emulation target for testing;
Renesas-ra —— Renesas RA Series;
rp2——Raspberry Pi RP2040(包括 Pico 和 Pico W);
samd —— Microchip (formerly Atmel) SAMD21 and SAMD51;
STM32 —— STMicroelectronics STM32 series (including F0, F4, F7, G0, G4, H7, L0, L4, WB);
WebAssembly —— Emscripten port for browsers and Node. js;
zephyr——Zephyr RTOS。
Documents
Comments Write