ARM Programming Method Based on IAR Integrated Development Platform

Publisher:xrmilkLatest update time:2012-10-29 Source: 21IC Keywords:IAR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

In project development, especially small and medium-sized project development, in order to reduce the development difficulty and development cost, the solution of not loading the operating system is often chosen. This paper selects the IAR embedded development platform, and uses C language (about 95%) and assembly language (about 5%) to develop software for an industrial control system based on ATMEL's AT91M40800 chip (ARM7TDMI core) without loading the operating system.


Figure 1 System hardware structure



Figure 2 System software framework

Hardware Architecture

The overall hardware framework of the system is shown in Figure 1. The system basically includes various functions required by current industrial control systems, and its software development is very representative.

IAR Integrated Development Environment

IAR development platform is a comprehensive development platform based on the latest C/C++ compilation and debugging technology developed by Swedish IAR. This platform is a complete integrated development environment that can complete all the work of creating projects, editing files, compiling, assembling, linking and debugging applications; multiple projects can be placed in the same workspace; it can be configured for a single source file, a group of source files or all source files; it provides project templates and supports almost all ARM cores; it provides ANSI standard C compiler, ISO/ANSI C and embedded C++ libraries; it supports multiple JTAGs including Wiggler JTAG interface; and it provides multiple code optimization methods.

The target code generated by IAR is divided into two types: debug version (Debug) and release version (Release). The address of the Debug target code is defined in SRAM and will be downloaded to SRAM for execution; the address of the Release target code is defined in Flash, and most of it will eventually be executed in Flash. Before compiling the program, you need to write two memory allocation files, Debug.xcl and Release.xcl, according to the template. Based on the project template provided by IAR, the following areas need to be modified:

-DROMSTART=2000000
-DROMEND=200FFFF
//ROM address segment
-Z(CODE)INTVEC=00-3F
-DRAMSTART=2010000
-DRAMEND=207FFFF
//RAM address segment
-D_USR_STACK_SIZE=20000
//Stack size
-D_SVC_STACK_SIZE=50
-D_FIQ_STACK_SIZE=100
-D_ABT_STACK_SIZE=50
-D_UND_STACK_SIZE=50 -D_IRQ_STACK_SIZE=
1000
-D_HEAP_SIZE=2000
//Heap size

Startup code design

Usually, C language starts to execute from the main function. In the absence of an operating system, the initialization of the main function is completed by the startup code, including hardware initialization, stack initialization, initialization of various registers, etc.

After completing all the initialization work, a jump instruction is used to enter the main function of the C program, and the control of the program is transferred to the C program. [page]

Driver design

The software framework of the system is shown in Figure 2. The driver includes the device driver, interrupt program and interrupt service program. First, take the Flash driver design as an example. According to the Flash datasheet and hardware design, there are the following definitions:

#define FLASH_BASE ((volatile USHORT *)(0x01000000))
/*Base address of FLASH*/
/*Define the operation code of flash*/
#define FLASH_SEQ_ADD1 (0x5555)
#define FLASH_SEQ_ADD2 (0x2AAA)
#define FLASH_CODE1 ((USHORT)(0xAA))
#define FLASH_CODE2 ((USHORT)(0x55))
#define ID_IN_CODE ((USHORT
)(0x90)) #define ID_OUT_CODE ((USHORT)(0xF0))
#define WRITE_CODE ((USHORT)(0xA0))
#define CHIP_ERASE_CODE ((USHORT)(0x10))

Then write the FLASH function. The following function is used to verify the FLASH device ID:

-ramfunc-farfunc BOOL FLASH_Test(void)
{
//Input command sequence, manuf_code indicates production number, device_code indicates device number
USHORT manuf_code,device_ code;
*(FLASH_BASE + FLASH_ SEQ_ADD1) = FLASH_CODE1;
*(FLASH_BASE + FLASH_ SEQ_ADD2) = FLASH_CODE2;
*(FLASH_BASE + FLASH_ SEQ_ADD1) = ID_IN_CODE;
//Read production number and device number
manuf_code = *FLASH_BASE ;
device_code = *(FLASH_BASE + 1);
//Exit product authentication mode
*(FLASH_BASE + FLASH_ SEQ_ADD1) = ID_OUT_CODE;
//Judge whether the read production number and device number are correct
return ((manuf_code== 0x001f)&&(device_code==0x00c0));
}

When an interrupt occurs, the ARM core operating state will enter several other modes (including FIQ, IRQ, etc.) from the general mode (System & User), so it is necessary to protect the running scene (r0~r12 general registers) and push the ARM status registers (CPSR and SPSR) into the stack. The interrupt program uses assembly language to protect the registers, while the interrupt service program can be written in C language. Here we take the timer interrupt that controls the movement of the stepper motor as an example:

