Rewrore STM32F4 HAL_I2C_MspDeInit to not call HAL_GPIO_DeInit(), but only disable I2C GPIO with GPIO_Init().

This commit is contained in:
rotorman
2021-07-16 18:40:52 +02:00
parent a886c72a55
commit 5f0bac3dc9
2 changed files with 22 additions and 11 deletions
+20 -9
View File
@@ -145,20 +145,31 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
if(hi2c->Instance==I2C1) if(hi2c->Instance==I2C1)
{ {
__HAL_RCC_I2C1_CLK_DISABLE(); __HAL_RCC_I2C1_CLK_DISABLE();
} else }
else
{ {
if(hi2c->Instance==I2C2) if(hi2c->Instance==I2C2)
{ {
__HAL_RCC_I2C2_CLK_DISABLE(); __HAL_RCC_I2C2_CLK_DISABLE();
if(hi2c->Instance==I2C3) if(hi2c->Instance==I2C3)
{ __HAL_RCC_I2C3_CLK_DISABLE();
__HAL_RCC_I2C3_CLK_DISABLE(); else
} else TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration");
TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration");
} }
} }
HAL_GPIO_DeInit(I2C_GPIO, I2C_SCL_GPIO_PinSource);
HAL_GPIO_DeInit(I2C_GPIO, I2C_SDA_GPIO_PinSource); GPIO_InitTypeDef GPIO_InitStructure;
/* Configure the default Alternate Function in current IO */
GPIO_PinAFConfig(I2C_GPIO, I2C_SCL_GPIO_PinSource, 0);
GPIO_PinAFConfig(I2C_GPIO, I2C_SDA_GPIO_PinSource, 0);
GPIO_InitStructure.GPIO_Pin = I2C_SCL_GPIO_PIN | I2C_SDA_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; /* Configure a low value for IO Speed */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; /* Configure IO Direction in Input Floating Mode */
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; /* Leave the configuration to Open Drain */
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; /* Deactivate the Pull-up and Pull-down resistor for the current IO */
GPIO_Init(I2C_GPIO, &GPIO_InitStructure);
} }
/* Initializes the I2C according to the specified parameters /* Initializes the I2C according to the specified parameters
+2 -2
View File
@@ -546,13 +546,13 @@ bool I2C_GT911_ReadRegister(uint16_t reg, uint8_t * buf, uint8_t len)
if (HAL_I2C_Master_Transmit(&hi2c1, GT911_I2C_ADDR << 1, uRegAddr, 2, 10) != 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"); TRACE("I2C ERROR: ReadRegister write reg address failed");
return false; return false;
} }
if (HAL_I2C_Master_Receive(&hi2c1, GT911_I2C_ADDR << 1, buf, len, 100) != 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"); TRACE("I2C ERROR: ReadRegister read reg address failed");
return false; return false;
} }
return true; return true;