Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build folders
**/build
**/build-*

# ESP32 IDF build files
**/managed_components
100 changes: 86 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,91 @@
MicroPython example boards
==========================
MicroPython custom boards workspace
===================================

This repository is an example of how to define custom MicroPython boards
with custom Python and C modules. The core MicroPython repository is a
submodule and other code, including board definitions, is part of this
repository.
This repository contains out-of-tree custom board definitions and wrappers,
using upstream MicroPython (in `lib/micropython`) as a submodule.

To set up MicroPython, check out the submodule and build `mpy-cross`:
Quick start
-----------

$ git submodule update --init lib/micropython
$ make -C lib/micropython/mpy-cross
From repository root:

The various custom boards will require certain submodules of MicroPython
itself. These can be initialised via:
```sh
git submodule update --init lib/micropython
make -C lib/micropython/mpy-cross
```

Port prerequisites (using upstream `tools/ci.sh`)
-------------------------------------------------

From `lib/micropython`:

### ESP32 (`CUSTOM_ESP32`, `CUSTOM_ESP32_C6`)

```sh
cd lib/micropython
source tools/ci.sh
ci_esp32_idf_setup
# return to repo root
cd ../..
```

Then, for each shell where you build, load IDF env:

```sh
source lib/micropython/esp-idf/export.sh
```

### STM32 (`CUSTOM_PYBV11`, `CUSTOM_PYBD_SF2`)

```sh
cd lib/micropython
source tools/ci.sh
ci_stm32_setup
export PATH="$(pwd)/$(ci_stm32_path):$PATH"
# return to repo root
cd ../..
```

STM32 Notes
-----

- `CUSTOM_PYBD_SF2` main firmware expects `mboot` to be built/installed first:

```sh
cd boards/CUSTOM_PYBD_SF2
make mboot -j4
```


### RP2 / RP2040 (`CUSTOM_RP2040`)

```sh
cd lib/micropython
source tools/ci.sh
ci_rp2_setup
# return to repo root
cd ../..
```

If your distro toolchain is missing C++ headers for `arm-none-eabi`, install:

```sh
sudo apt-get install libstdc++-arm-none-eabi-newlib
```


- Board-specific details are documented in each board directory README.

Custom boards build matrix
--------------------------

All commands below are run from this repository root (`custom_boards`).

| Board | Port | Build | Output |
|---|---|---|---|
| `CUSTOM_ESP32` | `esp32` | `source lib/micropython/esp-idf/export.sh && cd boards/CUSTOM_ESP32 && idf.py set-target esp32 && idf.py build` | `boards/CUSTOM_ESP32/build/micropython.bin` |
| `CUSTOM_ESP32_C6` | `esp32` | `source lib/micropython/esp-idf/export.sh && cd boards/CUSTOM_ESP32_C6 && idf.py set-target esp32c6 && idf.py build` | `boards/CUSTOM_ESP32_C6/build/micropython.bin` |
| `CUSTOM_PYBV11` | `stm32` | `cd boards/CUSTOM_PYBV11 && make init-submodules && make clean && make -j4` | `boards/CUSTOM_PYBV11/build/firmware.dfu` |
| `CUSTOM_PYBD_SF2` | `stm32` | `cd boards/CUSTOM_PYBD_SF2 && make init-submodules && make clean && make -j4` | `boards/CUSTOM_PYBD_SF2/build/firmware.dfu` |
| `CUSTOM_RP2040` | `rp2` | `cd boards/CUSTOM_RP2040 && make init-submodules && make clean && make -j4` | `boards/CUSTOM_RP2040/build/firmware.uf2` |

$ cd lib/micropython
$ git submodule update --init lib/stm32lib lib/berkeley-db-1.xx
$ cd ../..
37 changes: 31 additions & 6 deletions boards/CUSTOM_ESP32/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
This directory contains board definition files for an esp32-based board.
This directory contains board definition files for a custom ESP32 board.

To build it make sure the IDF has been installed and the environment set up,
for example using `export $IDF_PATH/export.sh`. Then build with:
These files are maintained for current MicroPython + ESP-IDF 5.x layout.

$ idf.py build
## Build

To deploy the firmware to the board:
From the repository root (`custom_boards`):

