@@ -3438,6 +3438,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16
3438
3438
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3439
3439
}
3440
3440
3441
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3442
+ /* Wait until STOP flag is reset */
3443
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3444
+ do
3445
+ {
3446
+ count -- ;
3447
+ if (count == 0U )
3448
+ {
3449
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3450
+ hi2c -> State = HAL_I2C_STATE_READY ;
3451
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3452
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3453
+
3454
+ /* Process Unlocked */
3455
+ __HAL_UNLOCK (hi2c );
3456
+
3457
+ return HAL_ERROR ;
3458
+ }
3459
+ }
3460
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3461
+
3441
3462
/* Process Locked */
3442
3463
__HAL_LOCK (hi2c );
3443
3464
@@ -3537,6 +3558,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
3537
3558
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3538
3559
}
3539
3560
3561
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3562
+ /* Wait until STOP flag is reset */
3563
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3564
+ do
3565
+ {
3566
+ count -- ;
3567
+ if (count == 0U )
3568
+ {
3569
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3570
+ hi2c -> State = HAL_I2C_STATE_READY ;
3571
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3572
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3573
+
3574
+ /* Process Unlocked */
3575
+ __HAL_UNLOCK (hi2c );
3576
+
3577
+ return HAL_ERROR ;
3578
+ }
3579
+ }
3580
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3581
+
3540
3582
/* Process Locked */
3541
3583
__HAL_LOCK (hi2c );
3542
3584
@@ -3703,6 +3745,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
3703
3745
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3704
3746
}
3705
3747
3748
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3749
+ /* Wait until STOP flag is reset */
3750
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3751
+ do
3752
+ {
3753
+ count -- ;
3754
+ if (count == 0U )
3755
+ {
3756
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3757
+ hi2c -> State = HAL_I2C_STATE_READY ;
3758
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3759
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3760
+
3761
+ /* Process Unlocked */
3762
+ __HAL_UNLOCK (hi2c );
3763
+
3764
+ return HAL_ERROR ;
3765
+ }
3766
+ }
3767
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3768
+
3706
3769
/* Process Locked */
3707
3770
__HAL_LOCK (hi2c );
3708
3771
@@ -3828,6 +3891,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
3828
3891
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3829
3892
}
3830
3893
3894
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3895
+ /* Wait until STOP flag is reset */
3896
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3897
+ do
3898
+ {
3899
+ count -- ;
3900
+ if (count == 0U )
3901
+ {
3902
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3903
+ hi2c -> State = HAL_I2C_STATE_READY ;
3904
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3905
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3906
+
3907
+ /* Process Unlocked */
3908
+ __HAL_UNLOCK (hi2c );
3909
+
3910
+ return HAL_ERROR ;
3911
+ }
3912
+ }
3913
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3914
+
3831
3915
/* Process Locked */
3832
3916
__HAL_LOCK (hi2c );
3833
3917
@@ -4511,7 +4595,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4511
4595
UNUSED (DevAddress );
4512
4596
4513
4597
/* Abort Master transfer during Receive or Transmit process */
4514
- if (hi2c -> Mode == HAL_I2C_MODE_MASTER )
4598
+ if (( __HAL_I2C_GET_FLAG ( hi2c , I2C_FLAG_BUSY ) != RESET ) && ( hi2c -> Mode == HAL_I2C_MODE_MASTER ) )
4515
4599
{
4516
4600
/* Process Locked */
4517
4601
__HAL_LOCK (hi2c );
@@ -4542,6 +4626,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4542
4626
{
4543
4627
/* Wrong usage of abort function */
4544
4628
/* This function should be used only in case of abort monitored by master device */
4629
+ /* Or periphal is not in busy state, mean there is no active sequence to be abort */
4545
4630
return HAL_ERROR ;
4546
4631
}
4547
4632
}
0 commit comments