Getting Started with S3c2410 Bare Board Program---Flowing Light

Publisher:beup001Latest update time:2023-05-10 Source: elecfansKeywords:S3c2410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I am new to arm, so I wrote a few small practice programs, recorded here.


Includes: running water lamp, single button, pwm driven buzzer, serial port and PC communication


Development board s3c2410, development environment realview + h-jtag


Without further ado, let’s start the first program. The study of bare board program development by Liu Shui Deng is like hello world, the first lesson for novices in any high-level language, haha. The contents of several files are as follows:


led.c 


 1 #include "s3c2410.h"

 2 #include "delay.h"

 3 

 4 

 5 

 6 void myblink(void)

 7 {

 8 delay(0);

 9 GPFCON = (GPFCON & ~(0xff<<8))|0x5500;

10 

11 while(1){

12 GPFDAT = 0x7f;

13 delay(1000);

14 GPFDAT = 0xbf;

15 delay(1000);

16 GPFDAT = 0xdf;

17 delay(1000);

18 GPFDAT = 0xef;

19 delay(1000);

20}

twenty one }

Configure GPF4, 5, 6, and 7 pins as output states through GPFCON, and write data to the corresponding ports through GPFDAT. Pay attention to this bit operation method. In addition, the pin pull-up can also be configured through the GPFUP register, which is not used in this example.


delay.c


 1 #include "delay.h"

 2 #include "s3c2410.h"

 3 

 4 

 5 static int delayLoopCount = 400;

 6 

 7 /************************************************ *********************************************

 8 * name: delay

 9 * func: delay time

10 * para: nTime -- input, nTime=0: nAdjust the delay function by WatchDog timer.

11 * nTime>0: the number of loop time, 100us resolution.

12 * ret: none

13 * modify:

14* comment:      

15 ************************************************* *********************************************/

16 void delay(int nTime)

17 {

18 // time=0: adjust the Delay function by WatchDog timer.

19 // time>0: the number of loop time

20 // resolution of time is 100us.

21 int i,adjust=0;

22 if(nTime==0)

twenty three {

24 nTime = 200;

25 adjust = 1;

26 delayLoopCount = 400;

27 //PCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable

28 WTCON = ((PCLK/1000000-1)<<8)|(2<<3);

29 WTDAT = 0xffff; //for first update

30 WTCNT = 0xffff; //resolution=64us @any PCLK 

31 WTCON = ((PCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start

32}

33 for(;nTime>0;nTime--)

34 for(i=0;i35 if(adjust==1)

36 {

37 WTCON = ((PCLK/1000000-1)<<8)|(2<<3); //Watch-dog timer stop

38 i = 0xffff - WTCNT; //1count->64us, 200*400 cycle runtime = 64*i us

39 delayLoopCount = 8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i)   

40}

41 }

This is the delay code in the development board routine. I used it directly and the comments are more detailed. Note that the watchdog timer is only used once, when delay(0) is used to calculate the initial value of delayLoopCount. I still don't like this kind of delay method. It's too wasteful to just let the CPU run idle.


fs2410_ram.sct


 1 ; ************************************************ *************

 2 ; *** Scatter-Loading Description File generated by uVision ***

 3;************************************************ *************

 4 

 5 LR_ROM1 0x30000000 0x00200000 { ; load region size_region

 6 ER_ROM1 0x30000000 0x00200000 { ; load address = execution address

 7 *.o (RESET, +First)

 8 ;*(InRoot$$Sections)

 9.ANY (+RO)

10}

11 RW_RAM1 +0 { ; RW data

12.ANY (+RW +ZI)

13}

14}

15 

fs2410_flash.sct


 1 ; ************************************************ *************

 2 ; *** Scatter-Loading Description File generated by uVision ***

 3;************************************************ *************

 4 

 5 LR_ROM1 0x00000000 0x00200000 { ; load region size_region

 6 ER_ROM1 0x00000000 0x00200000 { ; load address = execution address

 7 *.o (RESET, +First)

 8 ;*(InRoot$$Sections)

 9.ANY (+RO)

10}

11 RW_RAM1 0x30000000 0x04000000 { ; RW data

12.ANY (+RW +ZI)

13}

14}

DebugInRam.ini


 1 FUNC void Init_Board(void)

 2 {

 3 _WWORD (0x53000000,0x00000000);

 4 

 5 _WWORD (0x4A000008,0xFFFFFFFF);

 6 _WWORD (0x4A00001C,0x000007FF);

 7 

 8 _WWORD (0x4C000014,0x3);

 9 _WWORD (0x4C000004,0x0005c042);

10 

11 _WWORD (0x56000070,0x00280000);

12 _WWORD (0x56000078,0x00000000);

13 

14 _WWORD (0x48000000,0x22111110);

15 _WWORD (0x48000004,0x00000700);

16 _WWORD (0x48000008,0x00000700);

17 _WWORD (0x4800000C,0x00000700);

18 _WWORD (0x48000010,0x00000700);

19 _WWORD (0x48000014,0x00000700);

20 _WWORD (0x48000018,0x00000700);

21 _WWORD (0x4800001c,0x00018005);

22 _WWORD (0x48000020,0x00000700);

23 _WWORD (0x48000024,0x008e0459);

24 _WWORD (0x48000028,0x000000B2);

25 _WWORD (0x4800002c,0x00000030);

26 _WWORD (0x48000030,0x00000030);

27 

28 _WWORD (0x56000014,0x1);

29 

30 _WWORD (0x56000020,0xaaaa55aa);

31 _WWORD (0x56000028,0xffff);

32 _WWORD (0x56000024,0x0);

33 pc = 0x30000000;

34}

35 //map 0x48000000, 0x60000000 read write

36 Init_Board();

37 

In fact, the key to this first project is to be familiar with the processor, board, and development environment. Therefore, the configuration of the project is the key point.


fs2410_ram.sct and fs2410_flash.sct are link scripts whose target files are run on ram and flash respectively. They are mainly used to configure the addresses of the program code segment and data segment. ;*(InRoot$$Sections) is commented out because a development board is not needed. For the libraries provided, it is very important to understand the address allocation of the board before writing the program. These two files are generated by realview. You cannot compile the project at the beginning and they will be generated automatically.


DebugInRam.ini is the debugging script when the target is running on ram. It was not written by me. It is included in the development board routine, but this is very important. Otherwise, the memory has not been initialized, and there will be problems with the debugger. It cannot be Always run programs on flash.


The above three scripts, unless otherwise specified, will be used in subsequent programs and will not be posted again.


main.c is very simple. It just contains the header file and then calls myblink. I won’t post it here. This project does not require the startup code provided by the project


You can also use S3C2410A.C, but the configuration is more complicated, which is the content of other articles.


Keywords:S3c2410 Reference address:Getting Started with S3c2410 Bare Board Program---Flowing Light

Previous article:PLL,FCLK、HCLK、PCLK,AHB/APB (S3C2410)
Next article:Introduction to 3c2410 bare board program---single button (2)

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号