Skip to content

Commit f59f025

Browse files
committed
Use official STM32 SDK for stm32 builds instead of libopencm3
AtomVM now supports the following STM32 families: - stm32f2xx - stm32f4xx (was supported by libopencm3) - stm32f7xx (was supported by libopencm3) - stm32g0xx - stm32g4xx - stm32h5xx - stm32h7xx - stm32l4xx - stm32l5xx - stm32u3xx - stm32wbxx Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 155da97 commit f59f025

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4680
-822
lines changed

.github/workflows/stm32-build.yaml

Lines changed: 142 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ on:
1414
- 'CMakeModules/**'
1515
- 'src/platforms/stm32/**'
1616
- 'src/libAtomVM/**'
17+
- 'libs/**'
1718
pull_request:
1819
paths:
1920
- '.github/workflows/stm32-build.yaml'
2021
- 'CMakeLists.txt'
2122
- 'CMakeModules/**'
2223
- 'src/platforms/stm32/**'
2324
- 'src/libAtomVM/**'
25+
- 'libs/**'
2426

2527
concurrency:
2628
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }}
@@ -34,17 +36,74 @@ jobs:
3436
contents: read
3537
security-events: write
3638

37-
steps:
38-
- uses: actions/cache@v4
39-
id: builddeps-cache
40-
with:
41-
path: |
42-
/home/runner/libopencm3
43-
key: ${{ runner.os }}-build-deps
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
device:
43+
- stm32f407vgt6
44+
- stm32f411ceu6
45+
- stm32f429zit6
46+
- stm32h743vit6
47+
- stm32h743zit6
48+
- stm32u585ait6q
49+
- stm32wb55rg
50+
- stm32h562rgt6
51+
- stm32f746zgt6
52+
- stm32g474ret6
53+
- stm32l476rgt6
54+
- stm32l562qei6
55+
- stm32f207zgt6
56+
- stm32u375rgt6
57+
- stm32g0b1ret6
58+
include:
59+
- device: stm32f407vgt6
60+
max_size: 524288
61+
renode_platform: stm32f4.repl
62+
avm_address: "0x08080000"
63+
- device: stm32f411ceu6
64+
max_size: 393216
65+
renode_platform: stm32f4.repl
66+
avm_address: "0x08060000"
67+
- device: stm32f429zit6
68+
max_size: 524288
69+
- device: stm32h743vit6
70+
max_size: 524288
71+
renode_platform: stm32h743.repl
72+
avm_address: "0x08080000"
73+
- device: stm32h743zit6
74+
max_size: 524288
75+
- device: stm32u585ait6q
76+
max_size: 524288
77+
- device: stm32wb55rg
78+
max_size: 524288
79+
- device: stm32h562rgt6
80+
max_size: 524288
81+
- device: stm32f746zgt6
82+
max_size: 524288
83+
renode_platform: stm32f746.repl
84+
avm_address: "0x08080000"
85+
- device: stm32g474ret6
86+
max_size: 393216
87+
- device: stm32l476rgt6
88+
max_size: 524288
89+
- device: stm32l562qei6
90+
max_size: 393216
91+
renode_platform: stm32l562.repl
92+
avm_address: "0x08060000"
93+
- device: stm32f207zgt6
94+
max_size: 524288
95+
- device: stm32u375rgt6
96+
max_size: 524288
97+
- device: stm32g0b1ret6
98+
max_size: 393216
99+
renode_platform: stm32g0b1.repl
100+
avm_address: "0x08060000"
44101

102+
steps:
45103
- uses: erlef/setup-beam@v1
46104
with:
47-
otp-version: "27"
105+
otp-version: "28"
106+
rebar3-version: "3.25.1"
48107
hexpm-mirrors: |
49108
https://builds.hex.pm
50109
https://repo.hex.pm
@@ -54,42 +113,91 @@ jobs:
54113
run: sudo apt update
55114

56115
- name: "Install deps"
57-
run: sudo apt install -y cmake gperf gcc-arm-none-eabi
116+
run: sudo apt install -y cmake ninja-build gperf python3-pip && pip3 install meson
58117

59-
- name: Checkout and build libopencm3
60-
if: ${{ steps.builddeps-cache.outputs.cache-hit != 'true' }}
61-
working-directory: /home/runner
118+
- name: "Install ARM GNU Toolchain"
62119
run: |
63-
set -euo pipefail
64-
cd /home/runner
65-
test -d libopencm3 && rm -fr libopencm3
66-
git clone https://github.com/libopencm3/libopencm3.git -b v0.8.0
67-
cd libopencm3
68-
make
120+
wget -q https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi.tar.xz
121+
tar xJf arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi.tar.xz -C /opt
122+
echo "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi/bin" >> $GITHUB_PATH
69123
70124
- name: Checkout repo
71125
uses: actions/checkout@v4
72126

