S3C2440③ | GPIO Experiment

Publisher:superstar10Latest update time:2024-07-15 Source: elecfansKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Experiment 1 - Lighting up an LED

1. Look at the schematic to determine how the hardware is connected

The schematic diagram shows the hardware circuit of the chip controlling the LED and how the chip pins are connected to the LED.

2. Check the main chip manual to determine how to control the pins

Specific: How to make GPF4 output high and low levels?

2.1. Configure GPF4 to output mode (GPFCON)

Set bits [9:8] of the GPFCON register = 0b01.

2.2.Configure GPF4 output high/low level (GPFDAT)

The 4th bit of GPFDAT is 0-low level, 1-high level. (Note: corresponding)

3. Assembler program accesses registers to control LED

3.1. Editing Program


Code language: javascript


@ brief: Light up the LED connected to GPF4

@ author: mculover666

@ date: 2019/3/1


.text

.global _start


_start:

@ Set GPFCON register, GPF4 is output mode

LDR R0,=0x56000050

LDR R1,=0x0100

STR R1,[R0]


@ Set the GPF DAT register, GPF4 outputs low level

LDR R0,=0X56000054

LDR R1,=0

STR R1,[R0]


@Program Pause

halt:

B halt

3.2. Compiling the Program

Assemble to binary object file

Code language: javascript


arm-linux-gcc -c led_on.s -Wall -o led_on.o

Link to executable file elf

Code language: javascript


arm-linux-ld -Ttext 0 led_on.o -o led_on.elf

Convert to bin file

Code language: javascript


arm-linux-objcopy -O binary -S led_on.elf led_on.bin

The entire compilation step can be written as a makefile:


Code language: javascript


TARGET = led_on


# Output all warnings

CFLAGS = -Wall


$(TARGET).bin:$(TARGET).elf

arm-linux-objcopy -O binary -S $(TARGET).elf $(TARGET).bin

$(TARGET).elf:$(TARGET).o

arm-linux-ld -Ttext 0 $(TARGET).o -o $(TARGET).elf

$(TARGET).o:$(TARGET).s

arm-linux-gcc -c $(TARGET).s $(CFLAGS) -o $(TARGET).o


clean:

rm -rf *.o *.elf *.bin


download_to_nand:

#Download to nand flash

oflash 0 1 0 0 0 $(TARGET).bin

3.3. Burning Program

Use oflash to burn the bin file to address 0 of Nand Flash:


Code language: javascript


oflash 0 1 0 0 0 .led_on.bin


3.4. Run the program

  1. Set the boot switch to Nand boot;

  2. Re-power on;

  3. Experimental Results

4.C program accesses registers to control LED

4.1. Prerequisites for running C programs - startup files

  • The C language entry function is the main() function, which is called by the startup file (the assembler program executed when power is just turned on);

  • The stack will be pushed when calling, and the stack will be popped after the call is completed, so the stack top pointer SP needs to be set;

  • After the main function is called, it returns to the startup file calling point.


Code language: javascript


Startup file start.s: Initialize the C language operating environment and introduce C programs


@ brief: S3C2440 startup file

@ author: mculover666


.text

.global _start


_start:

@ Disable watchdog

LDR R0,=0x53000000

MOV R1,#0

STR R1,[R0]


@ Set the stack top pointer SP (start from Nand)

LDR SP,=4096


@ Call the main function, save the return address, and transfer to the C program

BL main


@ The main function returns and the program pauses

halt:

B halt

4.2. Writing C Programs - Pointers + Bit Operations

Code language: javascript


int main(void)

{


/* Set the GPFCON register to configure the GPF4 pin as output mode*/

*(unsigned int *)0x56000050 &= ~(3<<(2*4));

*(unsigned int *)0x56000050 |= 1<<(2*4);


/* Set the GPF DAT register, GPF4 outputs low level, and lights up the LED */

*(unsigned int *)0x56000054 &= ~(1<<4);


/* Program pause */

while(1);


}

4.3. Compilation

Code language: javascript


TARGET = led_on


CFLAGS = -Wall # Output all warnings


$(TARGET).bin:$(TARGET).elf

arm-linux-objcopy -O binary -S $(TARGET).elf $(TARGET).bin


#Note: The startup file must be linked first

$(TARGET).elf:start.o $(TARGET).o

arm-linux-ld -Ttext 0 start.o $(TARGET).o -o $(TARGET).elf


$(TARGET).o:$(TARGET).c

arm-linux-gcc -c $(TARGET).c $(CFLAGS) -o $(TARGET).o

start.o:start.s

arm-linux-gcc -c start.s $(CFLAGS) -o start.o


clean:

rm -rf *.o *.elf *.bin


download_to_nand:

#Download to nand flash

oflash 0 1 0 0 0 $(TARGET).bin


4.4. Burn and run

Code language: javascript

copy

oflash 0 1 0 0 0 .led_on.bin

Experiment 2 - Key Detection

1. Look at the schematic to determine how the hardware is connected

2. Check the main chip manual to determine how to control the pins

2.1. Configure GPF0 to input mode (GPFCON)

2.2. Read the status of GPF0 (high/low level) (GPFDAT)


3.C program accesses register detection button

3.1. Programming

Code language: javascript


int main(void)

