@@ -3416,6 +3416,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16
3416
3416
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3417
3417
}
3418
3418
3419
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3420
+ /* Wait until STOP flag is reset */
3421
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3422
+ do
3423
+ {
3424
+ count -- ;
3425
+ if (count == 0U )
3426
+ {
3427
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3428
+ hi2c -> State = HAL_I2C_STATE_READY ;
3429
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3430
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3431
+
3432
+ /* Process Unlocked */
3433
+ __HAL_UNLOCK (hi2c );
3434
+
3435
+ return HAL_ERROR ;
3436
+ }
3437
+ }
3438
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3439
+
3419
3440
/* Process Locked */
3420
3441
__HAL_LOCK (hi2c );
3421
3442
@@ -3515,6 +3536,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
3515
3536
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3516
3537
}
3517
3538
3539
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3540
+ /* Wait until STOP flag is reset */
3541
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3542
+ do
3543
+ {
3544
+ count -- ;
3545
+ if (count == 0U )
3546
+ {
3547
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3548
+ hi2c -> State = HAL_I2C_STATE_READY ;
3549
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3550
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3551
+
3552
+ /* Process Unlocked */
3553
+ __HAL_UNLOCK (hi2c );
3554
+
3555
+ return HAL_ERROR ;
3556
+ }
3557
+ }
3558
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3559
+
3518
3560
/* Process Locked */
3519
3561
__HAL_LOCK (hi2c );
3520
3562
@@ -3681,6 +3723,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
3681
3723
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3682
3724
}
3683
3725
3726
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3727
+ /* Wait until STOP flag is reset */
3728
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3729
+ do
3730
+ {
3731
+ count -- ;
3732
+ if (count == 0U )
3733
+ {
3734
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3735
+ hi2c -> State = HAL_I2C_STATE_READY ;
3736
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3737
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3738
+
3739
+ /* Process Unlocked */
3740
+ __HAL_UNLOCK (hi2c );
3741
+
3742
+ return HAL_ERROR ;
3743
+ }
3744
+ }
3745
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3746
+
3684
3747
/* Process Locked */
3685
3748
__HAL_LOCK (hi2c );
3686
3749
@@ -3798,6 +3861,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
3798
3861
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3799
3862
}
3800
3863
3864
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3865
+ /* Wait until STOP flag is reset */
3866
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3867
+ do
3868
+ {
3869
+ count -- ;
3870
+ if (count == 0U )
3871
+ {
3872
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3873
+ hi2c -> State = HAL_I2C_STATE_READY ;
3874
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3875
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3876
+
3877
+ /* Process Unlocked */
3878
+ __HAL_UNLOCK (hi2c );
3879
+
3880
+ return HAL_ERROR ;
3881
+ }
3882
+ }
3883
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3884
+
3801
3885
/* Process Locked */
3802
3886
__HAL_LOCK (hi2c );
3803
3887
@@ -4465,7 +4549,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4465
4549
UNUSED (DevAddress );
4466
4550
4467
4551
/* Abort Master transfer during Receive or Transmit process */
4468
- if (hi2c -> Mode == HAL_I2C_MODE_MASTER )
4552
+ if (( __HAL_I2C_GET_FLAG ( hi2c , I2C_FLAG_BUSY ) != RESET ) && ( hi2c -> Mode == HAL_I2C_MODE_MASTER ) )
4469
4553
{
4470
4554
/* Process Locked */
4471
4555
__HAL_LOCK (hi2c );
@@ -4496,6 +4580,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4496
4580
{
4497
4581
/* Wrong usage of abort function */
4498
4582
/* This function should be used only in case of abort monitored by master device */
4583
+ /* Or periphal is not in busy state, mean there is no active sequence to be abort */
4499
4584
return HAL_ERROR ;
4500
4585
}
4501
4586
}
0 commit comments