Skip to content

Commit d83c639

Browse files
added build_firmware_uf2 workflow, build_and_upload.py improvements
build_and_upload.py: - --jobs option, to override/disable parallel make jobs - fixed `no_upload` to not require pyserial/serial packages - fixed a newline being included in the firmware filename
1 parent 45d78d6 commit d83c639

3 files changed

Lines changed: 89 additions & 14 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# this follows "Building on Linux for RP2350" in README.md
2+
3+
name: Build Firmware (.uf2)
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
micropython-repo:
9+
description: 'repo to clone as mp-thumby'
10+
required: true
11+
default: TinyCircuits/micropython
12+
type: string
13+
micropython-ref:
14+
description: 'commit to checkout in mp-thumby'
15+
required: true
16+
default: engine
17+
type: string
18+
19+
jobs:
20+
build_firmware_uf2:
21+
runs-on: ubuntu-22.04
22+
steps:
23+
- name: Install build chain dependencies (steps 1-2)
24+
# https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#page=33
25+
run: |
26+
# sudo apt update
27+
sudo apt install -y git python3 cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential g++ libstdc++-arm-none-eabi-newlib
28+
29+
- name: Clone TinyCircuits MicroPython (steps 3-6)
30+
uses: actions/checkout@v4
31+
with:
32+
repository: ${{ inputs.micropython-repo }}
33+
path: mp-thumby
34+
ref: ${{ inputs.micropython-ref }}
35+
submodules: recursive
36+
37+
- name: Switch engine repo to current commit
38+
uses: actions/checkout@v4
39+
with:
40+
path: mp-thumby/TinyCircuits-Tiny-Game-Engine
41+
submodules: recursive
42+
43+
- name: Setup cross compiler (steps 7-8)
44+
run: |
45+
cd mp-thumby/mpy-cross
46+
make
47+
48+
- name: Setup rp2 port (steps 9-10)
49+
run: |
50+
cd mp-thumby/ports/rp2
51+
make submodules
52+
# make clean
53+
54+
- name: Run the custom Python build script (11-12)
55+
# disabling parallel jobs, because i regularly saw a race that resulted
56+
# in pwm.pio.h not being generated in time -gg
57+
run: |
58+
cd mp-thumby/TinyCircuits-Tiny-Game-Engine
59+
python3 -m pip install psutil
60+
python3 build_and_upload.py -j1 no_upload
61+
62+
- name: Create firmware artifact
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: firmware (.uf2)
66+
path: mp-thumby/ports/rp2/build-THUMBY_COLOR/firmware_*.uf2
67+
if-no-files-found: error

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The engine has been tested on and ported to the following platforms:
3737
# Building on Linux for RP2350
3838
1. Update package list: `sudo apt update`
3939
2. Install build chain dependencies (https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf#page=33): `sudo apt install git python3 cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential g++ libstdc++-arm-none-eabi-newlib`
40-
3. Clone TinyCircuits MicroPython: `git https://github.com/TinyCircuits/micropython.git mp-thumby`
40+
3. Clone TinyCircuits MicroPython: `git clone https://github.com/TinyCircuits/micropython.git mp-thumby`
4141
4. `cd` into MicroPython: `cd mp-thumby`
4242
5. Checkout engine branch: `git checkout engine`
4343
6. Init the engine submodule: `git submodule update --init --recursive`

build_and_upload.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
import psutil
77
import subprocess
88
import datetime
9+
import argparse
910
from subprocess import Popen, PIPE, CalledProcessError
1011

11-
# python -m pip install pyserial
12-
# python -m pip install serial
13-
import serial
14-
import serial.tools.list_ports
15-
1612

1713
# Helper for running commands and processing output
1814
def execute(cmd):
@@ -37,20 +33,26 @@ def get_drives():
3733

3834

3935
# ### Step 1: Get arguments
40-
arguments = sys.argv[1:]
41-
upload = True
42-
43-
if len(arguments) > 0 and arguments[0] == "clean":
36+
parser = argparse.ArgumentParser()
37+
parser.add_argument('-j', '--jobs', type=int, default=8, help='(default: 8) simultaneous jobs (passed to make)')
38+
parser.add_argument('mode', choices=['default', 'no_upload', 'clean'], default='default')
39+
args = parser.parse_args()
40+
41+
if args.mode == 'default':
42+
upload = True
43+
elif args.mode == 'no_upload':
44+
upload = False
45+
elif args.mode == 'clean':
4446
execute(['make', '-C', '../ports/rp2', 'clean', 'BOARD=THUMBY_COLOR'])
4547
print("\n\nSUCCESS: Done cleaning rp2 port!\n")
4648
exit(1)
47-
elif len(arguments) > 0 and arguments[0] == "no_upload":
48-
upload = False
49+
else:
50+
assert False, f'unknown mode {args.mode}' # argparse should have caught this
4951

5052

5153
# ### Step 2: Get the date of the last commit and bake into firmware
5254
firmware_date_file = open("src/firmware_date.h", "w")
53-
commit_id = os.popen('git rev-parse --short HEAD').read()
55+
commit_id = os.popen('git rev-parse --short HEAD').read().strip()
5456
commit_date = os.popen('git log -1 --format="%cd" --date=iso').read()
5557
commit_date = commit_date.splitlines()
5658
commit_date = commit_date[0]
@@ -68,7 +70,7 @@ def get_drives():
6870

6971
# ### Step 3: Build the firmware (which will freeze everything in `modules`)
7072
print("\n\nBuilding rp2 port...\n")
71-
execute(['make', '-C', '../ports/rp2', '-j8', 'BOARD=THUMBY_COLOR', 'USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine/src/micropython.cmake'])
73+
execute(['make', '-C', '../ports/rp2', f'-j{args.jobs}', 'BOARD=THUMBY_COLOR', 'USER_C_MODULES=../../TinyCircuits-Tiny-Game-Engine/src/micropython.cmake'])
7274
print("\n\nDone building rp2 port!\n")
7375

7476
# Rename UF2 if want to
@@ -88,6 +90,12 @@ def get_drives():
8890
if(upload is False):
8991
exit(0)
9092

93+
94+
# python -m pip install pyserial
95+
# python -m pip install serial
96+
import serial
97+
import serial.tools.list_ports
98+
9199
# ### Step 5: Assume that the port is plugged in and may be running a program, connect to it
92100
# end program with ctrl-c, and put into BOOTLOADER mode for upload
93101
print("Looking for serial port to reset...")

0 commit comments

Comments
 (0)