当我使用宏定义来访问imx6ull的寄存器,控制GPIO5_IO3输出高低电平控制LED时,程序烧录进去后没有反应。但是当我使用指针来访问寄存器,LED可以正常驱动,请问这是什么原因?除了寄存器访问方式外,其余.s启动文件,.lds链接文件,Makefile文件完全相同。
下面代码使用指针来配置寄存器,程序正常运行。
volatile unsigned int *CCM_CCGR1 ;volatile unsigned int *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3;volatile unsigned int *IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3;volatile unsigned int *GPIO5_GDIR ;volatile unsigned int *GPIO5_DR ;// #define CCM_CCGR1 ((volatile unsigned int*)0x020C406C) //CCGR1// #define IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 ((volatile unsigned int*)0x02290014) //IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3// #define IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 ((volatile unsigned int*)0x02290058) // #define GPIO5_GDIR ((volatile unsigned int*)0x020AC004)// #define GPIO5_DR ((volatile unsigned int*)0x020AC000)void delay(volatile unsigned int d){ while(d--); }int main(){ unsigned int val; CCM_CCGR1 = (volatile unsigned int *)(0x20C406C); IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = (volatile unsigned int *)(0x2290014); IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 = (volatile unsigned int *)(0x2290058); GPIO5_GDIR = (volatile unsigned int *)(0x020AC000 + 0x4); GPIO5_DR = (volatile unsigned int *)(0x020AC000); /* GPIO5_IO03 */ /* a. 使能GPIO5 * set CCM to enable GPIO5 * CCM_CCGR1[CG15] 0x20C406C */ *CCM_CCGR1 = 0xFFFFFFFF; /* b. 设置GPIO5_IO03用于GPIO * set IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 * to configure GPIO5_IO03 as GPIO * IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 0x2290014 * bit[3:0] = 0b0101 alt5 */ val = 5; *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = val; *IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 = 0x10b0; /* c. 设置GPIO5_IO03作为output引脚 * set GPIO5_GDIR to configure GPIO5_IO03 as output * GPIO5_GDIR 0x020AC000 + 0x4 * bit[3] = 0b1 */ *GPIO5_GDIR = 0xFFFFFFFF; while(1) { *GPIO5_DR = 0x00000000; //输出低电平,点亮LED delay(1000000); *GPIO5_DR = 0xFFFFFFFF; //输出高电平,关闭LED delay(1000000); } return 0; }
下面代码使用宏定义配置寄存器,程序无反应。
/* // volatile unsigned int *CCM_CCGR1 ; // volatile unsigned int *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3; // volatile unsigned int *IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3; // volatile unsigned int *GPIO5_GDIR ; // volatile unsigned int *GPIO5_DR ; */#define CCM_CCGR1 ((volatile unsigned int*)0x020C406C) #define IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 ((volatile unsigned int*)0x02290014) #define IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 ((volatile unsigned int*)0x02290058) #define GPIO5_GDIR ((volatile unsigned int*)0x020AC004)#define GPIO5_DR ((volatile unsigned int*)0x020AC000)void delay(volatile unsigned int d){ while(d--); }int main(){ unsigned int val; // CCM_CCGR1 = (volatile unsigned int *)(0x20C406C); // IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = (volatile unsigned int *)(0x2290014); // IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 = (volatile unsigned int *)(0x2290058); // GPIO5_GDIR = (volatile unsigned int *)(0x020AC000 + 0x4); // GPIO5_DR = (volatile unsigned int *)(0x020AC000); /* GPIO5_IO03 */ /* a. 使能GPIO5 * set CCM to enable GPIO5 * CCM_CCGR1[CG15] 0x20C406C * bit[31:30] = 0b11 */ *CCM_CCGR1 = 0xFFFFFFFF; /* b. 设置GPIO5_IO03用于GPIO * set IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 * to configure GPIO5_IO03 as GPIO * IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 0x2290014 * bit[3:0] = 0b0101 alt5 */ val = 5; *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = val; *IOMUXC_SNVS_SW_PAD_CTL_PAD_SNVS_TAMPER3 = 0x10b0; /* c. 设置GPIO5_IO03作为output引脚 * set GPIO5_GDIR to configure GPIO5_IO03 as output * GPIO5_GDIR 0x020AC000 + 0x4 * bit[3] = 0b1 */ *GPIO5_GDIR = 0xFFFFFFFF; while(1) { *GPIO5_DR = 0x00000000;//输出低电平,点亮LED delay(1000000); *GPIO5_DR = 0xFFFFFFFF;//输出高电平,熄灭LED delay(1000000); } return 0; }