Skip to content

Commit fce320f

Browse files
committed
Fix issue if a pin has no peripheral
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 156ccfc commit fce320f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

cores/arduino/stm32/spi_com.c

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
198198

199199
/* Pins MOSI/MISO/SCLK must not be NP. ssel can be NP. */
200200
if(spi_mosi == NP || spi_miso == NP || spi_sclk == NP) {
201+
printf("ERROR: at least one SPI pin has no peripheral\n");
201202
return;
202203
}
203204

cores/arduino/stm32/twi.c

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
154154
I2C_TypeDef *i2c_sda = pinmap_peripheral(obj->sda, PinMap_I2C_SDA);
155155
I2C_TypeDef *i2c_scl = pinmap_peripheral(obj->scl, PinMap_I2C_SCL);
156156

157+
//Pins SDA/SCL must not be NP
158+
if(i2c_sda == NP || i2c_scl == NP) {
159+
printf("ERROR: at least one I2C pin has no peripheral\n");
160+
return;
161+
}
162+
157163
obj->i2c = pinmap_merge_peripheral(i2c_sda, i2c_scl);
158164

159165
if(obj->i2c == NP) {

cores/arduino/stm32/uart.c

+6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ void uart_init(serial_t *obj)
132132
USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX);
133133
USART_TypeDef *uart_rx = pinmap_peripheral(obj->pin_rx, PinMap_UART_RX);
134134

135+
//Pins Rx/Tx must not be NP
136+
if(uart_rx == NP || uart_tx == NP) {
137+
printf("ERROR: at least one UART pin has no peripheral\n");
138+
return;
139+
}
140+
135141
// Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
136142
obj->uart = pinmap_merge_peripheral(uart_tx, uart_rx);
137143

0 commit comments

Comments
 (0)