―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.
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.
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)
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.
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.
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.
Previous article:ARM Getting Started Notes (3)
Next article:ARM Getting Started Notes (1)
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
Guess you like
- Why does the output voltage of an op amp need to be offset? Analysis of the principle of differential circuit
- [Mill MYC-J1028X development board trial] Use Node-RED to transform the MYC-J1028X development board into an industrial control gateway
- [Qinheng RISC-V core CH582] 4-The mobile phone reads and writes data from CH582
- EEWORLD University Hall ---- Operating System Principles Tian Lihua, Xi'an Jiaotong University
- FPGA digital electronic system design and development example navigation.pdf
- How much do you know about the rising star of CAT1?
- The Hall sensor signal is asymmetric and the HALL C high level is too low. What is the cause? How to solve it?
- [Reprint] "Very Silly" Circuit Problem (Part 2)
- Find a DC circuit that outputs positive and negative 12V output
- Sensor Problems