创建时间: | 2022/1/14 11:28 |
更新时间: | 2022/2/16 17:12 |
作者: | gi51wa2j |
标签: | 100ask_IMX6ULL_v11, bingo, 操作, 正文 |
②看主芯片的芯片手册,确定如何设置控制这个引脚;
③写程序。
方式2:使用引脚拉低到0V点亮LED,输出3.3V熄灭LED。
方式3:使用引脚输出1.2V点亮LED,输出0V熄灭LED。(引脚驱动能力不足时使用三极管)
方式4:使用引脚输出0V点亮LED,输出1.2V熄灭LED。
/* a. 使能GPIO5
* set CCM to enable GPIO5
* CCM_CCGR1[CG15] 0x20C406C
* bit[31:30] = 0b11
*/
* 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
*/
* set GPIO5_GDIR to configure GPIO5_IO03 as output
* GPIO5_GDIR 0x020AC000 + 0x4
* bit[3] = 0b1
*/
/* d. 设置GPIO5_DR输出低电平
* set GPIO5_DR to configure GPIO5_IO03 output 0
* GPIO5_DR 0x020AC000 + 0
* bit[3] = 0b0
*/
/* e. 设置GPIO5_IO3输出高电平
* set GPIO5_DR to configure GPIO5_IO03 output 1
* GPIO5_DR 0x020AC000 + 0
* bit[3] = 0b1
*/
led.c是重点,其他文件暂且不关心,比如Makefile、imx6ull.lds,这些文件的知识在后面再介绍。
值得关注的是第13~16行,在C语言中使用指针来访问寄存器,需要先设置指针的值,即它指向哪个地址──当然是寄存器的地址:
02 #include "led.h"
03
04 static volatile unsigned int *CCM_CCGR1 ;
05 static volatile unsigned int *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3;
06 static volatile unsigned int *GPIO5_GDIR ;
07 static volatile unsigned int *GPIO5_DR ;
08
09 void led_init(void)
10 {
11 unsigned int val;
12
13 CCM_CCGR1 = (volatile unsigned int *)(0x20C406C);
14 IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = (volatile unsigned int *)(0x2290014);
15 GPIO5_GDIR = (volatile unsigned int *)(0x020AC000 + 0x4);
16 GPIO5_DR = (volatile unsigned int *)(0x020AC000);
17
18 /* GPIO5_IO03 */
19 /* a. 使能GPIO5
20 * set CCM to enable GPIO5
21 * CCM_CCGR1[CG15] 0x20C406C
22 * bit[31:30] = 0b11
23 */
24 *CCM_CCGR1 |= (3<<30);
25
26 /* b. 设置GPIO5_IO03用于GPIO
27 * set IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3
28 * to configure GPIO5_IO03 as GPIO
29 * IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 0x2290014
30 * bit[3:0] = 0b0101 alt5
31 */
32 val = *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3; //临时变量
33 val &= ~(0xf); //清零
34 val |= (5); //置位
35 *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = val;
36
37
38 /* c. 设置GPIO5_IO03作为output引脚
39 * set GPIO5_GDIR to configure GPIO5_IO03 as output
40 * GPIO5_GDIR 0x020AC000 + 0x4
41 * bit[3] = 0b1
42 */
43 *GPIO5_GDIR |= (1<<3);
44
45 }
46
48 {
49 if (on) /* on: output 0*/
50 {
51 /* d. 设置GPIO5_DR输出低电平
52 * set GPIO5_DR to configure GPIO5_IO03 output 0
53 * GPIO5_DR 0x020AC000 + 0
54 * bit[3] = 0b0
55 */
56 *GPIO5_DR &= ~(1<<3);
57 }
58 else /* off: output 1*/
59 {
60 /* e. 设置GPIO5_IO3输出高电平
61 * set GPIO5_DR to configure GPIO5_IO03 output 1
62 * GPIO5_DR 0x020AC000 + 0
63 * bit[3] = 0b1
64 */
65 *GPIO5_DR |= (1<<3);
66 }
67 }
ROM上的固件根据EMMC或TF卡上1K偏移处的头部信息,把led.bin复制到0x80100000处,并运行
第一条指令把栈设置为0x80100000
程序从0x80100000向上运行,栈从0x80100000向下增长