1.GPIO Introduction
GPIO (General purpose I/O ports) means universal input/output port, which is popularly said to be some pins.
We can use them to output high or low levels or the state of the read-in PIN.
There are 130 I/O ports in the s3c2440, divided into 9 groups A~j, GPA, GPB 、..... GPJ
2.GPIO Registers
Since the gpio is to be manipulated, the corresponding registers must be operated, and the GPIO registers in 2440 are:
gpxcon--Select Pin function (input, output, retention, etc.)
gpxdat--used to read and write pins
gpcup--One is 1 o'clock, the corresponding pin has no internal pull-up resistor; for 0 o'clock, there is an internal pull-up resistor
3. Schematic diagram
Led:
Keys:
4. Experiment Code:
>> using assembly language to achieve illumination:
led_on. S
[CPP]View PlainCopyprint?
- . text
- . Global _start
- _start:
- LDR R0, =0x56000050 //gpfcon Register Address
- MOV R1, #0x00001500 //See technical Manual corresponding configuration, general 01 for the output pin
- STR R1, [R0] //set to output
- LDR R0, =0x56000054 //gpfdat Register
- MOV R1, #0x00000000
- STR R1, [R0] //gpfdat Register write value
- Main_loop:
- B main_loop //Cycle wait
Makefile:
[CPP]View PlainCopyprint?
- led_on.bin:led_on. S
- Arm-linux-gcc-g-C led_on. S-o LED_ON.O
- Arm-linux-ld-ttext 0x00000000-g led_on.o-o led_on_elf //-ttext to set the connection address
- Arm-linux-objcopy-o binary-s led_on_elf led_on.bin //convert elf files to. bin Files
- Clean
- RM-RF *.bin *.O *elf
>> Lighting with C language
Use C to write, need a boot file, can be used to close the door, set the stack and so on.
Crt0. S
[CPP]View PlainCopyprint?
- . text
- . Global _begin
- _begin:
- LDR R0, =0x53000000 //watchdog register address
- MOV R1, #0x00000000 //write 0 forbidden watchdog
- STR R1, [R0]
- LDR SP, =1024*4 //Set stack, note cannot be greater than 4 K, because now the available SRAM space is only 4 K
- BL main //Call the main function, and finally note that the assembly language case does not matter
- _loop:
- B _loop
Led_on_c.c
[CPP]View PlainCopyprint?
- #define GPFCON * (volatile unsigned long *) 0x56000050
- #define GPFDAT * (volatile unsigned long *) 0x56000054
- int main ()
- {
- gpfcon=0x00001500; //Simple configuration for Output
- gpfdat=0x00000000; ///Simple output 0, the above schematic shows that the corresponding LED will illuminate
- return 0;
- }
Makefile
[CPP]View PlainCopyprint?
- Led_on_c.bin:crt0. S LED_ON_C.C
- Arm-linux-gcc-g-c-o crt0.o crt0. S
- Arm-linux-gcc-g-c-o LED_ON_C.O LED_ON_C.C
- Arm-linux-ld-ttext 0x0000000-g crt0.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 //convert elf files to disassembly files
- Clean
- Rm-f Led_on_c.dis led_on_c.bin led_on_c_elf *.o
>> use key +c language for lighting
Look at the schematic diagram above, the principle is that the PIN PIN is configured as input pin, to read the status of the pin;
When the key is pressed, the pin reads low, and when the key is released, it is read to a high level;
Crt0. s ibid;
Key_led.c
[CPP]View PlainCopyprint?
- /*
- GPF4 GPF5 GPF6--led
- GPF0 GPF2 GPG3--key
- */
- #define GPFCON (* (volatile unsigned long *) 0x56000050)
- #define GPFDAT (* (volatile unsigned long *) 0x56000054)
- #define GPGCON (* (volatile unsigned long *) 0x56000060)
- #define GPGDAT (* (volatile unsigned long *) 0x56000064)
- #define Gpf4_out (1<< (4*2))
- #define Gpf5_out (1<< (5*2))
- #define Gpf6_out (1<< (6*2))
- #define GPF4_MSK (3<< (4*2))
- #define GPF5_MSK (3<< (5*2))
- #define GPF6_MSK (3<< (6*2))
- #define GPF0_IN (0<< (0*2))
- #define GPF2_IN (0<< (2*2))
- #define GPG3_IN (0<< (3*2))
- #define GPF0_MSK (3<< (0*2))
- #define GPF2_MSK (3<< (2*2))
- #define GPG3_MSK (3<< (3*2))
- int main ()
- {
- unsigned long dwdat;
- //1 Output Pin
- Gpfcon &= ~ (Gpf4_msk | Gpf5_msk | GPF6_MSK);
- Gpfcon |= (Gpf4_out | Gpf5_out | Gpf6_out);
- //input Pin
- Gpfcon &= ~ (Gpf0_msk | GPF2_MSK);
- Gpfcon |= (gpf0_in | GPF2_IN);
- Gpgcon &= ~gpg3_msk;
- Gpgcon |= gpg3_in;
- While (1)
- {
- Dwdat = Gpfdat;
- if (Dwdat & (1<<0))
- Gpfdat |= (1<<4);
- Else
- Gpfdat &= ~ (1<<4); //light
- if (Dwdat & (1<<2))
- Gpfdat |= (1<<5);
- Else
- Gpfdat &= ~ (1<<5);
- Dwdat = Gpgdat;
- if (Dwdat & (1<<3))
- Gpfdat |= (1<<6);
- Else
- Gpfdat &= ~ (1<<6);
- }
- return 0;
- }
Makefile the corresponding modification can be;
The above program compiles will get bin file, we burn it into NAND flash, can use tools, can also be cured in NOR flash uboot to burn, many methods, after burning, power on, 2440CPU will automatically put NAND Flash 4k content, copied to 2440 in 4k SRAM run, this memory commonly known as stepping stone area.
Note: Original article, reproduced please specify the source: http://blog.csdn.net/scottly1/article/details/38960309
"Embedded Linux+arm" Gpio operation