Skip to content

Commit 208601c

Browse files
author
Michael O'Cleirigh
committed
Add support for building esp32-s2 with spiram
1 parent d5f32c7 commit 208601c

File tree

8 files changed

+246
-2
lines changed

8 files changed

+246
-2
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
name: ESP32 S2
3+
4+
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule
5+
on:
6+
push:
7+
pull_request:
8+
paths-ignore:
9+
- 'examples/**'
10+
- 'README.md'
11+
- 'ci/*unix*.sh'
12+
- '.github/workflows/build_unix.yml'
13+
14+
jobs:
15+
tensorflow_micropython_esp32s2_build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v2
21+
- name: Prepare to Build Tensorflow Micropython Firmware for ESP32
22+
run: |
23+
git submodule init
24+
git submodule update --recursive
25+
cd micropython
26+
git submodule update --init lib/axtls
27+
git submodule update --init lib/berkeley-db-1.xx
28+
cd ports/esp32
29+
make BOARD= submodules
30+
cd ../../..
31+
- name: Get Cache Keys
32+
# later get this like this: git ls-remote --heads https://github.com/espressif/esp-idf
33+
# this commit is hard-coded in micropython/tools/ci.sh
34+
run: |
35+
IDF_COMMIT=5bb59b00e72f8f91eb24d8c65bf9a7ea2b8a4f5f
36+
echo "esp-idf-commit=$IDF_COMMIT" >> $GITHUB_ENV
37+
TFLM_COMMIT=$(git submodule status tensorflow | awk '{print ($1)}')
38+
echo "tflm-commit=$TFLM_COMMIT" >> $GITHUB_ENV
39+
# - name: Cache esp-idf
40+
# id: cache-esp-idf
41+
# uses: actions/cache@v2
42+
# env:
43+
# cache-name: cache-esp-idf
44+
# with:
45+
# path: ./esp-idf
46+
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.esp-idf-commit }}
47+
- name: Setup IDF
48+
# if: steps.cache-esp-idf.outputs.cache-hit != 'true'
49+
run: |
50+
source ./micropython/tools/ci.sh && ci_esp32_idf44_setup
51+
- name: Cache tflm
52+
id: cache-tflm
53+
uses: actions/cache@v2
54+
env:
55+
cache-name: cache-tflm
56+
with:
57+
path: ./micropython-modules/microlite/tflm
58+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.tflm-commit }}
59+
- name: Setup Build for Tensorflow
60+
if: steps.cache-tflm.outputs.cache-hit != 'true'
61+
run: |
62+
63+
source ./esp-idf/export.sh
64+
65+
pip3 install Pillow
66+
pip3 install Wave
67+
68+
echo "Regenerating microlite/tfm directory"
69+
rm -rf ./micropython-modules/microlite/tflm
70+
71+
cd ./tensorflow
72+
73+
../micropython-modules/microlite/prepare-tflm-esp.sh
74+
75+
- name: Build micropython cross compiler
76+
run: |
77+
source ./esp-idf/export.sh
78+
cd ./micropython
79+
echo "make -C mpy-cross V=1 clean all"
80+
make -C mpy-cross V=1 clean all
81+
82+
- name: Build ESP32 S2 with SPIRAM
83+
run: |
84+
source ./esp-idf/export.sh
85+
86+
echo "cd ./boards/esp32/MICROLITE_S2_SPIRAM"
87+
cd ./boards/esp32/MICROLITE_S2_SPIRAM
88+
89+
echo "Building MICROLITE_S2_SPIRAM"
90+
rm -rf builds
91+
idf.py clean build
92+
93+
94+
95+
- name: Archive ESP32-MICROLITE_S2_SPIRAM firmware
96+
uses: actions/upload-artifact@v2
97+
with:
98+
name: microlite-esp3223-spiram-firmware
99+
path: |
100+
boards/esp32/MICROLITE_S2_SPIRAM/build/bootloader/bootloader.bin
101+
boards/esp32/MICROLITE_S2_SPIRAM/build/partition_table/partition-table.bin
102+
boards/esp32/MICROLITE_S2_SPIRAM/build/micropython.bin
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Top-level cmake file for building MicroPython on ESP32.
2+
# Nothing in here needs to be customised, it will work for any board.
3+
4+
cmake_minimum_required(VERSION 3.12)
5+
6+
# Set the location of MicroPython, the esp32 port, and the board directory.
7+
get_filename_component(PROJECT_DIR "../../.." ABSOLUTE)
8+
set(MICROPY_PORT_DIR ${PROJECT_DIR}/micropython/ports/esp32)
9+
get_filename_component(MICROPY_BOARD_DIR "." ABSOLUTE)
10+
11+
message (STATUS "PROJECT_DIR=${PROJECT_DIR}")
12+
message (STATUS "MICROPY_PORT_DIR=${MICROPY_PORT_DIR}")
13+
message (STATUS "MICROPY_BOARD_DIR=${MICROPY_BOARD_DIR}")
14+
15+
# Define the output sdkconfig so it goes in the build directory.
16+
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
17+
18+
# Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options).
19+
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
20+
21+
# Concatenate all sdkconfig files into a combined one for the IDF to use.
22+
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
23+
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
24+
file(READ ${SDKCONFIG_DEFAULT} CONTENTS)
25+
file(APPEND ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "${CONTENTS}")
26+
endforeach()
27+
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
28+
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)
29+
30+
# Include main IDF cmake file and define the project.
31+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
32+
project(micropython)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Program your board using the esptool.py program, found [here](https://github.com/espressif/esptool).
2+
3+
To flash or erase your TinyS2, you have to first put it into download mode.
4+
To do this, follow these steps:
5+
6+
- Press and hold the [BOOT] button
7+
- Press and release the [RESET] button
8+
- Release the [BOOT] button
9+
10+
Now the board is in download mode and the native USB will have enumerated as a serial device.
11+
12+
If you are putting MicroPython on your board for the first time then you should
13+
first erase the entire flash using:
14+
15+
### Linux
16+
```bash
17+
esptool.py --chip esp32s2 --port /dev/ttyACM0 erase_flash
18+
```
19+
20+
### Mac
21+
```bash
22+
esptool.py --chip esp32s2 --port /dev/cu.usbmodem01 erase_flash
23+
```
24+
25+
#### Windows
26+
Change (X) to whatever COM port is being used by the board
27+
```bash
28+
esptool --chip esp32s2 --port COM(X) erase_flash
29+
```
30+
31+
Now download the version of the firmware you would like to install from the options below,
32+
then use the following command to program the firmware starting at address 0x1000,
33+
remembering to replace `tinys2-micropython-firmware-version.bin` with the name of the
34+
firmware you just downloaded:
35+
36+
#### Linux
37+
```bash
38+
esptool.py --chip esp32s2 --port /dev/ttyACM0 write_flash -z 0x1000 tinys2-micropython-firmware-version.bin
39+
```
40+
41+
#### Mac
42+
```bash
43+
esptool.py --chip esp32s2 --port /dev/cu.usbmodem01 write_flash -z 0x1000 tinys2-micropython-firmware-version.bin
44+
```
45+
46+
#### Windows
47+
Change (X) to whatever COM port is being used by the board
48+
```bash
49+
esptool --chip esp32s2 --port COM(X) write_flash -z 0x1000 tinys2-micropython-firmware-version.bin
50+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Include MicroPython ESP32 component.
2+
3+
get_filename_component(CURRENT_DIR "." ABSOLUTE)
4+
5+
message(STATUS "microlite/main/cmake: CURRENT_DIR=${CURRENT_DIR}")
6+
7+
get_filename_component(MICROPY_DIR "../../../../micropython" ABSOLUTE)
8+
9+
10+
message (STATUS "microlite/main/cmake: MICROPY_DIR=${MICROPY_DIR}")
11+
12+
set(PROJECT_DIR ${MICROPY_DIR}/ports/esp32)
13+
include(${PROJECT_DIR}/main/CMakeLists.txt)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(IDF_TARGET esp32s2)
2+
set(SDKCONFIG_DEFAULTS
3+
${MICROPY_PORT_DIR}/boards/sdkconfig.base
4+
${MICROPY_PORT_DIR}/boards/sdkconfig.spiram_sx
5+
# ${MICROPY_PORT_DIR}/boards/sdkconfig.usb
6+
${MICROPY_BOARD_DIR}/sdkconfig.board
7+
)
8+
9+
message (STATUS "mpconfigboard.cmake: PROJECT_DIR=${PROJECT_DIR}")
10+
11+
set(USER_C_MODULES
12+
${PROJECT_DIR}/micropython-modules/micropython.cmake
13+
)
14+
15+
if(NOT MICROPY_FROZEN_MANIFEST)
16+
set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py)
17+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#define MICROPY_HW_BOARD_NAME "ESP32S2 Microlite"
2+
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
3+
4+
#define MICROPY_PY_BLUETOOTH (0)
5+
#define MICROPY_HW_ENABLE_SDCARD (0)
6+
7+
// these were from the um_tiny s2 double check if they match the ESP32S2DEVKITM1R
8+
// #define MICROPY_HW_I2C0_SCL (9)
9+
// #define MICROPY_HW_I2C0_SDA (8)
10+
11+
// #define MICROPY_HW_SPI1_MOSI (35)
12+
// #define MICROPY_HW_SPI1_MISO (36)
13+
// #define MICROPY_HW_SPI1_SCK (37)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CONFIG_FLASHMODE_QIO=y
2+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
3+
CONFIG_USB_AND_UART=y
4+
# LWIP
5+
# CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2"
6+
# end of LWIP
7+
CONFIG_PARTITION_TABLE_CUSTOM=y
8+
# cwd is boards/esp32/MICROLITE_S2_SPIRAM
9+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="../../../micropython/ports/esp32/partitions.csv"

micropython-modules/microlite/micropython.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ if(IDF_TARGET STREQUAL "esp32")
3232
set(MICROLITE_PLATFORM "ESP32")
3333
endif()
3434

35+
if(IDF_TARGET STREQUAL "esp32s2")
36+
set(MICROLITE_PLATFORM "ESP32S2")
37+
endif()
38+
3539
if(IDF_TARGET STREQUAL "esp32s3")
3640
set(MICROLITE_PLATFORM "ESP32S3")
3741
endif()
@@ -46,7 +50,8 @@ add_library(microlite INTERFACE)
4650

4751
if (MICROLITE_PLATFORM STREQUAL "ESP32" OR
4852
MICROLITE_PLATFORM STREQUAL "ESP32S3" OR
49-
MICROLITE_PLATFORM STREQUAL "ESP32C3")
53+
MICROLITE_PLATFORM STREQUAL "ESP32C3" OR
54+
MICROLITE_PLATFORM STREQUAL "ESP32S2")
5055

5156
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
5257
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
@@ -60,7 +65,10 @@ endif()
6065
# DEPENDS MICROPY_FORCE_BUILD
6166
# )
6267

63-
if (MICROLITE_PLATFORM STREQUAL "ESP32" OR MICROLITE_PLATFORM STREQUAL "ESP32S3" OR MICROLITE_PLATFORM STREQUAL "ESP32C3")
68+
if (MICROLITE_PLATFORM STREQUAL "ESP32" OR
69+
MICROLITE_PLATFORM STREQUAL "ESP32S3" OR
70+
MICROLITE_PLATFORM STREQUAL "ESP32C3" OR
71+
MICROLITE_PLATFORM STREQUAL "ESP32S2")
6472
set (TF_MICROLITE_LOG
6573
${CMAKE_CURRENT_LIST_DIR}/tflm/tensorflow/lite/micro/debug_log.cpp
6674
${CMAKE_CURRENT_LIST_DIR}/tflm/tensorflow/lite/micro/micro_time.cpp

0 commit comments

Comments
 (0)