目标:熟悉imx6ull的GPIO的基本使用,包括clock使能、gpio复用、电气属性和输入输出设置及输出高低电平等操作;熟悉ARM的内部常见寄存器及汇编的常用指令,为后面u-boot和kernel移植打好基础;
1)汇编
arm-linux-gnueabihf-gcc -g -c led.s -o led.o
-g 产生gdb调试信息
-c 编译源文件
-o 产生汇编文件
2)链接
arm-linux-gnueabihf-ld -Ttext 0x87800000 led.o -o led.elf
地址:外部DDR中,0x87800000
Ttext 代码段
3)格式转换
arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin
-O 表示格式转换的目标格式
4)反汇编
arm-linux-gnueabihf-objdump -D led.elf > led.dis
========================================================================
代码烧写
Disk /dev/sdb: 14.4 GiB, 15502147584 bytes, 30277632 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdb1 8192 30277631 30269440 14.4G c W95 FAT32 (LBA)
chmod +x ./imxdownload
./imxdownload led.bin /dev/sdb
=========================================================================
拨码开关网上拨动是1,往下拨是0
SD卡启动:裸机和u-boot启动;
10000010
EMMC启动:程序固化后,固化在EMMC内部;
10100110
代码源文件如下:
/*
* gpio control led using asm:LED1_3--->low--->on;high--->off
* version:1.0
* Date:20211016
* 1) enable gpio module[enable clock]
* 2) mul gpio
* 3) set electrical properties
* 4) set direction and data
* 5) loop
*/
.global _start
_start:
/*enable gpio clock*/
ldr r0, =0x020c4068 /*CCM_CCGR0 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c406C /*CCM_CCGR1 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c4070 /*CCM_CCGR2 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c4074 /*CCM_CCGR3 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c4078 /*CCM_CCGR4 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c407C /*CCM_CCGR5 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
ldr r0, =0x020c4080 /*CCM_CCGR6 */
ldr r1, =0xFFFFFFFF
str r1, [r0]
//io mul ---> gpio
ldr r0, =0x020e0068 /*IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03 */
ldr r1, = 0x05
str r1, [r0]
//set electrical properties
ldr r0, =0x020e02F4
ldr r1, =0x10b0
str r1, [r0]
//set direction and data
ldr r0, =0x0209c004
ldr r1, =0x00000008
str r1, [r0]
ldr r0, =0x0209c000
ldr r1, =0x0
str r1, [r0]
loop:
b loop
Makefile 如下:
led.bin:led.s
arm-linux-gnueabihf-gcc -g -c led.s -o led.o
arm-linux-gnueabihf-ld -Ttext 0x87800000 led.o -o led.elf
arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin
arm-linux-gnueabihf-objdump -D led.elf > led.dis
clean:
rm -rf *.o led.bin led.elf led.dis