【目的】
移植NXP-MCXA153。目前官方提供的rtt-bsp驱动只提供了Pin与uart,其他的驱动还没有更新。我这次是移植基于i2c的硬件i2c驱动。
【源码下载】
下载****:https://gitee.com/rtthread/rt-thread
【移植过程】
1、编写drv_i2c驱动,驱动的主要源代码是复制mcxn下的drv_i2c.c
2、根据原官方的sdk,需要修改驱动中的baud、clock_attach_id、clock_div_name
struct lpc_i2c_bus lpc_obj[] = { #ifdef BSP_USING_I2C0 { .I2C = LPI2C0, .baud = 1000000U, //总线速度 .clock_attach_id = kFRO12M_to_LPI2C0, /*!< Attach FRO12M to LPI2C0. */ .clock_div_name = kCLOCK_DivLPI2C0, /*!< LPI2C0 clock divider */ .clock_src = kCLOCK_Fro12M, .name = "i2c0", }, #endif };
3、在pin_mux.c中添加复位i2c0的代码:
/* LPI2C0 peripheral is released from reset */ RESET_ReleasePeripheralReset(kLPI2C0_RST_SHIFT_RSTn);
根据原理图,i2c0的SCL与SDA的引脚为P3_27,P3_28,添加io的配置代码:
const port_pin_config_t port3_27_pin34_config = {/* Internal pull-up resistor is enabled */ kPORT_PullUp, /* Low internal pull resistor value is selected. */ kPORT_LowPullResistor, /* Fast slew rate is configured */ kPORT_FastSlewRate, /* Passive input filter is disabled */ kPORT_PassiveFilterDisable, /* Open drain output is enabled */ kPORT_OpenDrainEnable, /* Low drive strength is configured */ kPORT_LowDriveStrength, /* Normal drive strength is configured */ kPORT_NormalDriveStrength, /* Pin is configured as LPI2C0_SCL */ kPORT_MuxAlt2, /* Digital input enabled */ kPORT_InputBufferEnable, /* Digital input is not inverted */ kPORT_InputNormal, /* Pin Control Register fields [15:0] are not locked */ kPORT_UnlockRegister}; /* PORT3_27 (pin 34) is configured as LPI2C0_SCL */ PORT_SetPinConfig(PORT3, 27U, &port3_27_pin34_config); const port_pin_config_t port3_28_pin33_config = {/* Internal pull-up resistor is enabled */ kPORT_PullUp, /* Low internal pull resistor value is selected. */ kPORT_LowPullResistor, /* Fast slew rate is configured */ kPORT_FastSlewRate, /* Passive input filter is disabled */ kPORT_PassiveFilterDisable, /* Open drain output is enabled */ kPORT_OpenDrainEnable, /* Low drive strength is configured */ kPORT_LowDriveStrength, /* Normal drive strength is configured */ kPORT_NormalDriveStrength, /* Pin is configured as LPI2C0_SDA */ kPORT_MuxAlt2, /* Digital input enabled */ kPORT_InputBufferEnable, /* Digital input is not inverted */ kPORT_InputNormal, /* Pin Control Register fields [15:0] are not locked */ kPORT_UnlockRegister}; /* PORT3_28 (pin 33) is configured as LPI2C0_SDA */ PORT_SetPinConfig(PORT3, 28U, &port3_28_pin33_config);
编译后顺利通过。
4、打开env图形配置工具,打开i2c0
5、使用 scons --target=mdk5生成工程。
6、编译下载到开发板,使用list device可以看到初始化好了i2c0
致此i2c0移植成功