tc0_handler
stmfd sp!, {r14}
;Push the protection register to the stack
mrs r14, SPSR
stmfd sp!, {r14}
mrs r14, CPSR
stmfd sp!, {r0-r12,r14}
IMPORT Interrupt_Tc0
ldr r0,=Interrupt_Tc0
;Jump to C language interrupt service routine Interrupt_Tc0()
mov lr,pc
bx r0
IntExit
;Interrupt service routine completed
ldmia sp!,{r0-r12,r14}
;Restore the scene
msr CPSR_cxsf, r14
ldmia sp!,{r14}
msr SPSR_cxsf,r14
ldmia sp!, {r14}
subs pc,lr,#4

It is worth noting that ARM's division operation uses software division, which uses the r14 register, so it must also be protected. After the interrupt service program is completed, the scene is restored and the registers are popped out of the stack one by one.

Conclusion

The following experiences were gained during the development of this system:

1. Try to avoid using variables that take up a lot of storage space (such as int buffer[4096]). The system overhead is too high and may cause the system to crash.

2. Use memory allocation functions such as malloc() with caution. If used, be sure to call free() to release the memory space after use, otherwise it is easy to cause memory leaks or even system crashes.

3. Pay attention to all warning messages of the IAR compiler and carefully read the meaning of the warning messages.

4. For some modules that are frequently called and need to be processed quickly, consider using assembly.

5. When generating the Release version target code, the exe directory under the Release directory is the target file, and the *.map file in the List directory contains the specific situation of the target file's memory allocation. You can judge whether there is a problem with the memory allocation based on the information in it.

A certain industrial control product developed according to the above development method has been launched on the market after rigorous testing, and its reliability and stability have been verified.

Keywords:IAR Reference address:ARM Programming Method Based on IAR Integrated Development Platform

Previous article:Design of smart home controller based on multimedia processor VG2
Next article:Design of Inclination Angle Sensor Based on Three-axis Accelerometer SCA3000 and LPC2210

Recommended ReadingLatest update time:2024-11-16 19:51

IAR Embedded Workbench will support RISC-V space-grade processor NOEL-V
Uppsala and Gothenburg, Sweden – December 16, 2022 – IAR Systems, a global leader in embedded development software and services, and Gaisler, the Fault-Tolerant Processor Design Center of CAES, are pleased to announce a new collaboration agreement . IAR Systems’ upcoming new version of IAR Embedded Workbench
[Embedded]
IAR Embedded Workbench will support RISC-V space-grade processor NOEL-V
IAR for ARM series tutorial (I)_Detailed process of creating a new software project
II. Main Points Many people on the Internet asked: "I previously built a project using IAR for ARM V5 or V6. After IED upgraded to V7, when I opened the previous project, a lot of compilation errors appeared?" After the IAR for ARM version upgrade, there are slight differences in the tool chain. These issues will be
[Microcontroller]
IAR for ARM series tutorial (I)_Detailed process of creating a new software project
IAR include file path definition
1) In the text box that defines the path of the included file, there are two very important syntaxes for defining the path of the included file.       One is $TOOLKIT_DIR$. This syntax indicates that the path containing the files is in the 8051 folder of the IAR installation path. That is to say, if IAR is installed i
[Microcontroller]
IAR STM8S and STM32 integration
Today I installed two versions of IAR on a system with a mobile hard disk, and was surprised to find that the paths of the two versions pointed to the same path, and even the registration tool was the same. Pictures speak louder than words, above: Since the registration tools are integrated, each time you ope
[Microcontroller]
MCU, is it going to start an AI revolution?
Yesterday, a big news happened in the embedded world. IAR announced that it has joined forces with Edge Impulse to provide AI and ML integration capabilities to global customers.  Maybe many people don't know much about this news. You know, Keil and IAR are two giants in embedded/microcontroller development. IAR has
[Embedded]
MCU, is it going to start an AI revolution?
IAR updates model-based design solution to master complex designs through visualization
IAR’s state machine design solution Visual State has recently added a series of new features to enable better cross-platform support and enable large distributed teams to collaborate more effectively Uppsala, Sweden – May 17, 2023 – IAR, a global leader in embedded development software
[Embedded]
IAR updates model-based design solution to master complex designs through visualization
IAR For AVR USART Application
#include #define uchar unsigned char  #define uint unsigned int   //############################################################## /*Serial port initialization function*/ void Uart_Init(void) {                             UCSRB = (1 RXEN)|(1 TXEN)|(1 RXCIE); //Allow sending and receiving UCSRC = (1 URSEL)|(
[Microcontroller]
STM8-SO8-DISCO creates IAR template and the first project lights
Development environment:          IAR for STM8 V3.10.4 (this article mainly uses it)          STVD-STM8          Cosmic C   creates a project template:   1. Unzip en.stsw-stm8069.zip and enter the unzip directory en.stsw-stm8S069STM8S_StdPeriph_LibProjectSTM8S_StdPeriph_Template; delete the two folders RIDE and STVD
[Microcontroller]
STM8-SO8-DISCO creates IAR template and the first project lights
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号