@@ -3492,6 +3492,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16
3492
3492
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3493
3493
}
3494
3494
3495
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3496
+ /* Wait until STOP flag is reset */
3497
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3498
+ do
3499
+ {
3500
+ count -- ;
3501
+ if (count == 0U )
3502
+ {
3503
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3504
+ hi2c -> State = HAL_I2C_STATE_READY ;
3505
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3506
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3507
+
3508
+ /* Process Unlocked */
3509
+ __HAL_UNLOCK (hi2c );
3510
+
3511
+ return HAL_ERROR ;
3512
+ }
3513
+ }
3514
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3515
+
3495
3516
/* Process Locked */
3496
3517
__HAL_LOCK (hi2c );
3497
3518
@@ -3591,6 +3612,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1
3591
3612
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3592
3613
}
3593
3614
3615
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3616
+ /* Wait until STOP flag is reset */
3617
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3618
+ do
3619
+ {
3620
+ count -- ;
3621
+ if (count == 0U )
3622
+ {
3623
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3624
+ hi2c -> State = HAL_I2C_STATE_READY ;
3625
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3626
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3627
+
3628
+ /* Process Unlocked */
3629
+ __HAL_UNLOCK (hi2c );
3630
+
3631
+ return HAL_ERROR ;
3632
+ }
3633
+ }
3634
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3635
+
3594
3636
/* Process Locked */
3595
3637
__HAL_LOCK (hi2c );
3596
3638
@@ -3757,6 +3799,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_
3757
3799
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3758
3800
}
3759
3801
3802
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3803
+ /* Wait until STOP flag is reset */
3804
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3805
+ do
3806
+ {
3807
+ count -- ;
3808
+ if (count == 0U )
3809
+ {
3810
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3811
+ hi2c -> State = HAL_I2C_STATE_READY ;
3812
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3813
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3814
+
3815
+ /* Process Unlocked */
3816
+ __HAL_UNLOCK (hi2c );
3817
+
3818
+ return HAL_ERROR ;
3819
+ }
3820
+ }
3821
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3822
+
3760
3823
/* Process Locked */
3761
3824
__HAL_LOCK (hi2c );
3762
3825
@@ -3882,6 +3945,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16
3882
3945
while (__HAL_I2C_GET_FLAG (hi2c , I2C_FLAG_BUSY ) != RESET );
3883
3946
}
3884
3947
3948
+ /* Before any new treatment like start or restart, check that there is no pending STOP request */
3949
+ /* Wait until STOP flag is reset */
3950
+ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U );
3951
+ do
3952
+ {
3953
+ count -- ;
3954
+ if (count == 0U )
3955
+ {
3956
+ hi2c -> PreviousState = I2C_STATE_NONE ;
3957
+ hi2c -> State = HAL_I2C_STATE_READY ;
3958
+ hi2c -> Mode = HAL_I2C_MODE_NONE ;
3959
+ hi2c -> ErrorCode |= HAL_I2C_ERROR_TIMEOUT ;
3960
+
3961
+ /* Process Unlocked */
3962
+ __HAL_UNLOCK (hi2c );
3963
+
3964
+ return HAL_ERROR ;
3965
+ }
3966
+ }
3967
+ while (READ_BIT (hi2c -> Instance -> CR1 , I2C_CR1_STOP ) == I2C_CR1_STOP );
3968
+
3885
3969
/* Process Locked */
3886
3970
__HAL_LOCK (hi2c );
3887
3971
@@ -4565,7 +4649,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4565
4649
UNUSED (DevAddress );
4566
4650
4567
4651
/* Abort Master transfer during Receive or Transmit process */
4568
- if (hi2c -> Mode == HAL_I2C_MODE_MASTER )
4652
+ if (( __HAL_I2C_GET_FLAG ( hi2c , I2C_FLAG_BUSY ) != RESET ) && ( hi2c -> Mode == HAL_I2C_MODE_MASTER ) )
4569
4653
{
4570
4654
/* Process Locked */
4571
4655
__HAL_LOCK (hi2c );
@@ -4596,6 +4680,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA
4596
4680
{
4597
4681
/* Wrong usage of abort function */
4598
4682
/* This function should be used only in case of abort monitored by master device */
4683
+ /* Or periphal is not in busy state, mean there is no active sequence to be abort */
4599
4684
return HAL_ERROR ;
4600
4685
}
4601
4686
}
0 commit comments