From 2dbf9acc71e28139d6e1ccd0f4c74cb7a16bbca5 Mon Sep 17 00:00:00 2001 From: Rbb666 <64397326+Rbb666@users.noreply.github.com> Date: Tue, 18 Jul 2023 11:59:20 +0800 Subject: [PATCH] [bsp][Infineon]fix i2c init error (#7817) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加iic4的配置,将初始化错误断言部分修改为打印方式 --- bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c | 50 ++++++++++++++----- .../psoc6-evaluationkit-062S2/board/Kconfig | 35 ++++--------- .../psoc6-evaluationkit-062S2/board/board.h | 2 +- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c b/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c index 079d4b16de..df05462bf3 100644 --- a/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c +++ b/bsp/Infineon/libraries/HAL_Drivers/drv_i2c.c @@ -11,9 +11,18 @@ #include "board.h" #if defined(RT_USING_I2C) -#if defined(BSP_USING_HW_I2C3) || defined(BSP_USING_HW_I2C4) || defined(BSP_USING_HW_I2C6) +#if defined(BSP_USING_HW_I2C2) || defined(BSP_USING_HW_I2C3) || defined(BSP_USING_HW_I2C4)|| defined(BSP_USING_HW_I2C6) #include +#ifndef I2C2_CONFIG +#define I2C2_CONFIG \ + { \ + .name = "i2c2", \ + .scl_pin = BSP_I2C2_SCL_PIN, \ + .sda_pin = BSP_I2C2_SDA_PIN, \ + } +#endif /* I2C2_CONFIG */ + #ifndef I2C3_CONFIG #define I2C3_CONFIG \ { \ @@ -40,11 +49,13 @@ .sda_pin = BSP_I2C6_SDA_PIN, \ } #endif /* I2C6_CONFIG */ - #endif /* defined(BSP_USING_I2C1) || defined(BSP_USING_I2C2) */ enum { +#ifdef BSP_USING_HW_I2C2 + I2C2_INDEX, +#endif #ifdef BSP_USING_HW_I2C3 I2C3_INDEX, #endif @@ -72,17 +83,21 @@ struct ifx_i2c }; static struct ifx_i2c_config i2c_config[] = - { +{ +#ifdef BSP_USING_HW_I2C2 + I2C2_CONFIG, +#endif + #ifdef BSP_USING_HW_I2C3 - I2C3_CONFIG, + I2C3_CONFIG, #endif #ifdef BSP_USING_HW_I2C4 - I2C4_CONFIG, + I2C4_CONFIG, #endif #ifdef BSP_USING_HW_I2C6 - I2C6_CONFIG, + I2C6_CONFIG, #endif }; @@ -145,20 +160,29 @@ out: } static const struct rt_i2c_bus_device_ops i2c_ops = - { - _i2c_xfer, - RT_NULL, - RT_NULL}; +{ + _i2c_xfer, + RT_NULL, + RT_NULL +}; void HAL_I2C_Init(struct ifx_i2c *obj) { - rt_uint8_t result = RT_EOK; + cy_rslt_t result = CY_RSLT_SUCCESS; result = cyhal_i2c_init(&obj->mI2C, obj->config->sda_pin, obj->config->scl_pin, NULL); - RT_ASSERT(result == RT_EOK); + if (result != CY_RSLT_SUCCESS) + { + rt_kprintf("hal i2c init fail!\n"); + return; + } result = cyhal_i2c_configure(&obj->mI2C, &obj->mI2C_cfg); - RT_ASSERT(result == RT_EOK); + if (result != CY_RSLT_SUCCESS) + { + rt_kprintf("hal i2c configure fail!\n"); + return; + } } int rt_hw_i2c_init(void) diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig index 84005737f6..346d12fc35 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/board/Kconfig @@ -14,6 +14,7 @@ menu "Onboard Peripheral Drivers" select BSP_USING_UART select BSP_USING_UART6 default y + endmenu menu "On-chip Peripheral Drivers" @@ -141,19 +142,19 @@ menu "On-chip Peripheral Drivers" select RT_USING_I2C select RT_USING_PIN if BSP_USING_HW_I2C - config BSP_USING_HW_I2C3 - bool "Enable I2C3 Bus (User I2C)" + config BSP_USING_HW_I2C2 + bool "Enable I2C2 Bus (User I2C)" default n - if BSP_USING_HW_I2C3 - comment "Notice: P6_0 --> 48; P6_1 --> 49" - config BSP_I2C3_SCL_PIN - int "i2c3 SCL pin number" + if BSP_USING_HW_I2C2 + comment "Notice: P3_0 --> 24; P3_1 --> 25" + config BSP_I2C2_SCL_PIN + int "i2c2 SCL pin number" range 1 113 - default 48 - config BSP_I2C3_SDA_PIN - int "i2c3 SDA pin number" + default 24 + config BSP_I2C2_SDA_PIN + int "i2c2 SDA pin number" range 1 113 - default 49 + default 25 endif config BSP_USING_HW_I2C4 bool "Enable I2C4 Bus (Arduino I2C)" @@ -169,20 +170,6 @@ menu "On-chip Peripheral Drivers" range 1 113 default 65 endif - config BSP_USING_HW_I2C6 - bool "Enable I2C6 Bus (User I2C)" - default n - if BSP_USING_HW_I2C6 - comment "Notice: P13_0 --> 48; P13_1 --> 49" - config BSP_I2C6_SCL_PIN - int "i2c6 SCL pin number" - range 1 113 - default 104 - config BSP_I2C6_SDA_PIN - int "i2c6 SDA pin number" - range 1 113 - default 105 - endif endif menuconfig BSP_USING_I2C diff --git a/bsp/Infineon/psoc6-evaluationkit-062S2/board/board.h b/bsp/Infineon/psoc6-evaluationkit-062S2/board/board.h index 2e6db4780d..80c71b3da6 100644 --- a/bsp/Infineon/psoc6-evaluationkit-062S2/board/board.h +++ b/bsp/Infineon/psoc6-evaluationkit-062S2/board/board.h @@ -39,7 +39,7 @@ #define IFX_EFLASH_END_ADDRESS ((uint32_t)(IFX_EFLASH_START_ADRESS + IFX_EFLASH_SIZE)) /*SRAM CONFIG*/ -#define IFX_SRAM_SIZE (1013) +#define IFX_SRAM_SIZE (1010) #define IFX_SRAM_END (0x08002000 + IFX_SRAM_SIZE * 1024) #ifdef __ARMCC_VERSION