Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 15 additions & 76 deletions .github/workflows/stm32-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ jobs:
# FinishTransmission() on the I2C slave when a STOP condition
# occurs, causing the BME280 sensor to get stuck in Reading
# state and ignore subsequent writes.
skip_i2c_test: true
tests: "boot gpio spi crypto uart"
- device: stm32f411ceu6
max_size: 393216
renode_platform: stm32f4.repl
avm_address: "0x08060000"
skip_i2c_test: true
# No RNG peripheral on F411, so the firmware has no crypto NIFs
# (mbedTLS is excluded by STM32_HAS_RNG in CMake).
skip_crypto_test: true
tests: "boot gpio spi uart"
- device: stm32f429zit6
max_size: 524288
- device: stm32h743vit6
max_size: 524288
renode_platform: stm32h743.repl
avm_address: "0x08080000"
tests: "boot gpio i2c spi crypto uart"
- device: stm32h743zit6
max_size: 524288
- device: stm32u585ait6q
Expand All @@ -91,6 +91,7 @@ jobs:
max_size: 524288
renode_platform: stm32f746.repl
avm_address: "0x08080000"
tests: "boot gpio i2c spi crypto uart"
- device: stm32g474ret6
max_size: 393216
- device: stm32l476rgt6
Expand All @@ -102,10 +103,9 @@ jobs:
# Renode's built-in stm32l552.repl uses STM32F4_I2C (legacy I2C
# register layout) but the L5 HAL uses the newer I2C registers
# (TIMINGR, ISR, etc.), causing a complete register mismatch.
skip_i2c_test: true
# 512 KB flash with avm_address=0x08060000 leaves only 128 KB,
# but the crypto AVM is 207 KB and gets truncated.
skip_crypto_test: true
tests: "boot gpio spi uart"
- device: stm32f207zgt6
max_size: 524288
- device: stm32u375rgt6
Expand All @@ -117,7 +117,7 @@ jobs:
# No RNG peripheral on G0B1 (only G041/G061/G081/G0C1 have one),
# so the firmware has no crypto NIFs (mbedTLS is excluded by
# STM32_HAS_RNG in CMake).
skip_crypto_test: true
tests: "boot gpio i2c spi uart"

steps:
- uses: erlef/setup-beam@v1
Expand Down Expand Up @@ -195,7 +195,7 @@ jobs:
mkdir build-host
cd build-host
cmake .. -G Ninja
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test stm32_spi_test stm32_crypto_test
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test stm32_spi_test stm32_crypto_test stm32_uart_test

- name: Install Renode
if: matrix.renode_platform
Expand All @@ -207,7 +207,7 @@ jobs:
echo "$PWD/renode-portable" >> $GITHUB_PATH
pip install -r renode-portable/tests/requirements.txt

- name: Run Renode boot test
- name: Run Renode tests
if: matrix.renode_platform
run: |
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
Expand All @@ -216,71 +216,10 @@ jobs:
else
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
fi
renode-test src/platforms/stm32/tests/renode/stm32_boot_test.robot \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_boot_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM

- name: Run Renode GPIO test
if: matrix.renode_platform
run: |
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
if [ -f "$LOCAL_REPL" ]; then
PLATFORM="@$PWD/$LOCAL_REPL"
else
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
fi
renode-test src/platforms/stm32/tests/renode/stm32_gpio_test.robot \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_gpio_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM

- name: Run Renode I2C test
if: matrix.renode_platform && !matrix.skip_i2c_test
run: |
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
if [ -f "$LOCAL_REPL" ]; then
PLATFORM="@$PWD/$LOCAL_REPL"
else
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
fi
renode-test src/platforms/stm32/tests/renode/stm32_i2c_test.robot \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_i2c_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM

- name: Run Renode SPI test
if: matrix.renode_platform
run: |
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
if [ -f "$LOCAL_REPL" ]; then
PLATFORM="@$PWD/$LOCAL_REPL"
else
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
fi
renode-test src/platforms/stm32/tests/renode/stm32_spi_test.robot \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_spi_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM

