"Embedded Linux+arm" Gpio operation

Source: Internet
Author: User

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?
  1. . text
  2. . Global _start
  3. _start:
  4. LDR R0, =0x56000050 //gpfcon Register Address
  5. MOV R1, #0x00001500 //See technical Manual corresponding configuration, general 01 for the output pin
  6. STR R1, [R0] //set to output
  7. LDR R0, =0x56000054 //gpfdat Register
  8. MOV R1, #0x00000000
  9. STR R1, [R0] //gpfdat Register write value
  10. Main_loop:
  11. B main_loop //Cycle wait

Makefile:

[CPP]View PlainCopyprint?
    1. led_on.bin:led_on. S
    2. Arm-linux-gcc-g-C led_on. S-o LED_ON.O
    3. Arm-linux-ld-ttext 0x00000000-g led_on.o-o led_on_elf //-ttext to set the connection address
    4. Arm-linux-objcopy-o binary-s led_on_elf led_on.bin //convert elf files to. bin Files
    5. Clean
    6. 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?
  1. . text
  2. . Global _begin
  3. _begin:
  4. LDR R0, =0x53000000 //watchdog register address
  5. MOV R1, #0x00000000 //write 0 forbidden watchdog
  6. STR R1, [R0]
  7. LDR SP, =1024*4 //Set stack, note cannot be greater than 4 K, because now the available SRAM space is only 4 K
  8. BL main //Call the main function, and finally note that the assembly language case does not matter
  9. _loop:
  10. B _loop

Led_on_c.c

[CPP]View PlainCopyprint?
    1. #define GPFCON * (volatile unsigned long *) 0x56000050
    2. #define GPFDAT * (volatile unsigned long *) 0x56000054
    3. int main ()
    4. {
    5. gpfcon=0x00001500; //Simple configuration for Output
    6. gpfdat=0x00000000; ///Simple output 0, the above schematic shows that the corresponding LED will illuminate
    7. return 0;
    8. }

Makefile

[CPP]View PlainCopyprint?
  1. Led_on_c.bin:crt0. S LED_ON_C.C
  2. Arm-linux-gcc-g-c-o crt0.o crt0. S
  3. Arm-linux-gcc-g-c-o LED_ON_C.O LED_ON_C.C
  4. Arm-linux-ld-ttext 0x0000000-g crt0.o Led_on_c.o-o led_on_c_elf
  5. Arm-linux-objcopy-o binary-s led_on_c_elf Led_on_c.bin
  6. arm-linux-objdump-d-M arm led_on_c_elf > Led_on_c.dis //convert elf files to disassembly files
  7. Clean
  8. 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?
  1. /*
  2. GPF4 GPF5 GPF6--led
  3. GPF0 GPF2 GPG3--key
  4. */
  5. #define GPFCON (* (volatile unsigned long *) 0x56000050)
  6. #define GPFDAT (* (volatile unsigned long *) 0x56000054)
  7. #define GPGCON (* (volatile unsigned long *) 0x56000060)
  8. #define GPGDAT (* (volatile unsigned long *) 0x56000064)
  9. #define Gpf4_out (1<< (4*2))
  10. #define Gpf5_out (1<< (5*2))
  11. #define Gpf6_out (1<< (6*2))
  12. #define GPF4_MSK (3<< (4*2))
  13. #define GPF5_MSK (3<< (5*2))
  14. #define GPF6_MSK (3<< (6*2))
  15. #define GPF0_IN (0<< (0*2))
  16. #define GPF2_IN (0<< (2*2))
  17. #define GPG3_IN (0<< (3*2))
  18. #define GPF0_MSK (3<< (0*2))
  19. #define GPF2_MSK (3<< (2*2))
  20. #define GPG3_MSK (3<< (3*2))
  21. int main ()
  22. {
  23. unsigned long dwdat;
  24. //1 Output Pin
  25. Gpfcon &= ~ (Gpf4_msk | Gpf5_msk | GPF6_MSK);
  26. Gpfcon |= (Gpf4_out | Gpf5_out | Gpf6_out);
  27. //input Pin
  28. Gpfcon &= ~ (Gpf0_msk | GPF2_MSK);
  29. Gpfcon |= (gpf0_in | GPF2_IN);
  30. Gpgcon &= ~gpg3_msk;
  31. Gpgcon |= gpg3_in;
  32. While (1)
  33. {
  34. Dwdat = Gpfdat;
  35. if (Dwdat & (1<<0))
  36. Gpfdat |= (1<<4);
  37. Else
  38. Gpfdat &= ~ (1<<4); //light
  39. if (Dwdat & (1<<2))
  40. Gpfdat |= (1<<5);
  41. Else
  42. Gpfdat &= ~ (1<<5);
  43. Dwdat = Gpgdat;
  44. if (Dwdat & (1<<3))
  45. Gpfdat |= (1<<6);
  46. Else
  47. Gpfdat &= ~ (1<<6);
  48. }
  49. return 0;
  50. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.