Skip to content

Commit 3e44d53

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. This issue is mainly met when doing soft reset (button).
1 parent 5f5b063 commit 3e44d53

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

cores/arduino/stm32/spi_com.c

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void spi_init(spi_t *obj, uint32_t speed, spi_mode_e mode, uint8_t msb)
222222
/* Fill default value */
223223
handle->Instance = obj->spi;
224224
handle->Init.Mode = SPI_MODE_MASTER;
225+
handle->State = HAL_SPI_STATE_RESET;
225226

226227
spi_freq = spi_getClkFreqInst(obj->spi);
227228
if(speed >= (spi_freq/SPI_SPEED_CLOCK_DIV2_MHZ)) {

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)