@@ -3428,6 +3428,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16
3428
3428
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3429
3429
}
3430
3430
3431
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3432
+ /* Wait until STOP flag is reset */
3433
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3434
+ do
3435
+ {
3436
+ count -- ;
3437
+ if (count == 0U )
3438
+ {
3439
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3440
+ hi2c -> State = HAL_I2C_STATE_READY ;
3441
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3442
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3443
+
3444
+ /* Process Unlocked */
3445
+ __HAL_UNLOCK (hi2c );
3446
+
3447
+ return HAL_ERROR ;
3448
+ }
3449
+ }
3450
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3451
+
3431
3452
/* Process Locked */
3432
3453
__HAL_LOCK (hi2c );
3433
3454
@@ -3527,6 +3548,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
3527
3548
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3528
3549
}
3529
3550
3551
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3552
+ /* Wait until STOP flag is reset */
3553
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3554
+ do
3555
+ {
3556
+ count -- ;
3557
+ if (count == 0U )
3558
+ {
3559
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3560
+ hi2c -> State = HAL_I2C_STATE_READY ;
3561
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3562
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3563
+
3564
+ /* Process Unlocked */
3565
+ __HAL_UNLOCK (hi2c );
3566
+
3567
+ return HAL_ERROR ;
3568
+ }
3569
+ }
3570
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3571
+
3530
3572
/* Process Locked */
3531
3573
__HAL_LOCK (hi2c );
3532
3574
@@ -3693,6 +3735,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
3693
3735
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3694
3736
}
3695
3737
3738
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3739
+ /* Wait until STOP flag is reset */
3740
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3741
+ do
3742
+ {
3743
+ count -- ;
3744
+ if (count == 0U )
3745
+ {
3746
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3747
+ hi2c -> State = HAL_I2C_STATE_READY ;
3748
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3749
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3750
+
3751
+ /* Process Unlocked */
3752
+ __HAL_UNLOCK (hi2c );
3753
+
3754
+ return HAL_ERROR ;
3755
+ }
3756
+ }
3757
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3758
+
3696
3759
/* Process Locked */
3697
3760
__HAL_LOCK (hi2c );
3698
3761
@@ -3818,6 +3881,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
3818
3881
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3819
3882
}
3820
3883
3884
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3885
+ /* Wait until STOP flag is reset */
3886
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3887
+ do
3888
+ {
3889
+ count -- ;
3890
+ if (count == 0U )
3891
+ {
3892
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3893
+ hi2c -> State = HAL_I2C_STATE_READY ;
3894
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3895
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3896
+
3897
+ /* Process Unlocked */
3898
+ __HAL_UNLOCK (hi2c );
3899
+
3900
+ return HAL_ERROR ;
3901
+ }
3902
+ }
3903
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3904
+
3821
3905
/* Process Locked */
3822
3906
__HAL_LOCK (hi2c );
3823
3907
@@ -4501,7 +4585,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4501
4585
UNUSED (DevAddress );
4502
4586
4503
4587
/* Abort Master transfer during Receive or Transmit process */
4504
- if (hi2c -> Mode == HAL_I2C_MODE_MASTER )
4588
+ if (( __HAL_I2C_GET_FLAG ( hi2c , I2C_FLAG_BUSY ) != RESET ) && ( hi2c -> Mode == HAL_I2C_MODE_MASTER ) )
4505
4589
{
4506
4590
/* Process Locked */
4507
4591
__HAL_LOCK (hi2c );
@@ -4532,6 +4616,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4532
4616
{
4533
4617
/* Wrong usage of abort function */
4534
4618
/* This function should be used only in case of abort monitored by master device */
4619
+ /* Or periphal is not in busy state, mean there is no active sequence to be abort */
4535
4620
return HAL_ERROR ;
4536
4621
}
4537
4622
}
0 commit comments