Assembly LED experiment

Assembly language light LED To get a new chip...
1, The next steps are inseparable from the chip Manual:
2, Cross compile on Linux virtual machine:
3, SD card download, development board running
The source code is as follows
Assembly language light LED

To get a new chip, the first thing to do is to drive its GPIO and control its GPIO output high and low levels.

GPIO port is one of the functions of IO port.

1, The next steps are inseparable from the chip Manual:

1. Enable all clocks and all clocks of GPIO

2.IO configuration, multiplexing GPIO

3. Set IO register

Configure the up-down and speed of IO.

4. Configure GPIO

Set input / output, default output high / low level, interrupt, etc.

2, Cross compile on Linux virtual machine:

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

Explain these four steps separately:

Step 1: compile the assembly file. s into an. o file

Step 2: connect the previously compiled led.o file to the address 0X87800000 to generate an. elf file

Step 3: like a format conversion tool, convert the led.elf file into led.bin file

If there is no OS system after power on:

If you burn files in ELF format, including some sections such as symbol table and character table of ELF files, the operation will fail. If you use objcopy to generate pure binary files, remove sections such as symbol table, and only keep the code segments and data segments, the program can run step by step.

elf file contains symbol table and so on. BIN file is a memory image made by extracting code segments, data segments and some custom segments from elf file.

Step 4: disassembly

Step 5: you can write a makefile

3, SD card download, development board running

There are two points to pay attention to in this link:

1. Understand the SD card burning process, that is, don't forget the imxdownload file.

2. It is important to find the right SD card device.

ls /dev/sd*

Pay attention when inserting SD card and observe the comparison before and after.

Then it's execution

./imxdownload led.bin /dev/sdd

Different SD card devices are different, and their own devices shall prevail. For example, my one is:

./imxdownload led.bin /dev/sdb

After this operation, a load.imx file will be generated. In fact, this file is in the SD card. The difference from bin is that some data headers are added in front of it.

The source code is as follows

1 2 .global _start /* Global label */ 3 4 /* 5 * Description:_ start function, from which the program starts to execute. This function completes the clock enabling 6 * GPIO Initialize and finally control the GPIO output low level to turn on the LED. 7 */ 8 _start: 9 /* Routine code */ 10 /* 1,Enable all clocks */ 11 ldr r0, =0X020C4068 /* Register CCGR0 */ 12 ldr r1, =0XFFFFFFFF 13 str r1, [r0] 14 15 ldr r0, =0X020C406C /* Register CCGR1 */ 16 str r1, [r0] 17 18 ldr r0, =0X020C4070 /* Register CCGR2 */ 19 str r1, [r0] 20 21 ldr r0, =0X020C4074 /* Register CCGR3 */ 22 str r1, [r0] 23 24 ldr r0, =0X020C4078 /* Register CCGR4 */ 25 str r1, [r0] 26 27 ldr r0, =0X020C407C /* Register CCGR5 */ 28 str r1, [r0] 29 30 ldr r0, =0X020C4080 /* Register CCGR6 */ 31 str r1, [r0] 32 33 34 /* 2,Set GPIO1_IO03 multiplexed to GPIO1_IO03 */ 35 ldr r0, =0X020E0068 /* Register SW_MUX_GPIO1_IO03_BASE loaded into r0 */ 36 ldr r1, =0X5 /* Set register SW_ MUX_ GPIO1_ IO03_ MUX of base_ Mode is 5 */ 37 str r1,[r0] 38 39 /* 3,Configure gpio1_ IO properties of io03 40 *bit 16:0 HYS close 41 *bit [15:14]: 00 Default drop-down 42 *bit [13]: 0 kepper function 43 *bit [12]: 1 pull/keeper Enable 44 *bit [11]: 0 Turn off the open circuit output 45 *bit [7:6]: 10 Speed 100Mhz 46 *bit [5:3]: 110 R0/6 Driving capability 47 *bit [0]: 0 Low conversion rate 48 */ 49 ldr r0, =0X020E02F4 /*Register SW_PAD_GPIO1_IO03_BASE */ 50 ldr r1, =0X10B0 51 str r1,[r0] 52 53 /* 4,Set GPIO1_IO03 is output */ 54 ldr r0, =0X0209C004 /*Register GPIO1_GDIR */ 55 ldr r1, =0X0000008 56 str r1,[r0] 57 58 /* 5,Open LED0 59 * Set GPIO1_IO03 output low level 60 */ 61 ldr r0, =0X0209C000 /*Register GPIO1_DR */ 62 ldr r1, =0 63 str r1,[r0] 64 65 /* 66 * Description: loop loop loop 67 */ 68 loop: 69 b loop

3 December 2021, 18:02 | Views: 8475

Add new comment

For adding a comment, please log in
or create account

0 comments