Zookeeper
Lab Purpose: Use the C language to implement the flow lamp on jz2440
Tutorial principle:
Here, an nLED_1, nLED_2, and nLED_4 is illuminated. The pins used for this pair are GPF5, GPF6, and GPF7. In GPIO, each pin has configuration registers and data registers, in this example, the configuration register is GPFCON: 0x56000050, and the data register GPFDATA: 0x56000054, [] = 01) is the output pin, and according to the circuit schematic, it can be seen that LED1 can be lit only when it is set to a low level. Therefore, [0x56000050] = 0x00000100 ). [0x56000054] = 0x00000000, [9, 8] = 01 for the output) is the output pin, and according to the circuit schematic, we can see that it is set to a low level, so [0x56000050] = 0x00000400 ). [0x56000054] = 0x00000000, [] = 01 for the output) is the output pin, and according to the circuit schematic, we can see that is set to low level, so [0x56000050] = 0x00001000 ). [ 0x56000054] = 0x00000000, which lights them up in turn.
Tutorial steps:
Edit the source program in linux. The source program includes the Startup File: complete the initialization of closing dog and initialization stack, and then use your own Makefile to compile and link the source program to generate a binfile, finally, the file is transmitted to the window and written to nandflash using the u-boot in nor flash in the board. Download the dnw in the window to the board. Restart the board, set the board as nand flash, run the program, and observe the effect.
Lab tool: Remote Login Development Board jz2440 tool: SecureCRT 5.2, implement linux and window File sharing tool SSH Secure File Trsanfer Client
Compilation tool: Cross-compilation chain in linux (that is, compile a makefile file to compile and connect the file)
Note: Stack Initialization is required. During disassembly, we can see that some register values should be saved to the stack when Initialization is complete, and the Register values should be restored when the main function returns. Because the program is very short and less than 4 K is used, the front part of SRAM (commonly known as stepping stone, which stores nandflash's first 4 K in hardware) is used to store the bare board program, the rest is free. Here we direct the stack pointer to the end of 1024*4, that is, 4 K, to store the register value.
Experiment code: Start the code crt. S and the experiment code len_on_c.c
Start the purchase proxy crt. S:
.text.global _start_start:ldrR0, =0x53000000movR1,#0x0strR1,[R0]ldrsp, =1024*4blmainhalt_loop: bhalt_loop
Flow light led_on_c.c:
# Define GPFCON (* (volatile unsigned long *) 0x56000050) # define GPFDAT (* (volatile unsigned long x) 0x56000054) void delay (int n) {int I, j; for (I = 0; I
MAKefile file:
led_on_c.bin: crt.S led_on_c.c arm-linux-gcc -g -c -o led_on_c.o led_on_c.c arm-linux-gcc -g -c -o crt.o crt.S arm-linux-ld -Ttext 0x00000000 -g crt.o led_on_c.o -o led_on_c_elf arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin arm-linux-objdump -D -m arm led_on_c_elf > led_on_c.dis.PHONY:cleanclean: rm -f *.bin *.o led_on_c_elf led_on_c.dis
Note: Let's take a look at the decompiled led_on_c.dis file to see the purpose of stack initialization.
00000000 <_start>: 0:e3a00453 movr0, #1392508928; 0x53000000 4:e3a01000 movr1, #0; 0x0 8:e5801000 strr1, [r0] c:e3a0da01 movsp, #4096; 0x1000 10:eb00001a bl80
70:baffffef blt34
74:e28bd000 addsp, fp, #0; 0x0 78:e8bd0800 pop{fp} 7c:e12fff1e bxlr
00000018
: 18:e52db004 push{fp}; (str fp, [sp, #-4]!) 1c:e28db000 addfp, sp, #0; 0x0 20:e24dd014 subsp, sp, #20; 0x14
28:6965772f stmdbvsr5!, {r0, r1, r2, r3, r5, r8, r9, sl, ip, sp, lr}^
44:490b3b0b stmdbmifp, {r0, r1, r3, r8, r9, fp, ip, sp}