27. Light the LED operation
LEDs can be used as a tool for my debug program: In embedded system software, such as bootloader and kernel, in the early stages of development, because the serial port and other hardware has not been initialized, so debugging means is quite limited, this time can use led as a debugging means.
OK6410 schematic diagram of the LED:
From know, to let led light-emitting diode, is from right to left conduction, right is high level, so left to low level, diode will conduction, glow.
Once you know the principle, look at OK6410 's core board schematic to see which pins the nled1-4 should receive from the core board: the part of the LED:
We know from the above schematic that the led1-4 corresponds to the gpm0-3. Nled1-4.
2.GPIO
Gpio is general-purpose input/output Ports: Universal input/Output port. In embedded systems, the CPU often needs to control many simple external devices or circuits, these devices usually as long as two states, that is, switches, the control of these devices, the use of traditional serial port or USB port is complex, so in the embedded controller usually provides a "universal programmable i/ O Port ", which is gpio.
Here is the information for 6410GPIO: Gpmcon control Register, gpmdat data register.
Gpmdat Data Register:
Light LED Implementation ideas:
- Set GPIO control register, set PIN to output function
- set according to schematic diagram GPIO data registers, lit led .
Implemented code: lit. 3, 4 lights.
Compile to generate a. bin file. This is an executable file. When we write to the Development Board, we find that the development Board is not lit. This is because we did not initialize the hardware's peripheral interface in the previous operation.
In the 19. Bootloader frame settings, it is mentioned that when the Uboot is initialized, the 6,410:2,440 core is one more step is the peripheral base site initialization:
Here the light is not bright is the front of the uboot frame setting, this step is missing.
Open the ARM11 core manual and search for CP15:
Enter this chapter: Find C15 This register of peripheral Port Memory Remap This register, is the peripheral base address register. The front of the light is not lit, is less through the setting of this register, the peripheral is initialized.
Set parameters:
Click on the number of pages below to continue to view the setup information:
Above is the information of the Nuclear handbook:
The following is a chip manual information about the settings of the peripheral base register.
Set_peri_port:
Ldr R0, =0x70000000//ldr pseudo-directive, loads 0x70000000 to R0.
Orr R0, R0, #0x13//By the above know, 256 memory corresponding value: b10011=0x13
MCR p15,0,r0,c15,c2,4//corresponds to the above value set CP15.
mov pc, LR//return
One of the above Orr in the 0x13=0b10011, is corresponding to 256M memory.
The following is a set of values written to CP15:MCR p15,0,r0,c15,c2,4
Code:
. text
. Global _start
_start:
b Reset
Ldr pc, _undifined_instruction
Ldr pc, _software_interrupt
Ldr pc, _prefetch_abort
Ldr pc, _data_abort
Ldr pc, _not_used
Ldr pc, _IRQ
Ldr pc, _fiq
_undifined_instruction:. Word undifined_instruction
_software_interrupt:. Word software_interrupt
_prefetch_abort:. Word prefetch_abort
_data_abort:. Word data_abort
_not_used:. Word not_used
_IRQ:. Word IRQ
_fiq:. Word reset
Undifined_instruction:
Nop
Software_interrupt:
Nop
Prefetch_abort:
Nop
Data_abort:
Nop
Not_used:
Nop
Irq:
Nop
Fiq
Nop
@ What is the exception vector table
Reset
BL Set_svc
BL [email protected] initializing peripheral interface
BL Disable_watchdog
BL Disable_interrupt
BL Disable_mmu
BL light_led
SET_SVC:
Mrs R0,[email protected] read the value in CPSR to R0
BIC R0,r0,#[email protected] Clears r0, which is the latter five bits of CPSR 0
Orr R0,r0,#[email protected] Set the value of the r0 after five bits to 10011,svc
MSR Cpsr,[email Protected] Writes the value back to CPSR. SVC Mode Setup Complete
Set_peri_port:
Ldr R0, =0x70000000
Orr R0, R0, #0x13
MCR p15,0,r0,c15,c2,4
mov pc, LR
#define PWTCON 0x7e004000
Disable_watchdog:
LDR R0,[email protected] load this constant into the r0.
mov R1,#[email protected] Here cannot directly convert the value of Pwtcon directly into the register inside
The @mov object is the Universal register. This needs to be loaded using the str command.
Str r1,[r0]@ save R1 to 0x7e004000
Disable_interrupt:
MVN R1,#[email protected] Go to R1 write all 1
LDR r0,=0x71200014
STR R1,[R0]
LDR r0,=0x71300014
STR R1,[R0]
Disable_mmu:
MCR P15,0,r0,c7,c7,[email protected]
MRC p15,0,r0,c1,c0,0
Bic R0, R0, #[email protected] set three bits to 111, close Cachemmu, etc.
MCR p15,0,r0,c1,c0,0
mov pc, LR
#define LGPMCON 0x7f008820
#define LGPMDAT 0x7f008824
Light_led:
LDR R0,[email protected] internal registers cannot be accessed directly
LDR r1,=0x1111
STR r1,[r0]@ set the last four bits of the GPM as output pins
LDR R0,=lgpmdat
mov r1,#[email protected] to 3.4led output low, bright
STR R1,[R0]
MOV PC,LR
27. Light the LED operation