Skip to content

Commit 6c60e3a

Browse files
committed
[F4] I2C HAL fix: generate Start only once Stop is finished
1 parent a6f7a98 commit 6c60e3a

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

system/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16
34383438
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
34393439
}
34403440

3441+
/*+ Fix_Candidate_Ticket_79517_V1 */
3442+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3443+
/* Wait until STOP flag is reset */
3444+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3445+
do
3446+
{
3447+
count--;
3448+
if (count == 0U)
3449+
{
3450+
hi2c->PreviousState = I2C_STATE_NONE;
3451+
hi2c->State = HAL_I2C_STATE_READY;
3452+
hi2c->Mode = HAL_I2C_MODE_NONE;
3453+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3454+
3455+
/* Process Unlocked */
3456+
__HAL_UNLOCK(hi2c);
3457+
3458+
return HAL_ERROR;
3459+
}
3460+
}
3461+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3462+
/*- Fix_Candidate_Ticket_79517_V1 */
3463+
34413464
/* Process Locked */
34423465
__HAL_LOCK(hi2c);
34433466

@@ -3537,6 +3560,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
35373560
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
35383561
}
35393562

3563+
/*+ Fix_Candidate_Ticket_79517_V1 */
3564+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3565+
/* Wait until STOP flag is reset */
3566+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3567+
do
3568+
{
3569+
count--;
3570+
if (count == 0U)
3571+
{
3572+
hi2c->PreviousState = I2C_STATE_NONE;
3573+
hi2c->State = HAL_I2C_STATE_READY;
3574+
hi2c->Mode = HAL_I2C_MODE_NONE;
3575+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3576+
3577+
/* Process Unlocked */
3578+
__HAL_UNLOCK(hi2c);
3579+
3580+
return HAL_ERROR;
3581+
}
3582+
}
3583+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3584+
/*- Fix_Candidate_Ticket_79517_V1 */
3585+
35403586
/* Process Locked */
35413587
__HAL_LOCK(hi2c);
35423588

@@ -3703,6 +3749,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
37033749
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
37043750
}
37053751

3752+
/*+ Fix_Candidate_Ticket_79517_V1 */
3753+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3754+
/* Wait until STOP flag is reset */
3755+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3756+
do
3757+
{
3758+
count--;
3759+
if (count == 0U)
3760+
{
3761+
hi2c->PreviousState = I2C_STATE_NONE;
3762+
hi2c->State = HAL_I2C_STATE_READY;
3763+
hi2c->Mode = HAL_I2C_MODE_NONE;
3764+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3765+
3766+
/* Process Unlocked */
3767+
__HAL_UNLOCK(hi2c);
3768+
3769+
return HAL_ERROR;
3770+
}
3771+
}
3772+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3773+
/*- Fix_Candidate_Ticket_79517_V1 */
3774+
37063775
/* Process Locked */
37073776
__HAL_LOCK(hi2c);
37083777

@@ -3828,6 +3897,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
38283897
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
38293898
}
38303899

3900+
/*+ Fix_Candidate_Ticket_79517_V1 */
3901+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3902+
/* Wait until STOP flag is reset */
3903+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3904+
do
3905+
{
3906+
count--;
3907+
if (count == 0U)
3908+
{
3909+
hi2c->PreviousState = I2C_STATE_NONE;
3910+
hi2c->State = HAL_I2C_STATE_READY;
3911+
hi2c->Mode = HAL_I2C_MODE_NONE;
3912+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3913+
3914+
/* Process Unlocked */
3915+
__HAL_UNLOCK(hi2c);
3916+
3917+
return HAL_ERROR;
3918+
}
3919+
}
3920+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3921+
/*- Fix_Candidate_Ticket_79517_V1 */
3922+
38313923
/* Process Locked */
38323924
__HAL_LOCK(hi2c);
38333925

0 commit comments

Comments
 (0)