Analysis and Design of ARM7 Startup Code Writing

Publisher:陈熙琼Latest update time:2018-02-14 Source: eefocusKeywords:ARM7 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    Preface

    With the improvement of living standards and the advancement of IT technology, the processing power of 8-bit processors can no longer meet the needs of embedded systems; and 16-bit processors have not made great breakthroughs in performance and cost. In addition, in the development of 8-bit machines, assembly language is mostly used to write user programs. This makes the maintainability and portability of the program extremely challenging. It is based on this that ARM has launched a series of 32-bit embedded microcontrollers in a timely manner. Currently, the ARM7 and ARM9 series are widely used. The ARM7 processor with ARM7TDMI core is widely used in embedded devices such as industrial control, instrumentation, automotive electronics, communications, and consumer electronics. This article mainly takes the LPC2119 of Philips' ARM7TDMI core as an example to analyze how to write the startup code of ARM7.

 

    1. Startup code

    In the development of embedded system software, applications are usually written in C language on the development platform of embedded operating system. However, after the ARM system is powered on and reset, it is necessary to set the interrupt vector table, initialize the stacks of each mode, set the system clock frequency, etc., and these processes are operations on the internal register structure of ARM, which are difficult to implement using C language programming. Therefore, before turning to the C/C++ writing of the application, it is necessary to write the startup code in ARM assembly language, which completes the system initialization and jumps to the user C program. In ARM design and development, the writing of startup code is an extremely important process. However, the startup code varies with the specific target system and development system, but usually includes the following parts:

    Vector table definition

    Address remapping and transfer of interrupt vector table

    Stack initialization

    Set the system clock frequency

    Initialization of interrupt registers

    Enter C application

    The following will analyze and explain the writing of the startup code for the ARM7 processor in conjunction with the startup code of PHILIPS's LPC2119.

    1.1 Vector table definition

    After the ARM chip is powered on or reset, the system enters the management mode, ARM state, and PC (R15) points to the address 0x00000000. The interrupt vector table sets a storage space of 1 word for each interrupt, storing a jump instruction. Through this instruction, the PC pointer points to the corresponding interrupt service program entry, and then executes the corresponding interrupt handler. The interrupt vector table of LPC2219 is similar to the interrupt vector table of other chips based on the ARM core. As long as you pay attention to the fact that LPC2219 makes the 32-bit cumulative sum of all data in the vector table zero (the 8-word machine code accumulation of 0x00000000-0x0000001C), the user's program can be run offline.

    1.2 Address remapping and transfer of interrupt vector table

    The ARM7 processor reads the first instruction from address 0 after reset and executes it. Therefore, address 0 must be non-volatile ROM/FLASH after the system is powered on to ensure that the processor has the correct instructions available. In order to speed up the processing of interrupts and implement the processing of interrupts in different operating system modes, it is necessary to remap the interrupt vector table, Bootb LOC k and a small part of the SRAM space. ARM has a very flexible memory address allocation feature. There are two situations in the address remapping mechanism of the ARM processor:

    ① Remapping is done by a dedicated register, and you only need to set the corresponding bit of the corresponding Remap register.

    ② There is no dedicated Remap control register. The bank register used to control the memory start address needs to be rewritten to implement Remap. Remapping on LPC2119 can be achieved through the memory mapping controller. The program to implement the REMAP operation is as follows:

    MOV R8,#0x40000000; /Set the starting address of the new vector table/

    LDR R9,=Interrupt_Vector_Table; /Read the original vector table source address/

    LDMIA R9!, (R0-R7); /Copy the interrupt vector table and the entry address of the interrupt handler to RAM (64 bytes)/

    STMIA R8!,(R0-R7)

    LDMIA R9!,(R0-R7)

    STMIA R8!,(R0-R7)

    LDR R8, =MEMMAP; /REMMAP operation/

    MOV R9, #0x02

    STR R9, [R8]

    1.3 Stack Initialization

    The setting of stack space for each mode in the startup code is for interrupt processing and program jump. When the system responds to an interrupt or a program jumps, the current processor status and some important parameters need to be saved in a storage space, so the stack initialization work must be performed for each mode, and a stack base address and stack capacity are defined for the SP of each mode. There are two ways to initialize the stack: The first method is to define the stack in combination with the scattered loading file in the ADS development kit. The second method is the simplest and most commonly used one, which is to directly enter the corresponding processor mode and specify the corresponding value for the SP register. The following is a program for initializing the management mode and interrupt mode stack using the second method:

    MSR CPSR_c, #0xD3; /Switch to management mode and initialize the management mode stack/

    LDR SP, Stack_Svc

    MSR CPSR_c, #0xD2; /Switch to IRQ mode and initialize the IRQ mode stack/

    LDR SP, Stack_Irq

    …

    1.4 Initialization of some system clocks

    The clock is the basis for the normal operation of all parts of the chip, and should be set before entering the main() function. Some ARM7 chips have integrated PLL ( phase-locked loop ) circuits . Users can use low-frequency crystal oscillators to obtain a higher-frequency clock through the PLL circuit. The input clock frequency range accepted by the PLL circuit inside the LPC2119 is 10-25MHz , and the input frequency is multiplied to the range of 10-60MHz through a current- controlled oscillator ( CCO ). At the same time, in order to enable the high-speed ARM processor to communicate normally with low-speed peripherals and reduce power consumption (reducing the operating speed of peripherals to reduce power consumption), LPC2119 integrates an additional divider . The activation of the PLL is controlled by the PLLCON register. The values ​​of the PLL multiplier and divider are controlled by the PLLCFG register. Changes to the PLLCON or PLLCFG registers must follow a strict order, otherwise the changes will not take effect (write 0xAA, 0x55 to the PLLFEED register in consecutive VPB cycles , and interrupts must be disabled during this period.)

    1.5 Interrupt initialization

    ARM7's Vectored Interrupt Controller can program interrupts into three categories: FIQ, vectored IRQ, and non-vectored IRQ. FIQ interrupt requests have the highest priority, followed by IRQ interrupt requests, and non-vectored IRQ has the lowest priority. VIC has 32 interrupt request inputs, but only 17 interrupt inputs are occupied in LPC2219. The IRQ/FIQ selection of these 17 interrupt sources is controlled by the VICIntSelect register. When the corresponding bit is set to 1, the interrupt is a FIQ interrupt, otherwise it is an IRQ interrupt. If the IRQ interrupt is set to the vector control register (VICVectCntIn), the interrupt is a vectored IRQ interrupt, otherwise it is a non-vectored IRQ interrupt. FIQ interrupts are specifically used to handle special events that require timely responses, and only one interrupt source is assigned to FIQ as much as possible.

    1.6 Entering the C Application

    At this point, the initialization of each part of the system is basically completed, and you can directly transfer from the startup code to the main() function entry of the application. The example code for transferring from the startup code to the application is as follows:

    IMPORT main

    LDR R0, =main

    BX

    2. Summary

    An excellent startup code will provide a good development platform for application development. This article discusses the writing and difficulties of startup code in detail. In the stack initialization process, special attention should be paid to two points:

    ① Try to allocate fast and high-bandwidth memory to the stack.

    ② Try to avoid switching the processor to user mode too early. Generally, it is switched to user mode in the final stage of system initialization (user mode does not have the authority to switch modes by modifying CPSR).

    The rapid development of embedded systems has made the writing of boot code a skill that embedded system developers should have. This article helps readers who are engaged in embedded ARM development to understand the connotation of boot code and write boot code that suits them.


