ARM Getting Started Notes (2)

Publisher:skyshoucangLatest update time:2015-04-20 Source: eechinaKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
―Execute the program to the main function of the C file

II. Experimental purpose

Use ADS to write a small program so that the program can run from the initial assembly code to the main() function of the C program (this can also be called a very simple startup code), and connect the target board through the emulator, and finally run correctly in the AT91SAM7S64.

III. Experimental program and parameter settings

1> Connector option settings

The option settings are shown in Figure 2-1. Because the address of the FLASH memory in the AT91SAM7S64 starts with 0x0, and the address of the SRAM starts with 0x00200000, I set the RO Base and RW Base in the figure below to 0x0 and 0x00200000 respectively. For other settings, please refer to relevant books.
            
1.jpg 
Figure 2-1. Option Setting Figure

2> Startup Code

In ARM application system, after chip reset, before entering the main() function of C language, a startup code must be executed. This code is generally written in assembly language to complete the initialization of system operating environment and application program. For details, please refer to relevant books. Since the purpose of this experiment is very simple, that is, to let the program enter the main() function after reset, some initialization codes are simplified as much as possible, leaving the following code. In addition, __main is an internal library function of C language, which can complete the initialization of internal RAM before entering the user main(), similar to startup.a51 in KeilC51. After executing the __main code, jump to the main() function.

AREA init,CODE,READONLY
CODE32
Mode_USR EQU 0x10 ;Control bits corresponding to various processor modes in CPSR
I_Bit EQU 0x80 ;Interrupt disable bit
F_Bit EQU 0x40 in CPSR
USR_Stack EQU 0x00203000 ;Define the highest address of RAM, no remapping
ENTRY
                B InitReset ; 0x00 Reset handler
undefvec B undefvec ; 0x04 Undefined Instruction
swivec B swivec ; 0x08 Software Interrupt
pabtvec B pabtvec ; 0x0C Prefetch Abort
dabtvec B dabtvec ; 0x10 Data Abort
rsvdvec B rsvdvec ; 0x14 reserved
irqvec B irqvec ; 0x18 IRQ
fiqvec B fiqvec ; 0x1c FIQ
InitReset
MSR CPSR_c,#Mode_USR | I_Bit | F_Bit ;Change to user mode and disable IRQ and FIQ interrupts
LDR SP,=USR_Stack
IMPORT __main                  
b __main ;Jump to __main execution, which is located in the C runtime libraryEND                                
3
>C language main function
In the C language main function, an infinite loop is made, as shown below.
int main(void)
{
  while (1);
}

IV. Problems and solutions

After completing the above operations, software simulation is used first, and the purpose is achieved quickly, but the following problems occur when the program is run on the target board through the emulator.

1> When executing single-step operation, PC always stays at 0x0, and the Debug Log window displays "RDI Warning 00148: Can't set point".
The reason is that the number of breakpoints set in the ROM of the emulator is limited, and the breakpoints are also occupied internally during single-step operation. You can use "Option->Config Processor" to open the "Processor Properties-ARM7TDMI" window and set the breakpoint to shut down the phase according to the figure below.

2.jpg 
Figure 2-2

2> The loaded code is different from the actual program

The reason is that the program is not loaded into the FLASH ROM of AT91SAM7S64, and the debugger displays the program that originally existed in the FLASH ROM. Because in the option settings of the connector, RO Base and Image entry point are pointed to address 0, and this space in AT91SAM7S64 is the FLASH ROM area, and the emulator cannot directly download the code to the FLASH ROM. The emulator can only download the code to the internal SRAM of AT91SAM7S64 for debugging. It is necessary to change ARM Linker->Output->Simple image->RO Base and Image entry point 0 to the SRAM address 0x002000000.

3> In the case of software simulation, executing the "B __main" instruction can make the program jump to the main function of the C file, but in hardware simulation, it enters an abnormal interrupt before executing the main function.

The reason is that after executing the "B __main" instruction, the program first jumps to the entrance of the __main library function, then performs some initialization operations, and finally jumps to the user's main function. However, during the initialization process, the program fails due to the stack or other reasons. There are two ways to solve this problem. First: change the "B __main" instruction directly to "B main" so that the program does not initialize and directly jumps to the user's main() function. Second: initialize the stack properly. Considering that I have just come into contact with ARM and want to simplify the problem, I chose the first method.

V. Summary

1> When using the emulator, the program must be downloaded to the internal SRAM of AT91SAM7S64 instead of Flash ROM.

2> When entering the C file function from the assembly code, you can directly use the label in the C language (refer to the mixed programming part in the book). For example, if you execute "B main", it will jump directly to the entrance of the C language main() function.

3> In the startup code, you can call the __main() library function to initialize the memory, or you can write more effective code to initialize it yourself. After initialization, you can use the "B __main" instruction to directly jump to the C main() function.
Keywords:ARM Reference address:ARM Getting Started Notes (2)

Previous article:ARM Getting Started Notes (3)
Next article:ARM Getting Started Notes (1)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号