$ idf.py -p /dev/ttyUSB0 flash
```sh
cd lib/micropython
source tools/ci.sh
ci_esp32_idf_setup
# return to repo root
cd ../..

source lib/micropython/esp-idf/export.sh
cd boards/CUSTOM_ESP32
idf.py fullclean
idf.py set-target esp32
idf.py build
```

## Flash

```sh
idf.py -p /dev/ttyUSB0 flash
```

## Monitor serial output

```sh
idf.py -p /dev/ttyUSB0 monitor
```

Tip: if your serial device is different, replace `/dev/ttyUSB0` accordingly.
35 changes: 35 additions & 0 deletions boards/CUSTOM_ESP32/dependencies.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
dependencies:
espressif/lan867x:
component_hash: 0ff9dae3affeff53811e7c8283e67c6d36dc0c03e3bc5102c0fba629e08bf6c4
dependencies:
- name: idf
require: private
version: '>=5.3'
source:
registry_url: https://components.espressif.com/
type: service
targets:
- esp32
- esp32p4
version: 1.0.3
espressif/mdns:
component_hash: 46ee81d32fbf850462d8af1e83303389602f6a6a9eddd2a55104cb4c063858ed
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.1.0
idf:
source:
type: idf
version: 5.5.1
direct_dependencies:
- espressif/lan867x
- espressif/mdns
- idf
manifest_hash: 482087bc40f0e187795a9ef9ad08ef15a585b4cdabc296c715a9d19284622150
target: esp32
version: 2.0.0
4 changes: 2 additions & 2 deletions boards/CUSTOM_ESP32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Include MicroPython ESP32 component.
get_filename_component(MICROPY_DIR "../../../lib/micropython" ABSOLUTE)
set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32)
include(${PROJECT_DIR}/main_esp32/CMakeLists.txt)
set(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32)
include(${MICROPY_PORT_DIR}/main/CMakeLists.txt)
21 changes: 19 additions & 2 deletions boards/CUSTOM_ESP32/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns: "~1.1.0"
espressif/tinyusb:
rules:
- if: "target in [esp32s2, esp32s3, esp32p4]"
git: https://github.com/micropython/tinyusb-espressif.git
version: cherrypick/dwc2_zlp_fix
espressif/esp_hosted:
rules:
- if: "target == esp32p4"
version: "2.7.0"
espressif/esp_wifi_remote:
rules:
- if: "target == esp32p4"
version: "0.15.2"
espressif/lan867x:
version: "~1.0.0"
rules:
- if: "target == esp32"
- if: "idf_version >=5.3"
idf:
version: ">=5.0.2"
version: ">=5.2.0"
1 change: 1 addition & 0 deletions boards/CUSTOM_ESP32/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(IDF_TARGET esp32)
set(SDKCONFIG_DEFAULTS
${MICROPY_PORT_DIR}/boards/sdkconfig.base
${MICROPY_PORT_DIR}/boards/sdkconfig.ble
${MICROPY_BOARD_DIR}/sdkconfig.board
)

# Set the user C modules to include in the build.
Expand Down
1 change: 1 addition & 0 deletions boards/CUSTOM_ESP32/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB.csv"
28 changes: 28 additions & 0 deletions boards/CUSTOM_ESP32_C6/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Top-level cmake file for building MicroPython on ESP32.
# Nothing in here needs to be customised, it will work for any board.

cmake_minimum_required(VERSION 3.12)

# Set the location of MicroPython, the esp32 port, and the board directory.
get_filename_component(PROJECT_DIR "../.." ABSOLUTE)
set(MICROPY_PORT_DIR ${PROJECT_DIR}/lib/micropython/ports/esp32)
get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE)

# Define the output sdkconfig so it goes in the build directory.
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)

# Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options).
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)

# Concatenate all sdkconfig files into a combined one for the IDF to use.
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
file(READ ${SDKCONFIG_DEFAULT} CONTENTS)
file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}")
endforeach()
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)

# Include main IDF cmake file and define the project.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(micropython)
39 changes: 39 additions & 0 deletions boards/CUSTOM_ESP32_C6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
This directory contains board definition files for a custom ESP32-C6 board.

These files are maintained for current MicroPython + ESP-IDF 5.x layout.

