|
| 1 | +From 4aba75ec152a2d2c65d07c1912da9eb4ea08be2e Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alexandre Bourdiol < [email protected]> |
| 3 | +Date: Mon, 27 Jan 2020 18:23:15 +0100 |
| 4 | +Subject: [PATCH 1/1] [F1] I2C HAL fix: generate Start only once Stop is |
| 5 | + finished |
| 6 | + |
| 7 | +--- |
| 8 | + .../Src/stm32f1xx_hal_i2c.c | 87 ++++++++++++++++++- |
| 9 | + 1 file changed, 86 insertions(+), 1 deletion(-) |
| 10 | + |
| 11 | +diff --git a/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c b/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c |
| 12 | +index 6e74e699..fc108e0b 100644 |
| 13 | +--- a/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c |
| 14 | ++++ b/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c |
| 15 | +@@ -3492,6 +3492,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16 |
| 16 | + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); |
| 17 | + } |
| 18 | + |
| 19 | ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ |
| 20 | ++ /* Wait until STOP flag is reset */ |
| 21 | ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); |
| 22 | ++ do |
| 23 | ++ { |
| 24 | ++ count--; |
| 25 | ++ if (count == 0U) |
| 26 | ++ { |
| 27 | ++ hi2c->PreviousState = I2C_STATE_NONE; |
| 28 | ++ hi2c->State = HAL_I2C_STATE_READY; |
| 29 | ++ hi2c->Mode = HAL_I2C_MODE_NONE; |
| 30 | ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; |
| 31 | ++ |
| 32 | ++ /* Process Unlocked */ |
| 33 | ++ __HAL_UNLOCK(hi2c); |
| 34 | ++ |
| 35 | ++ return HAL_ERROR; |
| 36 | ++ } |
| 37 | ++ } |
| 38 | ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); |
| 39 | ++ |
| 40 | + /* Process Locked */ |
| 41 | + __HAL_LOCK(hi2c); |
| 42 | + |
| 43 | +@@ -3591,6 +3612,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint1 |
| 44 | + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); |
| 45 | + } |
| 46 | + |
| 47 | ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ |
| 48 | ++ /* Wait until STOP flag is reset */ |
| 49 | ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); |
| 50 | ++ do |
| 51 | ++ { |
| 52 | ++ count--; |
| 53 | ++ if (count == 0U) |
| 54 | ++ { |
| 55 | ++ hi2c->PreviousState = I2C_STATE_NONE; |
| 56 | ++ hi2c->State = HAL_I2C_STATE_READY; |
| 57 | ++ hi2c->Mode = HAL_I2C_MODE_NONE; |
| 58 | ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; |
| 59 | ++ |
| 60 | ++ /* Process Unlocked */ |
| 61 | ++ __HAL_UNLOCK(hi2c); |
| 62 | ++ |
| 63 | ++ return HAL_ERROR; |
| 64 | ++ } |
| 65 | ++ } |
| 66 | ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); |
| 67 | ++ |
| 68 | + /* Process Locked */ |
| 69 | + __HAL_LOCK(hi2c); |
| 70 | + |
| 71 | +@@ -3757,6 +3799,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_ |
| 72 | + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); |
| 73 | + } |
| 74 | + |
| 75 | ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ |
| 76 | ++ /* Wait until STOP flag is reset */ |
| 77 | ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); |
| 78 | ++ do |
| 79 | ++ { |
| 80 | ++ count--; |
| 81 | ++ if (count == 0U) |
| 82 | ++ { |
| 83 | ++ hi2c->PreviousState = I2C_STATE_NONE; |
| 84 | ++ hi2c->State = HAL_I2C_STATE_READY; |
| 85 | ++ hi2c->Mode = HAL_I2C_MODE_NONE; |
| 86 | ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; |
| 87 | ++ |
| 88 | ++ /* Process Unlocked */ |
| 89 | ++ __HAL_UNLOCK(hi2c); |
| 90 | ++ |
| 91 | ++ return HAL_ERROR; |
| 92 | ++ } |
| 93 | ++ } |
| 94 | ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); |
| 95 | ++ |
| 96 | + /* Process Locked */ |
| 97 | + __HAL_LOCK(hi2c); |
| 98 | + |
| 99 | +@@ -3882,6 +3945,27 @@ HAL_StatusTypeDef HAL_I2C_Master_Seq_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16 |
| 100 | + while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET); |
| 101 | + } |
| 102 | + |
| 103 | ++ /* Before any new treatment like start or restart, check that there is no pending STOP request */ |
| 104 | ++ /* Wait until STOP flag is reset */ |
| 105 | ++ count = I2C_TIMEOUT_BUSY_FLAG * (SystemCoreClock / 25U / 1000U); |
| 106 | ++ do |
| 107 | ++ { |
| 108 | ++ count--; |
| 109 | ++ if (count == 0U) |
| 110 | ++ { |
| 111 | ++ hi2c->PreviousState = I2C_STATE_NONE; |
| 112 | ++ hi2c->State = HAL_I2C_STATE_READY; |
| 113 | ++ hi2c->Mode = HAL_I2C_MODE_NONE; |
| 114 | ++ hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT; |
| 115 | ++ |
| 116 | ++ /* Process Unlocked */ |
| 117 | ++ __HAL_UNLOCK(hi2c); |
| 118 | ++ |
| 119 | ++ return HAL_ERROR; |
| 120 | ++ } |
| 121 | ++ } |
| 122 | ++ while (READ_BIT(hi2c->Instance->CR1, I2C_CR1_STOP) == I2C_CR1_STOP); |
| 123 | ++ |
| 124 | + /* Process Locked */ |
| 125 | + __HAL_LOCK(hi2c); |
| 126 | + |
| 127 | +@@ -4565,7 +4649,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA |
| 128 | + UNUSED(DevAddress); |
| 129 | + |
| 130 | + /* Abort Master transfer during Receive or Transmit process */ |
| 131 | +- if (hi2c->Mode == HAL_I2C_MODE_MASTER) |
| 132 | ++ if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_BUSY) != RESET) && (hi2c->Mode == HAL_I2C_MODE_MASTER)) |
| 133 | + { |
| 134 | + /* Process Locked */ |
| 135 | + __HAL_LOCK(hi2c); |
| 136 | +@@ -4596,6 +4680,7 @@ HAL_StatusTypeDef HAL_I2C_Master_Abort_IT(I2C_HandleTypeDef *hi2c, uint16_t DevA |
| 137 | + { |
| 138 | + /* Wrong usage of abort function */ |
| 139 | + /* This function should be used only in case of abort monitored by master device */ |
| 140 | ++ /* Or periphal is not in busy state, mean there is no active sequence to be abort */ |
| 141 | + return HAL_ERROR; |
| 142 | + } |
| 143 | + } |
| 144 | +-- |
| 145 | +2.25.1.windows.1 |
| 146 | + |
0 commit comments