Skip to content

Commit 7bcc843

Browse files
committed
initialize state before calling HAL_XXX_Init for SPI and I2C
If we use a dynamic instanciation, the state is not well initialized. This can ends with a blocking or strange behaviour.
1 parent 5f5b063 commit 7bcc843

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

cores/arduino/stm32/spi_com.c

+2
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
371371
}
372372
#endif
373373

374+
handle->State = HAL_SPI_STATE_RESET;
375+
374376
HAL_SPI_Init(handle);
375377

376378
/* In order to set correctly the SPI polarity we need to enable the peripheral */

cores/arduino/stm32/twi.c

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ void i2c_custom_init(i2c_t *obj, i2c_timing_e timing, uint32_t addressingMode, u
253253
handle->Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
254254
handle->Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
255255

256+
handle->State = HAL_I2C_STATE_RESET;
257+
256258
if(master == 0) {
257259
HAL_NVIC_SetPriority(obj->irq, 0, 1);
258260
HAL_NVIC_EnableIRQ(obj->irq);

0 commit comments

Comments
 (0)