Skip to content

Commit

Permalink
Fix mpy board (#138)
Browse files Browse the repository at this point in the history
* Remove unused var

* Define MicroPython board in separate device directory

* Use custom MH board def to make firmware

* Update gitignore

* Scripts import NON_DEVICE_FILES from parse_files

Previously, each script was hard-coded to exclude 'default.yml', but now they have been updated to check the constant 'NON_DEVICE_FILES' from the 'parse_files.py' script

This commit also includes a quick fix to TDECK/mpconfigboard.cmake, which points it at the new board definition

* Move misplaced partition file
  • Loading branch information
echo-lalia authored Sep 3, 2024
1 parent 9af7e8f commit f61f829
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 44 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Build directories
/MicroHydra

# Local config files
/.vscode
*.bak
/src/config.json

# Temporary files
*.bak

# Python cache files
__pycache__/
tools/__pycache__/
2 changes: 1 addition & 1 deletion devices/CARDPUTER/definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ features:
- bluetooth

mpy_arch: xtensawin
source_board: ESP32_GENERIC_S3
source_board: MICROHYDRA_GENERIC_S3
9 changes: 0 additions & 9 deletions devices/CARDPUTER/sdkconfig.board

This file was deleted.

2 changes: 1 addition & 1 deletion devices/TDECK/definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ features:
- spi_ram

mpy_arch: xtensawin
source_board: ESP32_GENERIC_S3
source_board: MICROHYDRA_GENERIC_S3
6 changes: 0 additions & 6 deletions devices/TDECK/manifest.py

This file was deleted.

6 changes: 3 additions & 3 deletions devices/TDECK/mpconfigboard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(SDKCONFIG_DEFAULTS
boards/sdkconfig.usb
boards/sdkconfig.ble
boards/sdkconfig.spiram_sx
boards/ESP32_GENERIC_S3/sdkconfig.board
boards/MICROHYDRA_GENERIC_S3/sdkconfig.board
)


Expand All @@ -18,12 +18,12 @@ set(SDKCONFIG_DEFAULTS
)

list(APPEND MICROPY_DEF_BOARD
MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM"
MICROPY_HW_BOARD_NAME="MicroHydra on TDeck with Octal-SPIRAM"
)

if(MICROPY_BOARD_VARIANT STREQUAL "FLASH_4M")
set(SDKCONFIG_DEFAULTS
${SDKCONFIG_DEFAULTS}
boards/ESP32_GENERIC_S3/sdkconfig.flash_4m
boards/MICROHYDRA_GENERIC_S3/sdkconfig.flash_4m
)
endif()
7 changes: 0 additions & 7 deletions devices/TDECK/partitions-8MiB.csv

This file was deleted.

2 changes: 1 addition & 1 deletion devices/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ features:
- keyboard

mpy_arch: xtensawin
source_board: ESP32_GENERIC_S3
source_board: MICROHYDRA_GENERIC_S3
File renamed without changes.
24 changes: 24 additions & 0 deletions devices/esp32_mpy_build/boards/MICROHYDRA_GENERIC_S3/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"deploy": [
"../deploy_s3.md"
],
"docs": "",
"features": [
"BLE",
"External Flash",
"External RAM",
"WiFi"
],
"images": [
"generic_s3.jpg"
],
"mcu": "esp32s3",
"product": "MicroHydra-ESP32-S3",
"thumbnail": "",
"url": "https://github.com/echo-lalia/MicroHydra",
"vendor": "Espressif",
"variants": {
"SPIRAM_OCT": "Support for Octal-SPIRAM",
"FLASH_4M": "4MiB flash"
}
}
9 changes: 9 additions & 0 deletions devices/esp32_mpy_build/boards/MICROHYDRA_GENERIC_S3/board.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The following files are firmware that should work on most ESP32-S3-based
boards with 4/8MiB of flash, including WROOM and MINI modules.

This firmware supports configurations with and without SPIRAM (also known as
PSRAM) and will auto-detect a connected SPIRAM chip at startup and allocate
the MicroPython heap accordingly. However if your board has Octal SPIRAM, then
use the "spiram-oct" variant.

If your board has 4MiB flash (including ESP32-S3FH4R2 based ones with embedded flash), then use the "flash-4m" build.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(SDKCONFIG_DEFAULTS
boards/sdkconfig.usb
boards/sdkconfig.ble
boards/sdkconfig.spiram_sx
boards/ESP32_GENERIC_S3/sdkconfig.board
boards/MICROHYDRA_GENERIC_S3/sdkconfig.board
)

if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM_OCT")
Expand All @@ -18,7 +18,7 @@ if(MICROPY_BOARD_VARIANT STREQUAL "SPIRAM_OCT")
)

list(APPEND MICROPY_DEF_BOARD
MICROPY_HW_BOARD_NAME="Generic ESP32S3 module with Octal-SPIRAM"
MICROPY_HW_BOARD_NAME="MicroHydra on ESP32S3 with Octal-SPIRAM"
)
endif()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef MICROPY_HW_BOARD_NAME
// Can be set by mpconfigboard.cmake.
#define MICROPY_HW_BOARD_NAME "MicroHydra on ESP32S3"
#endif
#define MICROPY_HW_MCU_NAME "ESP32S3"

// Enable UART REPL for modules that have an external USB-UART and don't use native USB.
#define MICROPY_HW_ENABLE_UART_REPL (1)