{

volatile int GPF0_state;


/* Set GPFCON register */

//Set GPF4 to output

*(unsigned int *)0x56000050 &= ~(3<<(2*4));

*(unsigned int *)0x56000050 |= (1<<(2*4));

//Set GPF0 as input

*(unsigned int *)0x56000050 &= ~(3<<(2*0));


/* Program infinite loop detection key */

while(1)

{

/* Read GPF DAT register */

GPF0_state = *(unsigned int *)0x56000054;


/* Check the status of GPF4 pin */

if(GPF0_state & 0x01)

{

//The button is not pressed, the pull-up resistor is pulled high, and the LED is turned off

*(unsigned int *)0x56000054 |= (1<<4);

}

else

{

//Button pressed, low level, light up the LED

*(unsigned int *)0x56000054 &= ~(1<<4);

}

}

}

3.2. Compiling the Program

Code language: javascript


TARGET = key_scan


CFLAGS = -Wall # Output all warnings


$(TARGET).bin:$(TARGET).elf

arm-linux-objcopy -O binary -S $(TARGET).elf $(TARGET).bin


#Note: The startup file must be linked first

$(TARGET).elf:start.o $(TARGET).o

arm-linux-ld -Ttext 0 start.o $(TARGET).o -o $(TARGET).elf


$(TARGET).o:$(TARGET).c

arm-linux-gcc -c $(TARGET).c $(CFLAGS) -o $(TARGET).o

start.o:start.s

arm-linux-gcc -c start.s $(CFLAGS) -o start.o


clean:

rm -rf *.o *.elf *.bin


download_to_nand:

#Download to nand flash

oflash 0 1 0 0 0 $(TARGET).bin

3.3. Burn the program and run it

Code language: javascript


oflash 0 1 0 0 0 .led_on.bin


Summary of Experiments 1 and 2

Through these two experiments:

  1. 1. In terms of the S3C2440 processor, we have mastered:

  • How to control the GPIO pins of S3C2440: output high and low levels and detect external input levels (GPFCON register and GPFDAT register)

  • 5 commonly used ARM assembly instructions: MOV, LDR, STR, BL, B;

  • The basic format for writing assembler programs;

  1. 2. In terms of C language, I have mastered:

  • How is assembly converted to C language in the startup file: BL calls the main function;

  • Calling functions requires a lot of stack usage, which shows the importance of setting the stack pointer SP at startup;

  • Use C language pointers to access registers and use C language bit operation syntax to change register data;

  1. 3. In terms of development tools, we have mastered:

  • Use of arm-linux-gcc series tools and makefile;


Keywords:S3C2440 Reference address:S3C2440③ | GPIO Experiment

Previous article:S3C2440⑤ | S3C2440 clock system architecture and experiments
Next article:S3C2440⑥ | UART Experiment

Recommended ReadingLatest update time:2024-11-25 05:20

How to determine the address space used by peripherals
The S3C2410/S3C2440 storage controller has the following features: 1. The address space of each BANK is 128MB, totaling 1GB (8 BANKs); 2. Programmable control bus width (8/16/32-bit), but BANK0 can only choose two bit widths (16/32-bit); 3. There are 8 banks in total, BANK0~BANK5 can support external ROM, SRAM,
[Microcontroller]
How to determine the address space used by peripherals
Understanding of link address 0x30008000 (S3C2440)
When we write the linker script, we will set the starting link address of the code segment to 0x30008000 (S3C2440). If you misunderstand the link address, you may encounter problems like mine. Q: The link address written in the gboot linker script is actually 0x30008000 in the memory. When the cross-tool is used to
[Microcontroller]
S3C2440 RTC real-time clock driver configuration and modification under Linux
The support for S3C2440 RTC under Linux is very complete. We only need to make simple modifications to use RTC 1、vi arch/arm/mach-s3c2440/mach-smdk2440.c static struct platform_device *smdk2440_devices __initdata = { &s3c_device_usb, &s3c_device_lcd, &s3c_device_wdt, &s3c_device_i2c0,
[Microcontroller]
S3C2440 LED Driver Summary
1. Circuit Diagram 2. Instructions for use Code language: javascript This driver implements two operating modes: Normal operation mode: ./LedTest led1/led2/led3 on/off Turn on or off a certain LED Mask operation mode: ./LedTest
[Microcontroller]
S3C2440 LED Driver Summary
ARM History 10 - Graduation Project (Watches)
#include "S3C2440addr.h" #include "math.h" #define pi 3.141593 U16 SEC, MIN, HOUR, TmpSEC_10, TmpMIN_10, TmpHOUR_10,TmpSEC_1,TmpMIN_1,TmpHOUR_1; U16 SEC_x, SEC_y, MIN_x, MIN_y, HOUR_x, HOUR_y, OldMIN=10000; U16 PandColor_big ; U16 PandColor_sml ; extern U16 Flag; external U16 fz; extern const unsigned char gImage_go
[Microcontroller]
Touch screen driver on S3C2440
Create the touch screen driver my2440_ts.c, first implement the loading and unloading parts. In the driver loading part, we mainly do the following: enable the clock required by ADC, map IO ports, initialize registers, apply for interrupts, initialize input devices, and register input devices to the input subsystem. T
[Microcontroller]
S3C2440 bare metal serial port
Preface Based on JZ2440 development board 1. Mind map 2. Code 1.uart.c The code is as follows (example): /****************************************************** *********************** * * File name: uart.c * * Function: Enter characters on the keyboard, and the information will be printed on the interface throu
[Microcontroller]
S3C2440 bare metal serial port
S3C2440 address space allocation and startup process
1. Allocation of S3C2440 address space 1. The memory controller of s3c2440A has the following features: l Big and small endian (selected by software) l Address space: 128M bytes per bank (1G bytes/8 banks in total) l Programmable access bit width, bank0 (16/32 bits), other banks (8/16/32 bits) l A total of 8
[Microcontroller]
S3C2440 address space allocation and startup process
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号