From 5f0bac3dc94a9ee3f4307c4a1dea6dacbd5787b0 Mon Sep 17 00:00:00 2001 From: rotorman Date: Fri, 16 Jul 2021 18:40:52 +0200 Subject: [PATCH] Rewrore STM32F4 HAL_I2C_MspDeInit to not call HAL_GPIO_DeInit(), but only disable I2C GPIO with GPIO_Init(). --- radio/src/targets/horus/i2c_driver.cpp | 29 ++++++++++++++++++-------- radio/src/targets/horus/tp_gt911.cpp | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/radio/src/targets/horus/i2c_driver.cpp b/radio/src/targets/horus/i2c_driver.cpp index 251b40f68..1bd9b403d 100644 --- a/radio/src/targets/horus/i2c_driver.cpp +++ b/radio/src/targets/horus/i2c_driver.cpp @@ -145,20 +145,31 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c) if(hi2c->Instance==I2C1) { __HAL_RCC_I2C1_CLK_DISABLE(); - } else + } + else { if(hi2c->Instance==I2C2) { - __HAL_RCC_I2C2_CLK_DISABLE(); - if(hi2c->Instance==I2C3) - { - __HAL_RCC_I2C3_CLK_DISABLE(); - } else - TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration"); + __HAL_RCC_I2C2_CLK_DISABLE(); + if(hi2c->Instance==I2C3) + __HAL_RCC_I2C3_CLK_DISABLE(); + else + 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 diff --git a/radio/src/targets/horus/tp_gt911.cpp b/radio/src/targets/horus/tp_gt911.cpp index b49d34a7a..b9065ad54 100644 --- a/radio/src/targets/horus/tp_gt911.cpp +++ b/radio/src/targets/horus/tp_gt911.cpp @@ -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) { - TRACE("I2C ERROR: ReadRedister write reg address failed"); + TRACE("I2C ERROR: ReadRegister write reg address failed"); return false; } 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 true;