Clear ADDR bit in atomic way. Not in original STM32F4 HAL.
Lower timeouts to more reasonable values.
This commit is contained in:
@@ -28,8 +28,7 @@ uint32_t GetTickCountMS(void)
|
||||
{
|
||||
static uint32_t tickcount = 0;
|
||||
tickcount++;
|
||||
return (tickcount >> 10);
|
||||
//return (ticksNow()/CYCLES_IN_MS);
|
||||
return (tickcount >> 11); // division with 2048, roughly to get milliseconds
|
||||
}
|
||||
|
||||
/* I2C MSP Initialization
|
||||
@@ -396,7 +395,7 @@ static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uin
|
||||
/* Check for the Timeout */
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U)) // Original HAL_GetTick()
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
hi2c->PreviousState = I2C_STATE_NONE;
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
@@ -447,7 +446,7 @@ static HAL_StatusTypeDef I2C_WaitOnMasterAddressFlagUntilTimeout(I2C_HandleTypeD
|
||||
/* Check for the Timeout */
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U)) // Original HAL_GetTick()
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
hi2c->PreviousState = I2C_STATE_NONE;
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
@@ -577,7 +576,7 @@ static HAL_StatusTypeDef I2C_WaitOnTXEFlagUntilTimeout(I2C_HandleTypeDef *hi2c,
|
||||
/* Check for the Timeout */
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U)) // Original: HAL_GetTick()
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
hi2c->PreviousState = I2C_STATE_NONE;
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
@@ -614,7 +613,7 @@ static HAL_StatusTypeDef I2C_WaitOnBTFFlagUntilTimeout(I2C_HandleTypeDef *hi2c,
|
||||
/* Check for the Timeout */
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U)) // Original HAL_GetTick()
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
hi2c->PreviousState = I2C_STATE_NONE;
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
@@ -644,7 +643,7 @@ static HAL_StatusTypeDef I2C_WaitOnBTFFlagUntilTimeout(I2C_HandleTypeDef *hi2c,
|
||||
HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
/* Init tickstart for timeout management*/
|
||||
uint32_t tickstart = GetTickCountMS(); // Original: HAL_GetTick();
|
||||
uint32_t tickstart = GetTickCountMS();
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
@@ -878,7 +877,7 @@ static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout(I2C_HandleTypeDef *hi2c,
|
||||
}
|
||||
|
||||
/* Check for the Timeout */
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U)) // Original HAL_GetTick()
|
||||
if (((GetTickCountMS() - Tickstart) > Timeout) || (Timeout == 0U))
|
||||
{
|
||||
hi2c->PreviousState = I2C_STATE_NONE;
|
||||
hi2c->State = HAL_I2C_STATE_READY;
|
||||
@@ -907,7 +906,7 @@ static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout(I2C_HandleTypeDef *hi2c,
|
||||
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
||||
{
|
||||
/* Init tickstart for timeout management*/
|
||||
uint32_t tickstart = GetTickCountMS(); // Original HAL_GetTick();
|
||||
uint32_t tickstart = GetTickCountMS();
|
||||
|
||||
if (hi2c->State == HAL_I2C_STATE_READY)
|
||||
{
|
||||
|
||||
@@ -234,8 +234,10 @@
|
||||
#define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \
|
||||
do{ \
|
||||
__IO uint32_t tmpreg = 0x00U; \
|
||||
__disable_irq(); \
|
||||
tmpreg = (__HANDLE__)->Instance->SR1; \
|
||||
tmpreg = (__HANDLE__)->Instance->SR2; \
|
||||
__enable_irq(); \
|
||||
UNUSED(tmpreg); \
|
||||
} while(0)
|
||||
|
||||
@@ -307,7 +309,6 @@ typedef enum
|
||||
HAL_I2C_STATE_ABORT = 0x60U, /*!< Abort user request ongoing */
|
||||
HAL_I2C_STATE_TIMEOUT = 0xA0U, /*!< Timeout state */
|
||||
HAL_I2C_STATE_ERROR = 0xE0U /*!< Error */
|
||||
|
||||
} HAL_I2C_StateTypeDef;
|
||||
|
||||
/* HAL Mode structure definition
|
||||
@@ -332,7 +333,6 @@ typedef enum
|
||||
HAL_I2C_MODE_MASTER = 0x10U, /*!< I2C communication is in Master Mode */
|
||||
HAL_I2C_MODE_SLAVE = 0x20U, /*!< I2C communication is in Slave Mode */
|
||||
HAL_I2C_MODE_MEM = 0x40U /*!< I2C communication is in Memory Mode */
|
||||
|
||||
} HAL_I2C_ModeTypeDef;
|
||||
|
||||
// I2C configuration structure definition
|
||||
|
||||
@@ -530,7 +530,7 @@ bool I2C_GT911_WriteRegister(uint16_t reg, uint8_t * buf, uint8_t len)
|
||||
}
|
||||
}
|
||||
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, GT911_I2C_ADDR << 1, uAddrAndBuf, len + 2, 10000) != HAL_OK)
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, GT911_I2C_ADDR << 1, uAddrAndBuf, len + 2, 100) != HAL_OK)
|
||||
{
|
||||
TRACE("I2C ERROR: WriteRegister failed");
|
||||
return false;
|
||||
@@ -544,13 +544,13 @@ bool I2C_GT911_ReadRegister(uint16_t reg, uint8_t * buf, uint8_t len)
|
||||
uRegAddr[0] = (uint8_t)((reg & 0xFF00) >> 8);
|
||||
uRegAddr[1] = (uint8_t)(reg & 0x00FF);
|
||||
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, GT911_I2C_ADDR << 1, uRegAddr, 2, 10000) != HAL_OK)
|
||||
if (HAL_I2C_Master_Transmit(&hi2c1, GT911_I2C_ADDR << 1, uRegAddr, 2, 10) != HAL_OK)
|
||||
{
|
||||
TRACE("I2C ERROR: ReadRedister write reg address failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, GT911_I2C_ADDR << 1, buf, len, 10000) != HAL_OK)
|
||||
if (HAL_I2C_Master_Receive(&hi2c1, GT911_I2C_ADDR << 1, buf, len, 100) != HAL_OK)
|
||||
{
|
||||
TRACE("I2C ERROR: ReadRedister read reg address failed");
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user