From ec539bc930af1b91c6bf9758160b0150f9316c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=93=E7=9B=B9=E7=9A=84=E6=B6=88=E9=98=B2=E8=BD=A6?= <1473454180@qq.com> Date: Mon, 11 Apr 2022 17:34:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Di2c=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5794)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:修复i2c异常问题 * add:格式化代码格式 --- .../libraries/HAL_Driver/Src/core_i2c.c | 25 ++++++++++++++++--- .../air105/libraries/rt_drivers/drv_i2c.c | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bsp/airm2m/air105/libraries/HAL_Driver/Src/core_i2c.c b/bsp/airm2m/air105/libraries/HAL_Driver/Src/core_i2c.c index a1c452903b..f0f17c3dec 100644 --- a/bsp/airm2m/air105/libraries/HAL_Driver/Src/core_i2c.c +++ b/bsp/airm2m/air105/libraries/HAL_Driver/Src/core_i2c.c @@ -20,7 +20,7 @@ */ #include "user.h" -//#define IIC_DBG(X,Y...) + #define IIC_DBG DBG enum { @@ -81,10 +81,18 @@ static int32_t prvI2C_DummyCB(void *pData, void *pParam) static void I2C_IrqHandle(int32_t IrqLine, void *pData) { + int32_t result = ERROR_NONE; I2C_TypeDef *I2C = prvI2C.RegBase; + uint32_t Source = I2C->IC_TX_ABRT_SOURCE; uint32_t State = I2C->IC_RAW_INTR_STAT; uint32_t RegValue = I2C->IC_CLR_INTR; + if (Source & 0x0000ffff) + { + result = -ERROR_OPERATION_FAILED; + goto I2C_DONE; + } + switch(prvI2C.State) { case I2C_STATE_WRITE_ADDRESS: @@ -144,20 +152,29 @@ static void I2C_IrqHandle(int32_t IrqLine, void *pData) } break; default: -// IIC_DBG("%x, %u", State, prvI2C.State); break; } return; I2C_DONE: I2C->IC_INTR_MASK = 0; - prvI2C_Done(ERROR_NONE); + prvI2C_Done(result); } static void I2C_IrqHandleRegQueue(int32_t IrqLine, void *pData) { + int32_t result = ERROR_NONE; I2C_TypeDef *I2C = prvI2C.RegBase; + uint32_t Source = I2C->IC_TX_ABRT_SOURCE; uint32_t State = I2C->IC_RAW_INTR_STAT; uint32_t RegValue = I2C->IC_CLR_INTR; + + if (Source & 0x0000ffff) + { + + result = -ERROR_OPERATION_FAILED; + goto I2C_DONE; + } + if (State & I2C_IT_TXE) { if (prvI2C.DataBuf.Pos >= prvI2C.DataBuf.MaxLen) @@ -189,7 +206,7 @@ static void I2C_IrqHandleRegQueue(int32_t IrqLine, void *pData) return; I2C_DONE: I2C->IC_INTR_MASK = 0; - prvI2C_Done(ERROR_NONE); + prvI2C_Done(result); } void I2C_GlobalInit(void) diff --git a/bsp/airm2m/air105/libraries/rt_drivers/drv_i2c.c b/bsp/airm2m/air105/libraries/rt_drivers/drv_i2c.c index ed0b43bb52..ca8feab600 100644 --- a/bsp/airm2m/air105/libraries/rt_drivers/drv_i2c.c +++ b/bsp/airm2m/air105/libraries/rt_drivers/drv_i2c.c @@ -112,6 +112,8 @@ int air105_hw_i2c_init(void) prv_air105_i2c.ops = &air105_i2c_ops; prv_air105_i2c.priv = 0; I2C_MasterSetup(0, 400000); + GPIO_Iomux(GPIOE_06, 2); + GPIO_Iomux(GPIOE_07, 2); #ifdef I2C_BUS_NAME rt_i2c_bus_device_register(&prv_air105_i2c, I2C_BUS_NAME); #else