Skip to content

Commit be5d074

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

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c

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

3495+
/*+ Fix_Candidate_Ticket_79517_V1 */
3496+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3497+
/* Wait until STOP flag is reset */
3498+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3499+
do
3500+
{
3501+
count--;
3502+
if (count == 0U)
3503+
{
3504+
hi2c->PreviousState = I2C_STATE_NONE;
3505+
hi2c->State = HAL_I2C_STATE_READY;
3506+
hi2c->Mode = HAL_I2C_MODE_NONE;
3507+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3508+
3509+
/* Process Unlocked */
3510+
__HAL_UNLOCK(hi2c);
3511+
3512+
return HAL_ERROR;
3513+
}
3514+
}
3515+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3516+
/*- Fix_Candidate_Ticket_79517_V1 */
3517+
34953518
/* Process Locked */
34963519
__HAL_LOCK(hi2c);
34973520

@@ -3591,6 +3614,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
35913614
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
35923615
}
35933616

3617+
/*+ Fix_Candidate_Ticket_79517_V1 */
3618+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3619+
/* Wait until STOP flag is reset */
3620+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3621+
do
3622+
{
3623+
count--;
3624+
if (count == 0U)
3625+
{
3626+
hi2c->PreviousState = I2C_STATE_NONE;
3627+
hi2c->State = HAL_I2C_STATE_READY;
3628+
hi2c->Mode = HAL_I2C_MODE_NONE;
3629+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3630+
3631+
/* Process Unlocked */
3632+
__HAL_UNLOCK(hi2c);
3633+
3634+
return HAL_ERROR;
3635+
}
3636+
}
3637+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3638+
/*- Fix_Candidate_Ticket_79517_V1 */
3639+
35943640
/* Process Locked */
35953641
__HAL_LOCK(hi2c);
35963642

@@ -3757,6 +3803,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
37573803
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
37583804
}
37593805

3806+
/*+ Fix_Candidate_Ticket_79517_V1 */
3807+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3808+
/* Wait until STOP flag is reset */
3809+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3810+
do
3811+
{
3812+
count--;
3813+
if (count == 0U)
3814+
{
3815+
hi2c->PreviousState = I2C_STATE_NONE;
3816+
hi2c->State = HAL_I2C_STATE_READY;
3817+
hi2c->Mode = HAL_I2C_MODE_NONE;
3818+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3819+
3820+
/* Process Unlocked */
3821+
__HAL_UNLOCK(hi2c);
3822+
3823+
return HAL_ERROR;
3824+
}
3825+
}
3826+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3827+
/*- Fix_Candidate_Ticket_79517_V1 */
3828+
37603829
/* Process Locked */
37613830
__HAL_LOCK(hi2c);
37623831

@@ -3882,6 +3951,29 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
38823951
while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET);
38833952
}
38843953

3954+
/*+ Fix_Candidate_Ticket_79517_V1 */
3955+
/* Before any new treatment like start or restart, check that there is no pending STOP request */
3956+
/* Wait until STOP flag is reset */
3957+
count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U);
3958+
do
3959+
{
3960+
count--;
3961+
if (count == 0U)
3962+
{
3963+
hi2c->PreviousState = I2C_STATE_NONE;
3964+
hi2c->State = HAL_I2C_STATE_READY;
3965+
hi2c->Mode = HAL_I2C_MODE_NONE;
3966+
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
3967+
3968+
/* Process Unlocked */
3969+
__HAL_UNLOCK(hi2c);
3970+
3971+
return HAL_ERROR;
3972+
}
3973+
}
3974+
while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP);
3975+
/*- Fix_Candidate_Ticket_79517_V1 */
3976+
38853977
/* Process Locked */
38863978
__HAL_LOCK(hi2c);
38873979

0 commit comments

Comments
 (0)