Keywords:ARM7 Reference address:Analysis and Design of ARM7 Startup Code Writing

Previous article:Design of USB Host System in μCOS-II
Next article:Remote wireless water supply measurement and control system based on embedded and wireless communication technology

Recommended ReadingLatest update time:2024-11-15 07:33

Design of digital system for call control protocol without center based on ARM7 and MX618 chip
introduction The centerless mobile communication system is an important part of my country's professional mobile communication system. It works in a simplex intercom mode with an operating frequency between 915.0125 and 916.0875 MHz. The system has many technical features such as centerless networking, digital selecti
[Microcontroller]
Design of digital system for call control protocol without center based on ARM7 and MX618 chip
ARM7 Thumb series embedded processors
    The arm7 Thumb series processors are a series of high-performance, low-power 32-bit RISC processors that combine the Thumb 16-bit reduced instruction set. The excellent code efficiency achieved by Thumb means a reduction in the demand for memory capacity, making it possible to achieve high performance that can onl
[Microcontroller]
Application of ARM7 Embedded System in Vehicle Dispatching System Design
    1. Overall design of vehicle dispatching system:     The whole system consists of four parts: (1) communication master station; (2) vehicle-mounted slave station; (3) communication link; and (4) system monitoring part. The following is a brief introduction to the functions of each part.     (1) Communication maste
[Microcontroller]
Application of ARM7 Embedded System in Vehicle Dispatching System Design
ARM7 2131 BEEP Program Analysis
ARM7 BEEP Program Analysis In the schematic diagram, we can see that the buzzer is connected to the P07 port, and the interface is short-circuited. #include "config.h" #define BEEP 1 7 // P0.7 controls the buzzer, low-level buzzer Includes a config.h header file, which mainly defines the data type, clock fr
[Microcontroller]
Design of dormitory intelligent fire and theft alarm system based on ARM7
  0 Preface   Nowadays, in school dormitories, accidents such as theft of students' valuables and fires caused by students' negligence often occur. These are "big problems" that have always troubled students, student workers and school security departments. Traditional preventive measures have great drawbacks. For ex
[Microcontroller]
Design of dormitory intelligent fire and theft alarm system based on ARM7
Build a simple robotic arm using ARM7 LPC2148 microcontroller
  Robotic arms are one of those fascinating engineering creations, and it's always fascinating to watch these things tilt and translate to accomplish complex things just like a human arm. These robotic arms are commonly found in industries that perform high-intensity mechanical work such as welding, drilling, and pain
[Microcontroller]
Build a simple robotic arm using ARM7 LPC2148 microcontroller
ARM core pipeline - ARM7, ARM9E, ARM11, Cortex-A series processors
This article mainly introduces the pipeline of ARM7, ARM9E, ARM11 and Cortex-A series processors, from instruction fetch, instruction decoding to each stage of instruction execution. Refer to ARM's website http://www.arm.com/about/company-profile/index.php. ARM was founded in 1990 and has sold more than 15 billion chi
[Microcontroller]
Changxue multifunctional ARM7 experimental box LED water light resources detailed explanation
1. Single color running light test Hardware preparation: 1 8P DuPont line Wiring instructions: Use an 8P DuPont line to connect P019~P026 of the ARM core board to JP15 of the single-color water light module on the bottom board. Jumper Description: None They are: P019-I1, P020-I2, P021-I3, P022-I4, P023-I5, P0
[Microcontroller]
Changxue multifunctional ARM7 experimental box LED water light resources detailed explanation
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号