diff --git a/cores/arduino/stm32/spi_com.c b/cores/arduino/stm32/spi_com.c index d389cf37da..8268f59fb4 100644 --- a/cores/arduino/stm32/spi_com.c +++ b/cores/arduino/stm32/spi_com.c @@ -198,6 +198,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb) /* Pins MOSI/MISO/SCLK must not be NP. ssel can be NP. */ if(spi_mosi == NP || spi_miso == NP || spi_sclk == NP) { + printf("ERROR: at least one SPI pin has no peripheral\n"); return; } diff --git a/cores/arduino/stm32/twi.c b/cores/arduino/stm32/twi.c index 211afb0c82..ac1d0cd528 100644 --- a/cores/arduino/stm32/twi.c +++ b/cores/arduino/stm32/twi.c @@ -154,6 +154,12 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u I2C_TypeDef *i2c_sda = pinmap_peripheral(obj->sda, PinMap_I2C_SDA); I2C_TypeDef *i2c_scl = pinmap_peripheral(obj->scl, PinMap_I2C_SCL); + //Pins SDA/SCL must not be NP + if(i2c_sda == NP || i2c_scl == NP) { + printf("ERROR: at least one I2C pin has no peripheral\n"); + return; + } + obj->i2c = pinmap_merge_peripheral(i2c_sda, i2c_scl); if(obj->i2c == NP) { diff --git a/cores/arduino/stm32/uart.c b/cores/arduino/stm32/uart.c index 142d5a9921..969ceeae2b 100644 --- a/cores/arduino/stm32/uart.c +++ b/cores/arduino/stm32/uart.c @@ -132,6 +132,12 @@ void uart_init(serial_t *obj) USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX); USART_TypeDef *uart_rx = pinmap_peripheral(obj->pin_rx, PinMap_UART_RX); + //Pins Rx/Tx must not be NP + if(uart_rx == NP || uart_tx == NP) { + printf("ERROR: at least one UART pin has no peripheral\n"); + return; + } + // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object obj->uart = pinmap_merge_peripheral(uart_tx, uart_rx);