1.
在【正点原子】I.MX6U嵌入式Linux驱动开发指南V1.81 第627页中有提到bsp_ap3216c.c中IO初始化,配置 I2C IO属性函数如下:
unsigned char ap3216c_init(void)
{
IOMUXC_SetPinMux(IOMUXC_UART4_TX_DATA_I2C1_SCL, 1);
IOMUXC_SetPinMux(IOMUXC_UART4_RX_DATA_I2C1_SDA, 1);
IOMUXC_SetPinConfig(IOMUXC_UART4_TX_DATA_I2C1_SCL, 0x70B0);
IOMUXC_SetPinConfig(IOMUXC_UART4_RX_DATA_I2C1_SDA, 0X70B0);
}
2.
要看懂这四句话,先到fsl_iomuxc.h文件中找到宏和函数的定义:
#define IOMUXC_UART4_TX_DATA_I2C1_SCL 0x020E00B4U, 0x2U, 0x020E05A4U, 0x1U, 0x020E0340U
#define IOMUXC_UART4_RX_DATA_I2C1_SDA 0x020E00B8U, 0x2U, 0x020E05A8U, 0x2U, 0x020E0344U
static inline void IOMUXC_SetPinMux(uint32_t muxRegister,
uint32_t muxMode,
uint32_t inputRegister,
uint32_t inputDaisy,
uint32_t configRegister,
uint32_t inputOnfield)
{
*((volatile uint32_t *)muxRegister) =
IOMUXC_SW_MUX_CTL_PAD_MUX_MODE(muxMode) | IOMUXC_SW_MUX_CTL_PAD_SION(inputOnfield);
if (inputRegister)
{
*((volatile uint32_t *)inputRegister) = IOMUXC_SELECT_INPUT_DAISY(inputDaisy);
}
}
static inline void IOMUXC_SetPinConfig(uint32_t muxRegister,
uint32_t muxMode,
uint32_t inputRegister,
uint32_t inputDaisy,
uint32_t configRegister,
uint32_t configValue)
{
if (configRegister)
{
*((volatile uint32_t *)configRegister) = configValue;
}
}
上面四句话展开为:
IOMUXC_SetPinMux(0x020E00B4U, 0x2U, 0x020E05A4U, 0x1U, 0x020E0340U,1)
IOMUXC_SetPinMux(0x020E00B8U, 0x2U, 0x020E05A8U, 0x2U, 0x020E0344U,1)
IOMUXC_SetPinConfig(0x020E00B4U, 0x2U, 0x020E05A4U, 0x1U, 0x020E0340U,0x70B0)
IOMUXC_SetPinConfig(0x020E00B8U, 0x2U, 0x020E05A8U, 0x2U, 0x020E0344U,0x70B0)
2.1
不难看出函数IOMUXC_SetPinMux(0x020E00B4U, 0x2U, 0x020E05A4U, 0x1U, 0x020E0340U,1)设置下面muxRegister寄存器,inputRegister寄存器
寄存器地址:0x020E00B4U
寄存器名称:SW_MUX_CTL_PAD_UART4_TX_DATA SW MUX Control Register
(IOMUXC_SW_MUX_CTL_PAD_UART4_TX_DATA)
IOMUXC_SetPinMux函数中设置语句为:
*((volatile uint32_t *)muxRegister) =
IOMUXC_SW_MUX_CTL_PAD_MUX_MODE(muxMode) | IOMUXC_SW_MUX_CTL_PAD_SION(inputOnfield);
上面两个宏的定义在MCIMX6Y2.h中
#define IOMUXC_SW_MUX_CTL_PAD_MUX_MODE(x) (((uint32_t)(((uint32_t)(x)) << IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_SHIFT)) & IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_MASK)
#define IOMUXC_SW_MUX_CTL_PAD_SION(x) (((uint32_t)(((uint32_t)(x)) << IOMUXC_SW_MUX_CTL_PAD_SION_SHIFT)) & IOMUXC_SW_MUX_CTL_PAD_SION_MASK)
最终设置 muxRegister value为0010 既手册中:
ALT2 — Select mux mode: ALT2 mux port: I2C1_SCL of instance: i2c1
2.2
寄存器地址:0x020E05A4U
寄存器名称:I2C1_SCL_SELECT_INPUT DAISY Register
(IOMUXC_I2C1_SCL_SELECT_INPUT)
IOMUXC_SetPinMux函数中设置语句为:
*((volatile uint32_t *)inputRegister) = IOMUXC_SELECT_INPUT_DAISY(inputDaisy);
上面IOMUXC_SELECT_INPUT_DAISY这个宏的定义也在MCIMX6Y2.h中
#define IOMUXC_SELECT_INPUT_DAISY(x) (((uint32_t)(((uint32_t)(x)) << IOMUXC_SELECT_INPUT_DAISY_SHIFT)) & IOMUXC_SELECT_INPUT_DAISY_MASK)
最终会设置 inputRegister value 为01,既UART4_TX_DATA 设置为ALT2:
UART4_TX_DATA 设置为ALT2,既复用为I2C1:
2.3
函数IOMUXC_SetPinConfig(0x020E00B4U, 0x2U, 0x020E05A4U, 0x1U, 0x020E0340U,0x70B0)设置configRegister寄存器
寄存器地址:0x020E0340U
寄存器名称:SW_PAD_CTL_PAD_UART4_TX_DATA SW PAD Control Register
(IOMUXC_SW_PAD_CTL_PAD_UART4_TX_DATA)
IOMUXC_SetPinConfig函数中设置语句为:
*((volatile uint32_t *)configRegister) = configValue;
set configRegister value with: 0x70B0
既设置了引脚的电气特性:
另外两个函数同理推导。