#define MICROPY_HW_I2C0_SCL (9)
#define MICROPY_HW_I2C0_SDA (8)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="boards/TDECK/partitions-8MiB.csv"
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="MH-partitions-8MiB.csv"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=

CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-4MiB.csv"
4 changes: 2 additions & 2 deletions tools/clean_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import shutil

from parse_files import NON_DEVICE_FILES



Expand All @@ -27,7 +27,7 @@ def main():
# parse devices into list of Device objects
devices = []
for filepath in os.listdir(DEVICE_PATH):
if filepath != 'default.yml':
if filepath not in NON_DEVICE_FILES:
devices.append(Device(filepath))


Expand Down
5 changes: 3 additions & 2 deletions tools/compile_firmwares.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
Script tries to setup esp-idf for building MicroPython.
This script mainly calls another build script, for building MicroPython firmware.
"""

import os
import yaml
import argparse
import subprocess
import shutil
from parse_files import NON_DEVICE_FILES


# argparser stuff:
Expand Down Expand Up @@ -54,7 +55,7 @@ def main():
# parse devices into list of Device objects
devices = []
for filepath in os.listdir(DEVICE_PATH):
if filepath != 'default.yml':
if filepath not in NON_DEVICE_FILES:
devices.append(Device(filepath))

# Run build script, passing each target device name.
Expand Down
3 changes: 2 additions & 1 deletion tools/compile_hydra_mpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import subprocess
import shutil
from parse_files import NON_DEVICE_FILES


# argparser stuff:
Expand Down Expand Up @@ -55,7 +56,7 @@ def main():
# parse devices into list of Device objects
devices = []
for filepath in os.listdir(DEVICE_PATH):
if filepath != 'default.yml':
if filepath not in NON_DEVICE_FILES:
devices.append(Device(filepath))


Expand Down
14 changes: 12 additions & 2 deletions tools/create_frozen_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import subprocess
import shutil
from parse_files import NON_DEVICE_FILES


# argparser stuff:
Expand All @@ -19,20 +20,24 @@

PARSER.add_argument('-d', '--dest', help='Path to MicroPython boards folder.')
PARSER.add_argument('-D', '--devices', help='Path to device definition folder.')
PARSER.add_argument('-M', '--micropython', help='Path to MicroPython source.')
PARSER.add_argument('-v', '--verbose', action='store_true')
SCRIPT_ARGS = PARSER.parse_args()

DEST_PATH = SCRIPT_ARGS.dest
DEVICE_PATH = SCRIPT_ARGS.devices
VERBOSE = SCRIPT_ARGS.verbose
MP_PATH = SCRIPT_ARGS.micropython


# set defaults for args not given:
CWD = os.getcwd()
OG_DIRECTORY = CWD

if MP_PATH is None:
MP_PATH = os.path.join(CWD, 'MicroPython')
if DEST_PATH is None:
DEST_PATH = os.path.join(CWD, 'MicroPython', 'ports', 'esp32', 'boards')
DEST_PATH = os.path.join(MP_PATH, 'ports', 'esp32', 'boards')
if DEVICE_PATH is None:
DEVICE_PATH = os.path.join(CWD, 'devices')

Expand All @@ -45,10 +50,15 @@ def main():
and all of the functions/classes used here are defined below.
"""

# start by copying over custom MicroHydra build files
custom_build_path = os.path.join(DEVICE_PATH, 'esp32_mpy_build')
mpy_esp32_path = os.path.join(MP_PATH, 'ports', 'esp32')
shutil.copytree(custom_build_path, mpy_esp32_path, dirs_exist_ok=True)

# parse devices into list of Device objects
devices = []
for filepath in os.listdir(DEVICE_PATH):
if filepath != 'default.yml':
if filepath not in NON_DEVICE_FILES:
devices.append(Device(filepath))


Expand Down
4 changes: 2 additions & 2 deletions tools/generate_default_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml
import os
from collections import Counter

from parse_files import NON_DEVICE_FILES


DEVICE_PATH = "devices"
Expand All @@ -27,7 +27,7 @@ def fill_device_data():
all_file_data = []

for dir_entry in os.scandir(DEVICE_PATH):
if dir_entry.is_dir():
if dir_entry.is_dir() and dir_entry.name not in NON_DEVICE_FILES:

for subdir_entry in os.scandir(dir_entry):
if subdir_entry.name == "definition.yml":
Expand Down
10 changes: 7 additions & 3 deletions tools/parse_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@



# These file/dir names in `devices/` should not define new devices
NON_DEVICE_FILES = ['default.yml', 'esp32_mpy_build', 'README.md']


# Designate unicode "noncharacter" as representation of completed mh conditional
# 1-byte noncharacters = U+FDD0..U+FDEF, choosing from these arbitrarily.
CONDITIONAL_PARSED_FLAG = chr(0xFDD1)
CONDITIONAL_PARSED_ORIGINAL_DELIMITER = chr(0xFDD2)
CONDITIONAL_PARSED_TEMP_FLAG = chr(0xFDD3)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -143,7 +146,7 @@ def main():
# parse devices into list of Device objects
devices = []
for filepath in os.listdir(DEVICE_PATH):
if filepath != 'default.yml': # TODO: why not only include directories?
if filepath not in NON_DEVICE_FILES:
devices.append(Device(filepath))

# print status information
Expand Down Expand Up @@ -825,4 +828,5 @@ def exclude_given_files(file_list:list, exclude_list:list):


# run script
main()
if __name__ == "__main__":
main()

0 comments on commit f61f829

Please sign in to comment.