## Build

From the repository root (`custom_boards`):

```sh
cd lib/micropython
source tools/ci.sh
ci_esp32_idf_setup
# return to repo root
cd ../..

source lib/micropython/esp-idf/export.sh
cd boards/CUSTOM_ESP32_C6
idf.py fullclean
idf.py set-target esp32c6
idf.py build
```

## Flash

```sh
idf.py -p /dev/ttyUSB0 flash
# or
idf.py -p /dev/ttyACM0 flash
```

## Monitor serial output

```sh
idf.py -p /dev/ttyUSB0 monitor
# or
idf.py -p /dev/ttyACM0 monitor
```

Tip: if your serial device is different, replace `/dev/ttyUSB0` accordingly.
21 changes: 21 additions & 0 deletions boards/CUSTOM_ESP32_C6/dependencies.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
dependencies:
espressif/mdns:
component_hash: 46ee81d32fbf850462d8af1e83303389602f6a6a9eddd2a55104cb4c063858ed
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.1.0
idf:
source:
type: idf
version: 5.5.1
direct_dependencies:
- espressif/mdns
- idf
manifest_hash: 482087bc40f0e187795a9ef9ad08ef15a585b4cdabc296c715a9d19284622150
target: esp32c6
version: 2.0.0
4 changes: 4 additions & 0 deletions boards/CUSTOM_ESP32_C6/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Include MicroPython ESP32 component.
get_filename_component(MICROPY_DIR "../../../lib/micropython" ABSOLUTE)
set(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32)
include(${MICROPY_PORT_DIR}/main/CMakeLists.txt)
22 changes: 22 additions & 0 deletions boards/CUSTOM_ESP32_C6/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
dependencies:
espressif/mdns: "~1.1.0"
espressif/tinyusb:
rules:
- if: "target in [esp32s2, esp32s3, esp32p4]"
git: https://github.com/micropython/tinyusb-espressif.git
version: cherrypick/dwc2_zlp_fix
espressif/esp_hosted:
rules:
- if: "target == esp32p4"
version: "2.7.0"
espressif/esp_wifi_remote:
rules:
- if: "target == esp32p4"
version: "0.15.2"
espressif/lan867x:
version: "~1.0.0"
rules:
- if: "target == esp32"
- if: "idf_version >=5.3"
idf:
version: ">=5.2.0"
5 changes: 5 additions & 0 deletions boards/CUSTOM_ESP32_C6/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# include default manifest
include("$(PORT_DIR)/boards/manifest.py")

# include our own extra...
module("xxd.py", base_path="$(BOARD_DIR)/../../src/utils")
20 changes: 20 additions & 0 deletions boards/CUSTOM_ESP32_C6/mpconfigboard.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Define the chip variant.
set(IDF_TARGET esp32c6)

# Set the sdkconfig fragments.
set(SDKCONFIG_DEFAULTS
${MICROPY_PORT_DIR}/boards/sdkconfig.base
${MICROPY_PORT_DIR}/boards/sdkconfig.riscv
${MICROPY_PORT_DIR}/boards/sdkconfig.c6
${MICROPY_PORT_DIR}/boards/sdkconfig.ble
${MICROPY_BOARD_DIR}/sdkconfig.board
)

# Set the user C modules to include in the build.
set(USER_C_MODULES
${PROJECT_DIR}/src/cmodules/cexample/micropython.cmake
${PROJECT_DIR}/src/cmodules/cexample2/micropython.cmake
)

# Set the manifest file for frozen Python code.
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
2 changes: 2 additions & 0 deletions boards/CUSTOM_ESP32_C6/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define MICROPY_HW_BOARD_NAME "Custom ESP32-C6 board"
#define MICROPY_HW_MCU_NAME "ESP32-C6"
7 changes: 7 additions & 0 deletions boards/CUSTOM_ESP32_C6/partitions-4MiB.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Notes: the offset of the partition table itself is set in
# $IDF_PATH/components/partition_table/Kconfig.projbuild.
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 0x1F0000,
vfs, data, fat, 0x200000, 0x200000,
1 change: 1 addition & 0 deletions boards/CUSTOM_ESP32_C6/sdkconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB.csv"
Loading