- name: Run Renode crypto test
# Devices without RNG hardware (F411 / G0) don't ship mbedTLS at all;
# L562 has only 512 KB of flash and the 207 KB crypto AVM is truncated
# at AVM_ADDRESS=0x08060000, which kills kernel boot.
if: matrix.renode_platform && !matrix.skip_crypto_test
run: |
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
if [ -f "$LOCAL_REPL" ]; then
PLATFORM="@$PWD/$LOCAL_REPL"
else
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
fi
renode-test src/platforms/stm32/tests/renode/stm32_crypto_test.robot \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_crypto_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM
for TEST in ${{ matrix.tests }}; do
renode-test "src/platforms/stm32/tests/renode/stm32_${TEST}_test.robot" \
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_${TEST}_test.avm \
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
--variable PLATFORM:$PLATFORM
done
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for `nif_start`, `executable_line` and `debug_line` opcodes
- Added named variable debugging support in DWARF when modules are compiled with `beam_debug_info`
- Added more reset reasons and ensured `esp:reset_reason/0` doesn't return `undefined`
- Added I2C and SPI APIs to stm32 platform
- Added I2C, SPI and UART APIs to stm32 platform
- Added `Transfer-Encoding: chunked` response support to `ahttp_client`, including HTTP trailers
- Added `proc_lib:init_fail/2,3`
- Added UART API to rp2 platform
Expand Down
2 changes: 1 addition & 1 deletion examples/erlang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ pack_runnable(i2c_scanner i2c_scanner eavmlib estdlib DIALYZE_AGAINST avm_esp32
pack_runnable(i2c_lis3dh i2c_lis3dh eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2 avm_stm32)
pack_runnable(spi_flash spi_flash eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2 avm_stm32)
pack_runnable(spi_lis3dh spi_lis3dh eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2 avm_stm32)
pack_runnable(sim800l sim800l eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2)
pack_runnable(sim800l sim800l eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2 avm_stm32)
38 changes: 27 additions & 11 deletions examples/erlang/sim800l.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
%% Default pins are auto-detected from the platform and chip model:
%%
%% Pico (UART1): TX=GP4, RX=GP5
%% STM32 (USART1): TX=PA9, RX=PA10, AF=7
%% ESP32/S2/S3 (UART1): TX=17, RX=16
%% ESP32-C2 (UART1): TX=4, RX=5
%% ESP32-C3/C5 (UART1): TX=4, RX=5
Expand All @@ -46,13 +47,8 @@
-define(AT_TIMEOUT, 2000).

start() ->
{TX, RX} = default_pins(),
io:format("Opening UART1 on TX=~B RX=~B~n", [TX, RX]),
UART = uart:open("UART1", [
{tx, TX},
{rx, RX},
{speed, 115200}
]),
Platform = atomvm:platform(),
UART = open_uart(Platform),
%% SIM800L takes 3-5 seconds to boot after power-on
case wait_for_module(UART, 5) of
ok ->
Expand Down Expand Up @@ -156,13 +152,33 @@ drain(UART) ->
end.

%%-----------------------------------------------------------------------------
%% Platform-specific default pins
%% Platform-specific UART operations
%%-----------------------------------------------------------------------------
default_pins() ->
default_pins(atomvm:platform()).

%% {TX, RX}
open_uart(stm32) ->
{TX, RX} = default_pins(stm32),
io:format("Opening USART1 on TX=~p RX=~p~n", [TX, RX]),
uart:open([
{peripheral, 1},
{tx, TX},
{rx, RX},
{af, 7},
{speed, 115200}
]);
open_uart(Platform) ->
{TX, RX} = default_pins(Platform),
io:format("Opening UART1 on TX=~p RX=~p~n", [TX, RX]),
uart:open("UART1", [
{tx, TX},
{rx, RX},
{speed, 115200}
]).

%%-----------------------------------------------------------------------------
%% Platform-specific default pins
%%-----------------------------------------------------------------------------
default_pins(pico) -> {4, 5};
default_pins(stm32) -> {{a, 9}, {a, 10}};
default_pins(esp32) -> esp32_default_pins().

esp32_default_pins() ->
Expand Down
16 changes: 16 additions & 0 deletions examples/erlang/stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,19 @@ add_custom_command(
VERBATIM
)
add_custom_target(stm32_spi_flash ALL DEPENDS stm32_spi_flash.avm)

set(SIM800L_BEAM ${CMAKE_BINARY_DIR}/examples/erlang/sim800l.beam)
add_custom_command(
OUTPUT stm32_sim800l.avm
DEPENDS sim800l_main ${SIM800L_BEAM}
${CMAKE_BINARY_DIR}/libs/estdlib/src/estdlib.avm estdlib
${CMAKE_BINARY_DIR}/libs/avm_stm32/src/avm_stm32.avm avm_stm32
PackBEAM
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/packbeam create ${INCLUDE_LINES} stm32_sim800l.avm
${SIM800L_BEAM}
${CMAKE_BINARY_DIR}/libs/estdlib/src/estdlib.avm
${CMAKE_BINARY_DIR}/libs/avm_stm32/src/avm_stm32.avm
COMMENT "Packing runnable stm32_sim800l.avm"
VERBATIM
)
add_custom_target(stm32_sim800l ALL DEPENDS stm32_sim800l.avm)
1 change: 1 addition & 0 deletions libs/avm_stm32/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(ERLANG_MODULES
gpio
i2c
spi
uart
)

pack_archive(avm_stm32 DEPENDS_ON eavmlib ERLC_FLAGS +warnings_as_errors MODULES ${ERLANG_MODULES})
Expand Down
Loading
Loading