diff --git a/source/Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c b/source/Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c index 8d3ef52274..a97210bf1b 100644 --- a/source/Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c +++ b/source/Core/BSP/Miniware/Vendor/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c @@ -1831,15 +1831,41 @@ HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t hi2c->hdmatx->XferHalfCpltCallback = NULL; hi2c->hdmatx->XferAbortCallback = NULL; - /* Enable the DMA channel */ - HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize); - /* Enable Acknowledge */ hi2c->Instance->CR1 |= I2C_CR1_ACK; /* Generate Start */ hi2c->Instance->CR1 |= I2C_CR1_START; + /* Wait until SB flag is set */ + if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_SB, RESET, HAL_MAX_DELAY, HAL_GetTick()) != HAL_OK) { + __HAL_UNLOCK(hi2c); + return HAL_TIMEOUT; + } + + if (hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_7BIT) { + /* Send slave address */ + hi2c->Instance->DR = I2C_7BIT_ADD_WRITE(DevAddress); + } else { + // Not used + } + + /* Wait until ADDR flag is set */ + if (I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, HAL_MAX_DELAY, HAL_GetTick()) != HAL_OK) { + if (hi2c->ErrorCode == HAL_I2C_ERROR_AF) { + __HAL_UNLOCK(hi2c); + return HAL_ERROR; + } else { + __HAL_UNLOCK(hi2c); + return HAL_TIMEOUT; + } + } + /* Clear ADDR flag */ + __HAL_I2C_CLEAR_ADDRFLAG(hi2c); + + /* Enable the DMA channel */ + HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr + 1, (uint32_t)&hi2c->Instance->DR, hi2c->XferSize - 1); + /* Process Unlocked */ __HAL_UNLOCK(hi2c);