73-
- name: "Git config safe.directory for codeql"
74-
run: git config --global --add safe.directory /__w/AtomVM/AtomVM
75-
76-
- name: "Initialize CodeQL"
77-
uses: github/codeql-action/init@v4
78-
with:
79-
languages: 'cpp'
80-
build-mode: manual
81-
queries: +./code-queries/term-to-non-term-func.ql,./code-queries/non-term-to-term-func.ql,./code-queries/mismatched-atom-string-length.ql,./code-queries/mismatched-free-type.ql,./code-queries/term-use-after-gc.ql
82-
83-
- name: Build
127+
- name: "Build for ${{ matrix.device }}"
84128
shell: bash
85129
working-directory: ./src/platforms/stm32/
86130
run: |
87131
set -euo pipefail
88132
mkdir build
89133
cd build
90-
# -DAVM_WARNINGS_ARE_ERRORS=ON
91-
cmake .. -DCMAKE_TOOLCHAIN_FILE=cmake/arm-toolchain.cmake -DLIBOPENCM3_DIR=/home/runner/libopencm3
92-
make -j
134+
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/arm-toolchain.cmake -DDEVICE=${{ matrix.device }}
135+
cmake --build .
136+
137+
- name: "Check firmware size for ${{ matrix.device }}"
138+
shell: bash
139+
working-directory: ./src/platforms/stm32/build
140+
run: |
141+
set -euo pipefail
142+
ELF="AtomVM-${{ matrix.device }}.elf"
143+
SIZES=$(arm-none-eabi-size "$ELF" | tail -1)
144+
TEXT=$(echo "$SIZES" | awk '{print $1}')
145+
DATA=$(echo "$SIZES" | awk '{print $2}')
146+
FLASH_USED=$((TEXT + DATA))
147+
MAX=${{ matrix.max_size }}
148+
echo "Firmware flash usage: ${FLASH_USED} bytes ($(( FLASH_USED / 1024 )) KB)"
149+
echo "Flash limit: ${MAX} bytes ($(( MAX / 1024 )) KB)"
150+
if [ "$FLASH_USED" -gt "$MAX" ]; then
151+
echo "::error::Firmware too large: ${FLASH_USED} bytes exceeds ${MAX} byte limit for ${{ matrix.device }}"
152+
exit 1
153+
fi
154+
echo "OK: ${FLASH_USED} / ${MAX} bytes ($(( FLASH_USED * 100 / MAX ))% used)"
155+
156+
- name: Build host AtomVM and test AVMs
157+
if: matrix.renode_platform
158+
run: |
159+
set -euo pipefail
160+
mkdir build-host
161+
cd build-host
162+
cmake .. -G Ninja
163+
cmake --build . -t stm32_boot_test stm32_gpio_test
164+
165+
- name: Install Renode
166+
if: matrix.renode_platform
167+
run: |
168+
set -euo pipefail
169+
mkdir -p renode-portable
170+
wget -qO- https://builds.renode.io/renode-latest.linux-portable.tar.gz \
171+
| tar -xzf - -C renode-portable --strip-components=1
172+
echo "$PWD/renode-portable" >> $GITHUB_PATH
173+
pip install -r renode-portable/tests/requirements.txt
93174
94-
- name: "Perform CodeQL Analysis"
95-
uses: github/codeql-action/analyze@v4
175+
- name: Run Renode boot test
176+
if: matrix.renode_platform
177+
run: |
178+
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
179+
if [ -f "$LOCAL_REPL" ]; then
180+
PLATFORM="@$PWD/$LOCAL_REPL"
181+
else
182+
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
183+
fi
184+
renode-test src/platforms/stm32/tests/renode/stm32_boot_test.robot \
185+
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
186+
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_boot_test.avm \
187+
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
188+
--variable PLATFORM:$PLATFORM
189+
190+
- name: Run Renode GPIO test
191+
if: matrix.renode_platform
192+
run: |
193+
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
194+
if [ -f "$LOCAL_REPL" ]; then
195+
PLATFORM="@$PWD/$LOCAL_REPL"
196+
else
197+
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
198+
fi
199+
renode-test src/platforms/stm32/tests/renode/stm32_gpio_test.robot \
200+
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
201+
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_gpio_test.avm \
202+
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
203+
--variable PLATFORM:$PLATFORM

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7070
- Added initial support for ESP32C5 and ESP32C61
7171
- Added `Range:size/1`
7272
- Added missing `ledc` functions for esp32 platform
73+
- Added support for 10 new STM32 families by switching to STM32 official SDK
7374

7475
### Changed
7576

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ add_subdirectory(tools/uf2tool)
8686
if (NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
8787
add_custom_target(dialyzer COMMENT "Run dialyzer")
8888
add_subdirectory(libs)
89+
add_subdirectory(src/platforms/stm32/tests/test_erl_sources)
8990
if(NOT AVM_BUILD_RUNTIME_ONLY)
9091
add_subdirectory(examples)
9192
add_subdirectory(doc)

README.Md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Supported Platforms
1717

1818
* Linux, macOS, FreeBSD, DragonFly ([generic_unix](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-on-the-generic-unix-platform))
1919
* ESP32 SoC (with IDF/FreeRTOS, see [esp32](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-on-the-esp32-platform))
20-
* STM32 MCUs (with LibOpenCM3, see [stm32](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-on-the-stm32-platform))
20+
* STM32 MCUs (with official ST HAL/LL SDK, see [stm32](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-on-the-stm32-platform))
2121
* Raspberry Pi Pico and Pico 2 (see [rp2](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-on-the-raspberry-pi-pico-platform))
2222
* Browsers and NodeJS with WebAssembly (see [emscripten](https://doc.atomvm.org/main/getting-started-guide.html#getting-started-with-atomvm-webassembly))
2323

0 commit comments

Comments
 (0)