Raspberry PI Series--bare metal illuminated LED lights
Background
Recently just bought Raspberry PI B +, configured to run the official Raspbian system, tossing a week Linux system, feel no meaning, so try to understand the bottom of the start process, through a few days of research, It is found that the boot of the lowest part is performed by the official Bootcore.bin and start.elf files (which should be the initialization of hardware devices, such as MMU), followed by the _start of the next part kernel.img. In order to really verify this process, so want to use Gpio control LED lights, after several tossing and finally successfully lit led, is now recorded here.
Peripheral address Encoding
To control the Gpio pins you must know the address of the Gpio pin, in the ARM architecture, foreign IO is generally unified encoding, BCM2835 the peripheral address 0x7e00000 mapping to ram 0x20000000, such as 0x7e200000 is 0x20200000, Here is the bus address, physical address, virtual address diagram:
Gpio Expansion Port
This time we have to use the Gpio pins on the board to control the LED lights, it is necessary to understand the meaning of these pins, B + version of the Gpio extension to 40 feet, is the difference between the second and the Gpio pin:
Gpio Registers
In BCM2835, there are 54 gpio pins, where gpio registers are Gpfseln, GPSETN, GPCLRN, and so on, and the functions of these registers are described below:
· Register GPFSEL0 ~ GPFSEL5---- function Register, specify PIN for input, output, etc. , every 3 Bits determine a PIN:
o $ = GPIO Pin 9 is aninput
o 001 = GPIO Pin 9 is anoutput
o + = GPIO Pin 9 takesalternate function 0
o 101 = GPIO Pin 9 takesalternate function 1
o = GPIO Pin 9 takesalternate function 2
o 111 = GPIO Pin 9 takesalternate function 3
o 011 = GPIO Pin 9 takesalternate function 4
o 010 = GPIO Pin 9 takesalternate function 5
which :( Register Device --- Address --- Description )
* GPFSEL0---0x7e200000--- decision gpio0-gpio9 the function of the pin
* GPFSEL1---0x7e200004--- decision gpio10-gpio19 the function of the pin
* GPFSEL2---0x7e200008--- decision gpio20-gpio29 the function of the pin
* GPFSEL3---0x7e20000c--- decision gpio30-gpio39 the function of the pin
* GPFSEL4---0x7e200010--- decision gpio40-gpio49 the function of the pin
* GPFSEL5---0x7e200014--- decision gpio50-gpio53 the function of the pin
· Register gpset0-cpset1---- set to 1, each of which decides on a pin
o 0 = No effect
o 1 = Set GPIO pin n
which :( Register Device --- Address --- Description )
* GPSET0---0x7e20001c--- decision gpio0-gpio31 Pin
* GPSET1---0x7e200020--- decision gpio32-gpio53 Pin
· Register GPCLR0-GPCLR1---- set to 0, each of which decides on a pin
o 0 = No effect
o 1 = Clear GPIO pin n
which :( Register Device --- Address --- Description )
* GPSET0---0x7e200028--- decision gpio0-gpio31 Pin
* GPSET1---0x7e20002c--- decision gpio32-gpio53 Pin
Example---setting GPIO16 to low level
Not much to say, the introduction, the previous has been introduced, directly on the code:
. section. Init
. globl _start
_start:
LDR r0,=0x20200000
/* Set GPIO16 to Output mode (001) */
mov r1, #1
LSL R1, #18
str r1,[r0, #4]/* GPFSEL1 ( decision gpoi10-gpio19) * /
/* Clear GPIO16 */
mov r1, #1
LSL R1, #16
str r1,[r0, #40]/* GPCLR0 ( decision gpoi0-gpio31) * /
/*
* Loop over this forevermore
*/
loop$:
b loop$
Results:
Summarize
After many attempts finally lit LED lights, although now think, may be very simple, when this is a zero breakthrough, in this small step, mastered a lot of knowledge, such as bus address, physical address of the relationship, how to see the Gpio register, ARM assembly instructions, etc. With the success of this step, I can do more complicated experiments.
Raspberry PI Series--bare metal illuminated LED lights