Skip to content

Commit 6d157e6

Browse files
Merge pull request #82 from makers-for-life/dev
Add automation scripts
2 parents 6aa9896 + 460ecc6 commit 6d157e6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ arduino-cli upload --port {SERIAL_PORT} --fqbn STMicroelectronics:stm32:Nucleo_6
6060

6161
_Make sure to replace {SERIAL_PORT} with your serial port, which should begin with `/dev/`._
6262

63+
## Scripts
64+
65+
A few scripts are available, eg. to automate repeated manual actions:
66+
67+
1. **Compile & Flash**: `./scripts/compile_and_flash.sh` (compiles firmware and flashes it over the plugged STM32 programmer);
68+
6369
## Configuration
6470

6571
The configuration options can be found in the following files:

scripts/compile_and_flash.sh

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
ABSPATH=$(cd "$(dirname "$0")"; pwd)
4+
BASE_DIR="$ABSPATH/../"
5+
6+
pushd "$BASE_DIR" > /dev/null
7+
# Acquire serial port first
8+
SERIAL_PORT=$(arduino-cli board list | grep "Serial Port (USB)" | cut -d ' ' -f 1 | head -n 1)
9+
10+
if [ ! -z "$SERIAL_PORT" ]; then
11+
echo "Detected STM32 programmer on serial port: $SERIAL_PORT"
12+
echo "Will proceed."
13+
14+
# Hold on a bit (give the user a chance to cancel)
15+
sleep 1
16+
17+
# Clear out built code
18+
echo ">> [1] Clearing old builds..."
19+
20+
sleep 0.5
21+
22+
rm -f ./output/* || exit 1
23+
24+
echo "Old builds cleared."
25+
26+
# Compile new firmware
27+
echo ">> [2] Compiling new firmware..."
28+
29+
sleep 0.5
30+
31+
arduino-cli compile --fqbn STMicroelectronics:stm32:Nucleo_64:opt=o3std,pnum=NUCLEO_F411RE --verbose srcs/respirator.cpp --output output/respirator-production || exit 1
32+
33+
# Flash new firmware
34+
echo ">> [3] Flashing new firmware..."
35+
36+
sleep 0.5
37+
38+
arduino-cli upload --port "$SERIAL_PORT" --fqbn STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE,upload_method=swdMethod --input output/respirator-production || exit 1
39+
40+
sleep 0.5
41+
42+
echo "Success: All done. The ventilator will boot using the new firmware now."
43+
else
44+
echo "Error: STM32 programmer device not detected!"
45+
46+
exit 1
47+
fi
48+
popd > /dev/null
49+
50+
exit 0

0 commit comments

Comments
 (0)