Tiny4412 uses assembly to light up LEDs to achieve the effect of running water

This article is reproduced from: http://www.techbulo.com/1313.html

From today, I have officially entered the development and learning of tiny4412. Today, I mainly looked at the startup process and memory mapping of Tiny4412 and the Exynos4412 databook, and wrote a marquee program in assembly (there will be a C language version in the future), Let's talk about my development environment first:

  • Development board: Tiny4412 enhanced version (the base plate is Tiny4412ADK 1312)
  • Development tool: UltraEdit
  • Host: VmWare Ubuntu12.04 (64bit)
  • Compilation tool: arm-linux-gcc4.5.1

1. Description of the control principle

tiny4412 core board

Let's take a look at the schematic first:

tiny4412-led schematic

tiny4412-led schematic

As can be seen from the above figure, Tiny4412 has 4 user LED lights, and the four pins to control them are GPM4_0~GPM4_3. According to the principle, when the IO pin is high, the LED light is off, and when the IO pin is low, the LED light is off. Bright. The work we have to do is to set GPM4_0~ GPM4_3 as the output function, and control and the output level can be high or low.

2. Program description

1. led.S

It can be seen from the schematic diagram that the program only performs two steps;

Step 1: Set the control register GPM4CON corresponding to GPM4_0~GPM4_3, so that the four pins of GPM4_0~GPM4_3 are output functions.

Step 2: Set the 4 bits corresponding to the corresponding data register GPM4DAT to 0, make GPM4_0~ GPM4_3 low level, all 4 LED lights are on, wait for a period of time to set the 0th bit to 0, and set the rest of the bits Set to 1, so that only the first light is on; wait for a period of time to set the first bit to 0, and the remaining bits to 1, so that only the second light is on; wait for a period of time to set the second bit to 0, and the remaining bits to 1 , so that only the third light is on; wait for a period of time to set the third bit to 0, and the other bits to 1, so that only the fourth light is on; wait for a period of time to make GPM4_0~GPM4_3 all high level, all 4 LED lights extinguish. This achieves the marquee effect.

In the program code, there are also related explanations, which will not be explained too much here.

.text
.globl _start
_start:

	/* Setup GPM4_0、GPM4_1、GPM4_2、GPM4_3为输出 */
	ldr r0, =0x110002E0		// GPM4CON的地址是0x110002E0
	ldr r1, [r0]			// 先读出原值
	bic r1, r1, #0xff00		// 清除bit[15:8]
	bic r1, r1, #0xff		// 清除bit[7:0]
	orr r1, r1, #0x1100		// 设置bit[15:8]为0b00010001
	orr r1, r1, #0x11		// 设置bit[7:0]为0b00010001
	str r1, [r0]			// 写入GPM4CON

	/*
	 * set GPM4DAT as Low For leds
	*/
	ldr r0, =0x110002E4		// GPM4DAT的地址是0x110002E0
	ldr r1, [r0]			// 读出原值

led_loop:
	bic r1, r1, #0xf		// 清除bit[0-3]为0 全亮
	str r1, [r0]			// 写入GPM4DAT
	ldr r2, =0xffffff
	bl led_delay

	orr r1, r1, #0xe		/* GM4_0 亮 */
	str r1, [r0]
	ldr r2, =0xffffff
	bl led_delay
	
	bic r1, r1, #0x2		/* GM4_1 亮 */
	orr r1, r1, #0x1
	str r1, [r0]
	ldr r2, =0xffffff
	bl led_delay
	
	bic r1, r1, #0x4		/* GM4_2 亮 */
	orr r1, r1, #0x2
	str r1, [r0]
	ldr r2, =0xffffff
	bl led_delay
	
	bic r1, r1, #0x8		/* GM4_3 亮 */
	orr r1, r1, #0x4
	str r1, [r0]
	ldr r2, =0xffffff
	bl led_delay
	
	bl led_loop
	
led_delay:				/* 循环 */
	sub r2, r2, #0x1	//sub 减法
	cmp r2, #0x0		//将r0 与0比较
	bne led_delay		//b是跳ne是不相等,不相等就跳到led_delay
	mov pc, lr			//lr里存的是调用函数时的下一条指令地址,将lr的值赋给pc程序计数器就可以完成返回

2. MakeFile Instructions

led.bin : led.S
   arm-linux-gcc -c -o led.o led.S
   arm-linux-ld -Tled.lds -N led.o -o led.elf
   arm-linux-objcopy -O binary -S led.elf led.bin
   arm-linux-objdump -D -m arm led.elf > led.dis
clean:
   rm -f *.dis *.bin *.elf *.o

When we execute the make command in the directory where the Makefile is located, the system will perform the following operations:

The first step is to execute the arm-linux-gcc -c -o led.o led.S command to compile the assembly file led.S existing in the current directory into the led.o file;

The second step is to execute arm-linux-ld -Tled.lds -N led.o -o led.elf to link the .o file into an elf file, -Tled.lds where the led.lds bit link script tells the linker how to interpret the program Make links, and link addresses, etc. (explained below);

The third step is to execute arm-linux-objcopy -O binary -S led.elf led.bin to extract the elf file into a bin file that can be run on the development board;

The fourth step is to execute arm-linux-objdump -D -m arm led.elf > led.dis to disassemble the elf file, which is convenient for us to analyze the program, find errors, etc.;

3. Link script led.lds description

SECTIONS {
  . = 0x02023400;
  .text : { *(.text) }
  .rodata ALIGN(4) : {*(.rodata*)}
  .data ALIGN(4) : { *(.data*) }
  .bss ALIGN(4) : { *(.bss) *(COMMON) }
}

This article does not introduce the specific syntax of the link script, readers can google it by themselves

Line 2 indicates that the connection address of the program starts at 0x02023400, which means that our program should be located at the memory address 0x02023400 bytes before running,

BL1 will copy BL2 to address 0x02023400 and start it again.

Lines 3 to 6 indicate that starting from 0x02023400, the code segment, read-only data segment, data segment, and BSS segment of the program are sequentially discharged.

3. Program compilation and programming

1. Compile

  • Upload the three files led.s, Makefile, led.lds to the server through FTP or other tools, and enter the make command to compile, and the led.bin file will be obtained.

2. Program

  • Insert the SD card into the computer and let Ubuntu in VmWare recognize it, then execute the following command:
  • ./sd_fusing.sh /dev/sdb ../../hardware_code/led/led.bin

As shown in the picture, the SD card is successfully burned, insert the SD card into the Tiny4412 development board, and set it to start the SD card, then you will see the LED light flashing.

Description: sd_fusing.sh is a shell script, this script file, one-click programming program to SD card. We will analyze this script in the next section.

4. Power-on experiment

As shown in the figure below, you can see that 4 LEDs are turned on and off in turn

tiny4412 running water light effect

Five, link script analysis

Take led.lds in the led directory as an example, its content is as follows:

SECTIONS {
	. = 0x02023400;
	.text : { *(.text) }
	.rodata ALIGN(4) : {*(.rodata*)}
	.data ALIGN(4) : { *(.data*) }
	.bss ALIGN(4) : { *(.bss) *(COMMON) }
}

Line 2 indicates that the connection address of the program starts at 0x02023400, which means that before our program runs, it should be located at the memory address
0x02023400 bytes. BL1 will copy BL2 to address 0x02023400 and start it again.
Lines 3 to 6 indicate that starting from 0x02023400, the code segment, read-only data segment, data segment, and BSS segment of the program are sequentially discharged.
We have no concept of these "segments", which will be introduced in subsequent chapters.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325076334&siteId=291194637