From 7016900fbe6d691129dd03f87ede3a9a7bde5236 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 1 Jul 2025 15:03:04 +1000 Subject: [PATCH] stm32/spi: Fail spi_init if pins can't be configured. Follows the UART and I2C drivers. Signed-off-by: Damien George --- ports/stm32/spi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ports/stm32/spi.c b/ports/stm32/spi.c index 19f2b65ed..248075579 100644 --- a/ports/stm32/spi.c +++ b/ports/stm32/spi.c @@ -481,7 +481,10 @@ int spi_init(const spi_t *self, bool enable_nss_pin) { if (pins[i] == NULL) { continue; } - mp_hal_pin_config_alt(pins[i], mode, pull, AF_FN_SPI, (self - &spi_obj[0]) + 1); + if (!mp_hal_pin_config_alt(pins[i], mode, pull, AF_FN_SPI, (self - &spi_obj[0]) + 1)) { + // Pin does not have SPI alternate function. + return -MP_EINVAL; + } } // init the SPI device