Skip to content

Commit a8496e8

Browse files
committed
Add SPI support to STM32 platform
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
1 parent 88554a9 commit a8496e8

File tree

14 files changed

+1134
-23
lines changed

14 files changed

+1134
-23
lines changed

.github/workflows/stm32-build.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
mkdir build-host
150150
cd build-host
151151
cmake .. -G Ninja
152-
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test
152+
cmake --build . -t stm32_boot_test stm32_gpio_test stm32_i2c_test stm32_spi_test
153153
154154
- name: Install Renode
155155
if: matrix.renode_platform
@@ -205,3 +205,18 @@ jobs:
205205
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_i2c_test.avm \
206206
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
207207
--variable PLATFORM:$PLATFORM
208+
209+
- name: Run Renode SPI test
210+
if: matrix.renode_platform
211+
run: |
212+
LOCAL_REPL="src/platforms/stm32/tests/renode/${{ matrix.renode_platform }}"
213+
if [ -f "$LOCAL_REPL" ]; then
214+
PLATFORM="@$PWD/$LOCAL_REPL"
215+
else
216+
PLATFORM="@platforms/cpus/${{ matrix.renode_platform }}"
217+
fi
218+
renode-test src/platforms/stm32/tests/renode/stm32_spi_test.robot \
219+
--variable ELF:@$PWD/src/platforms/stm32/build/AtomVM-${{ matrix.device }}.elf \
220+
--variable AVM:@$PWD/build-host/src/platforms/stm32/tests/test_erl_sources/stm32_spi_test.avm \
221+
--variable AVM_ADDRESS:${{ matrix.avm_address }} \
222+
--variable PLATFORM:$PLATFORM

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() ->

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)