GPIO(General-purpose input/output)即通用型输入输出,GPIO可以控制连接在其之上的引脚实现信号的输入和输出
芯片的引脚与外部设备相连,从而实现与外部硬件设备的通讯、控制及信号采集等功能
实验步骤
1. 通过电路原理图分析LED的控制逻辑
2. 通过电路原理图查找LED与Exynos4412的连接关系
3. 通过数据手册分析GPIO中哪些寄存器可以控制LED
4. 通过程序去操控对应的寄存器完成对LED的控制
高电平导通,低电平截止
该实验需要输出,所以就是Output模式,GPX2CON[7] = 0x1
输出高电平就对应位写1,输出低电平就对应位写0
预处理->编译->汇编->链接
gcc -E
gcc -S
gcc -c
gcc
链接使用的工具是ld,objcopy是对可执行文件进行转化
.elf是Linux可执行文件的后缀
-Ttext 0x40005000 是将程序放到内存上,保证程序可以执行。
led-asm.s:
- .text
- _start:
-
- LED_CONFIG:
- LDR R2, =0x11000c40
- LDR R1, =0x10000000
- STR R1, [R2]
-
- LED_ON:
- LDR R2, =0x11000c44
- LDR R1, =0x00000080
- STR R1, [R2]
- B STOP
-
- LED_OFF:
- LDR R2, =0x11000c44
- LDR R1, =0x00000000
- STR R1, [R2]
-
- STOP:
- B STOP
- .end
Makefile:
- TARGET = led-asm
- CROSS_COMPILE = arm-none-linux-gnueabi-
- CC = $(CROSS_COMPILE)gcc
- LD = $(CROSS_COMPILE)ld
- OBJCOPY = $(CROSS_COMPILE)objcopy
-
- all:
- $(CC) -c $(TARGET).s -o $(TARGET).o
- $(LD) $(TARGET).o -Ttext 0x40005000 -o $(TARGET).elf
- $(OBJCOPY) -O binary -S $(TARGET).elf $(TARGET).bin
-
- clean:
- rm $(TARGET).o $(TARGET).elf $(TARGET).bin
然后通过共享文件夹吧编译好的.bin文件传给windows
先输入loadb 0x40008000,把程序下载到0x40008000地址,然后发送Kermit协议的文件,选择led-asm.bin文件,然后输入go 0x40008000,跳转到0x40008000地址执行程序。led就会熄灭。
写一个程序让LED2闪烁
- .text
- _start:
-
- MAIN:
- BL LED_CONFIG
- LOOP:
- BL LED_ON
- BL DELAY
- BL LED_OFF
- BL DELAY
- B LOOP
-
- LED_CONFIG:
- LDR R2, =0x11000c40
- LDR R1, =0x10000000
- STR R1, [R2]
- MOV PC, LR
-
- LED_ON:
- LDR R2, =0x11000c44
- LDR R1, =0x00000080
- STR R1, [R2]
- MOV PC, LR
-
- LED_OFF:
- LDR R2, =0x11000c44
- LDR R1, =0x00000000
- STR R1, [R2]
- MOV PC, LR
- DELAY:
- LDR R1, =100000000
- L:
- SUB R1, R1, #1
- CMP R1, #0
- BNE L
- MOV PC, LR
-
- STOP:
- B STOP
- .end
再写一个让LED3闪烁
让LED3闪烁的程序如下:
- .text
- _start:
-
- MAIN:
- BL LED_CONFIG
- LOOP:
- BL LED_ON
- BL DELAY
- BL LED_OFF
- BL DELAY
- B LOOP
-
- LED_CONFIG:
- LDR R2, =0x11000c20
- LDR R1, =0x00000001
- STR R1, [R2]
- MOV PC, LR
-
- LED_ON:
- LDR R2, =0x11000c24
- LDR R1, =0x00000001
- STR R1, [R2]
- MOV PC, LR
-
- LED_OFF:
- LDR R2, =0x11000c24
- LDR R1, =0x00000000
- STR R1, [R2]
- MOV PC, LR
- DELAY:
- LDR R1, =100000000
- L:
- SUB R1, R1, #1
- CMP R1, #0
- BNE L
- MOV PC, LR
-
- STOP:
- B STOP
- .end