JZ2440 bare board development Exercise # 1 - LED lighting

Platform: JZ2440 development board --CPU: S3C2440 (ARM920)


S3C2440 as a SOC, is generally used to run the system (such as linux, etc.) mostly down here to the bare metal level in the most familiar way to lower hardware-related software development. Experiments first programming language is printed in black or other output window in the "hello world", and the bare metal "helloworld" compared to light a LED lamp.

There STC89C51 or STM32 microcontroller development experience and so all know, the bare board control CPU is actually doing the reading and writing registers , increase our business logic on this basis, we can make the board in accordance with what we want to run, S3C2440 is no exception .

analysis

Want to control the LED lamp on or off, can be known from the first circuit knowledge, LED as a light emitting diode, a unidirectional conductive, need only apply a potential difference at both ends thereof in the direction (depending on the LED set, typically to 3.3V) to which can be illuminated. Thus a need to look at the diagram of the lower board, as follows:

Seen from the schematic, the LED board has a high potential connected to 3.3V, so we only need to control nLED_x (FIG principle, n is generally represents active low) pin output connected to a low level.

Can also be found GPF4 / 5/6 is connected to the three LED lamps to be controlled from the original title FIG. Next need to find the appropriate manual S3C2440 chip register information. See know chip manual control necessary to control the LED to light GPIOF following registers

Wherein GPFCON the IO alternate function is selected, set here as long as output to an output pin, according to the manual to clear the corresponding bit set to 01.

GPFDATA data register, when we set to output, data can be written to the corresponding bit to make a high or low output.

GPFUP is a pull control register, the corresponding bit is set to 0 even if the pin can be pulled up, the pull-up setting, when no setting GPFDAT, the pin will be pulled as a high state, while the register is initialized to all reset 0, all of the pins default to open the pull-board LED is off by default, just to meet the demand, so you can not set it.

Part of the program

1. Compilation

Because of S3C2440 ARM architecture, using the ARM assembler instruction set, here simply write register is provided so that the next three LED lights, the value of the direct write mode to cover very rough, the subsequent write register in a more secure manner common and .

.text
.global _start

_start:
	/* 将GPF4,5,6设置为输出引脚 */
	LDR R0,=0x56000050
	LDR R1,=0x1500
	STR R1,[R0]
	
	/* 设置GPF4,5,6输出低电平 */
	LDR R0,=0x56000054
	LDR R1,=0x8f
	STR R1,[R0]
halt:
    b halt

2.C language

Unified entrance for the main C language function, but bare boards, you need a program to call our main written, this program is called start the program. Since C language function calls pass parameters and automatic variables need to use the stack memory, so the program is also responsible for starting the stack is set up, so that the C language program to work correctly.

Start.S
--------------------------------------------------
.text
.global _start

_start:
	MOV R0,#0
	LDR R1,[R0]  //保存0地址值	
	
	STR R0,[R0]	 //将0值写入,测试是否为NOR_Flash启动
	LDR R2,[R0]
	
	CMP R2,R0
	LDR SP,=0x40000000+4096
	MOVEQ SP,#4096
	STREQ R1,[R0]
	
	bl main
halt:
    b halt
led.c
---------------------------------------------------------------------------
int main()
{
	volatile unsigned int* pGPFCON = (unsigned int*)0x56000050;
	volatile unsigned int* pGPFDAT = (unsigned int*)0x56000054;
	
	//能不影响其他位的寄存器写方式
	*pGPFCON &= ~((3<<8) | (3<<10) | (3<<12));  //寄存器对应的控制位清0
	*pGPFCON |= ((1<<8) | (1<<10) | (1<<12));  //置位对应的控制位
	
	*pGPFDAT &=~((1<<4) | (1<<5) | (1<<6));
	return 0;
}

Boot file, needs to be determined or nandflash norflash startup mode, startup mode due to the presence norflash start mode and nandflash S3C2440 development board. Check the manual S3C2440 chip memory mapping table can be seen below,

When norflash start mode, the default norflash 0 to 0 address as a memory address, the chip built-in SRAM (Boot internal SRAM), compared with the address 0x40000000 + 4096.

When nandflash start mode, the chip will copy nandflash front 4k to the internal data SRAM (Boot internal SRAM), and thus the address operation is 0, the default memory available control blocks 0-4096.

If you need to use a different memory address the need for appropriate initialization, which is behind the content aside. norflash read-only boot file use this trial writing addresses 0 to a value of 0, compared with 0 and reads. Norflash If the write fails, the data should not be read as a 0, so the stack address is set to 0x40000000 + 4096. nandflash readable and writable, and therefore 0 is written after reading data is also 0, so the stack is set to 4096.

Thus, in assembly language and C, respectively, to complete the lighting operation, very rough and very simple but can realize the function, the effect of three led lights are on board. Compile the program using the cross compilers, and compiler used to simplify operation makefile, avoid entering, for a rough Makefile C language as follows:

all:
    arm-linux-gcc -o Start.o -c Start.S
    arm-linux-gcc -o led.o -c led.c
    arm-linux-ld -o led.elf Start.o led.o
    arm-linux-objcopy -O binary -S led.elf led.bin
    arm-linux-objdump -D led.elf > led.dis

clean:
    rm *.bin *.elf *.dis *.o

Dis program which is disassembled file, follow-up would be disassembled file for analysis, for the time being first on here.

 
Published 19 original articles · won praise 7 · views 6929

Guess you like

Origin blog.csdn.net/G_METHOD/article/details/104146636