Skip to content

Commit 54beff0

Browse files
committed
Add SPI support to STM32 platform
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 6d194db commit 54beff0

File tree

16 files changed

+1153
-24
lines changed

16 files changed

+1153
-24
lines changed

.github/workflows/stm32-build.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158
mkdir build-host
159159
cd build-host
160160
cmake .. -G Ninja
161-
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test
161+
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test stm32_spi_test
162162
163163
- name: Install Renode
164164
if: matrix.renode_platform
@@ -214,3 +214,18 @@ jobs:
214214
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_i2c_test.avm \
215215
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
216216
--variable PLATFORM:$PLATFORM
217+
218+
- name: Run Renode SPI test
219+
if: matrix.renode_platform
220+
run: |
221+
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
222+
if [ -f "$LOCAL_REPL" ]; then
223+
PLATFORM="@$PWD/$LOCAL_REPL"
224+
else
225+
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
226+
fi
227+
renode-test src/platforms/stm32/tests/renode/stm32_spi_test.robot \
228+
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
229+
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_spi_test.avm \
230+
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
231+
--variable PLATFORM:$PLATFORM

examples/erlang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ pack_runnable(network_console network_console estdlib eavmlib alisp)
4343
pack_runnable(logging_example logging_example estdlib eavmlib)
4444
pack_runnable(http_client http_client estdlib eavmlib avm_network)
4545
pack_runnable(disterl disterl estdlib)
46-
pack_runnable(spi_flash spi_flash eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2)
46+
pack_runnable(spi_flash spi_flash eavmlib estdlib DIALYZE_AGAINST avm_esp32 avm_rp2 avm_stm32)

examples/erlang/spi_flash.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ default_pins() ->
108108

109109
%% {SCK, MOSI, MISO, CS}
110110
default_pins(pico) -> {2, 3, 4, 5};
111+
default_pins(stm32) -> {{a, 5}, {a, 7}, {a, 6}, {a, 4}};
111112
default_pins(esp32) -> esp32_default_pins().
112113

113114
esp32_default_pins() ->

examples/erlang/stm32/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,24 @@ pack_runnable(blink_weact_studio_h743 blink_weact_studio_h743 eavmlib avm_stm32)
2828
pack_runnable(blink_weact_studio_u585 blink_weact_studio_u585 eavmlib avm_stm32)
2929
pack_runnable(blink_weact_studio_wb55 blink_weact_studio_wb55 eavmlib avm_stm32)
3030
pack_runnable(stm32_lis3dh stm32_lis3dh eavmlib avm_stm32)
31+
32+
set(SPI_FLASH_BEAM ${CMAKE_BINARY_DIR}/examples/erlang/spi_flash.beam)
33+
if(AVM_RELEASE)
34+
set(INCLUDE_LINES "")
35+
else()
36+
set(INCLUDE_LINES "-i")
37+
endif()
38+
add_custom_command(
39+
OUTPUT stm32_spi_flash.avm
40+
DEPENDS spi_flash_main ${SPI_FLASH_BEAM}
41+
${CMAKE_BINARY_DIR}/libs/estdlib/src/estdlib.avm estdlib
42+
${CMAKE_BINARY_DIR}/libs/avm_stm32/src/avm_stm32.avm avm_stm32
43+
PackBEAM
44+
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} stm32_spi_flash.avm
45+
${SPI_FLASH_BEAM}
46+
${CMAKE_BINARY_DIR}/libs/estdlib/src/estdlib.avm
47+
${CMAKE_BINARY_DIR}/libs/avm_stm32/src/avm_stm32.avm
48+
COMMENT "Packing runnable stm32_spi_flash.avm"
49+
VERBATIM
50+
)
51+
add_custom_target(stm32_spi_flash ALL DEPENDS stm32_spi_flash.avm)

libs/avm_stm32/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include(BuildErlang)
2525
set(ERLANG_MODULES
2626
gpio
2727
i2c
28+
spi
2829
)
2930

3031
pack_archive(avm_stm32 DEPENDS_ON eavmlib ERLC_FLAGS +warnings_as_errors MODULES ${ERLANG_MODULES})

libs/avm_stm32/src/gpio.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@
5858
-type direction() :: input | output | output_od | mode_config().
5959
%% The direction is used to set the mode of operation for a GPIO pin, either as an input, an output, or output with open drain.
6060
%% Pull mode and output_speed must be set at the same time as direction. See @type mode_config()
61-
-type mode_config() :: {direction(), pull()} | {output, pull(), output_speed()}.
61+
-type mode_config() ::
62+
{direction(), pull()} | {output, pull(), output_speed()} | {af, non_neg_integer()}.
6263
%% Extended mode configuration options. Default pull() is `floating', default output_speed() is `mhz_2' if options are omitted.
64+
%% `{af, AFNumber}' configures the pin in alternate function push-pull mode with the given AF number (e.g. 5 for SPI1).
6365
-type pull() :: up | down | floating.
6466
%% Internal resistor pull mode. STM32 does not support `up_down'.
6567
-type output_speed() :: mhz_2 | mhz_25 | mhz_50 | mhz_100.

0 commit comments

Comments
 (0)