Processors ESIGELEC-MSEE 2022 P4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Chapter IV

ARM Cortex M4 Programming Exercises

1 February 2022
Chapter Syllabus

▪ Software Development Tools


▪ Initiation to µVision Simulation Environment
▪ Assembler Programs Analysis

2
SOFTWARE DEVELOPMENT TOOLS

3
MCU Software Development Flow

4
Project Options to configure

5
MCU Software Compilation Flow

6
ARM Software Development Tools

Software Tools JTAG Debug and Trace Development Platforms


▪ DSTREAM ▪ Fast Models
▪ DS-5 ▪ Versatile Platform baseboards
▪ Application Edition

▪ Linux Edition

▪ Professional Edition ▪ ULINK ▪ Keil MCU development boards


▪ Keil µVision simulator
▪ MDK: Keil Microcontroller
Development Kit

7
DS-5 Professional at a Glance
▪ Integrated solution, professionally supported and maintained
▪ End-to-end development, from SoC bring-up to application debug

▪ Powerful ARM compiler DS-5


Eclipse
▪ Best code size and performance Compiler
IDE Debugger Streamline
▪ Intuitive DS-5 debugger
Device Configuration Database
▪ Flexible graphical user interface Simulation Hardware Debug

▪ DSTREAM probe with 4GB trace buffer

▪ Fast SoC simulation models


▪ Develop in a controlled environment
▪ Examples and applications

▪ Streamline performance analyzer


▪ System-wide analysis of Linux
and Android systems
8
Development Suite: MDK
▪ Low cost tools for ARM7, ARM9, Cortex-M and Cortex-R4 MCUs
▪ Extensive device support for many devices
▪ Core and peripheral simulation
▪ Flash support

▪ Microcontroller Development Kit (MDK)


▪ IDE, optimized run-time library, KEIL RTX RTOS
▪ ARM Compiler
▪ Realtime trace (for Cortex-M3 and Cortex-M4 based devices)

▪ Real-Time Library
▪ KEIL RTX RTOS + Source Code
▪ TCP networking suit, Flash File System, CAN Driver Library, USB Device Interface

▪ Debug Hardware
▪ Evaluation boards
9
GNU Tools and Linux
▪ GNU/GCC Tools Support
▪ ARM works with CodeSourcery to keep the GNU toolchain current with the latest ARM processors

▪ Linux Support
▪ Pre-built Linux images are available for ARM hardware platforms
▪ DS-5 accepts kernel images built with the GNU toolchain
▪ Can also debug applications or loadable kernel modules
▪ RVCT can be used to build Linux applications or libraries
▪ Giving performance benefits

▪ ARM does not provide technical support for the GNU toolchain, or Linux kernel/driver development

10
Keil-MDK µVision IDE Icons

11
INITIATION TO MICROVISION
SIMULATION ENVIRONMENT

12
New µVision Project Creation
1. Start µVision Program
2. Select the Project Menu, than the command New µVision project,

3. Choose a name and a directory for the project


4. Choose the target ARMCM4

13
Software Components Configuration
5. When the target selected, the window «Manage Run-Time Environnement » open automatcallyt. It permits
to configure the software components plataform needed to be used in the project.
Any program need to contain startup instructions, for that you need to select « Startup » under « Device »

14
Software Components Configuration
▪ The orange color means that other softwares are needed. They are displayed in the "Validation Output"
window.
▪ Simply press the "Resolve" button to automatically add the missing components. Once all the necessary
components are added and the color of the "selection" column turns green, simply press the "OK" button
to validate the addition.

15
Software Components Configuration
6. Components that have been added automatically are displayed in the Project Window tree under green
diamonds.

16
Target Configuration
7. Options for Target

▪ Select the Debug tab and check “Use Simulator”

17
Add Source Files
8. Right-click on “New Group” and from the context menu select "Adding Existing Files to Group
'New Group' ..."

Select the file Programme1.s and add it to the project.

18
Generate Executable
9. Build Target files to generate an executable

19
Debug Session
10. Debug Session

20
Debug Session
11. Different Debug options

▪ Running the entire program - Run: F5 key


▪ Step by step execution - Step: F11 key

21
ASSEMBELR PROGRAMS ANALYSIS

22
Program 1
GLOBAL __main
AREA Program, CODE, READONLY

__main LDR R0, =Value1


LDR R1, [R0]
LDR R2, [R0, #4]
LDR R0, =Value2
LDR R3, [R0]
LDR R4, [R0, #4]
ADDS R6, R2, R4
ADC R5, R1, R3
LDR R0, Result
STR R5, [R0]
STR R6, [R0, #4]
SVC 0x11

ALIGN
Value1 DCD 0x12A2E640, 0xF2100123
Value2 DCD 0x001019BF, 0x40023F51
Result DCD 0x20000000

END
23
Program 2
GLOBAL __main
AREA Program, CODE, READONLY

__main LDR R0, =TAB1


LDR R1, Value
MOV R1, R1, LSL #0x2
ADD R0, R0, R1
LDR R2, [R0]
LDR R3, Result
STR R2, [R3]
SWI 0x11

ALIGN
TAB1 DCD 1, 1, 2, 6, 24, 120, 720, 5040

Value DCB 5
ALIGN
Result DCD 0x20000000

END

24
Program 3
GLOBAL __main
AREA Program, CODE, READONLY

__main LDR R0, =Table


EOR R1, R1, R1
LDR R2, Length
LDR R4, Result
Loop
LDR R3, [R0], #4
ADD R1, R1, R3
SUBS R2, R2, #0x1
BNE Loop
STR R1, [R4]
SVC 0x11

ALIGN
Table DCD 0x2040
DCD 0x1C22
DCD 0x0242
Length DCW 3;
ALIGN
Result DCD 0x20000000
25
END
Program 4
GLOBAL __main
AREA Program, CODE, READONLY

__main MOV R0, #625 ; input


MOV R1, #0x8000
MOVS R2, #0

sqrt_loop ADDS R2, R2, R1


MUL R3, R2, R2
CMP R3, R0
IT HI
SUBHI R2, R2, R1
LSRS R1, R1, #1
BNE sqrt_loop
SVC 0x11

END

26
Program 5
GLOBAL __main
AREA Program, CODE, READONLY
__main
MOV R6,#8 ;
MOV R4,#8
MOV R7, #0xFFFF ;
MOVT R7, #0xFFFF

LDR R8,=TAB1
loop1 LDR R0,[R8], #4
MOV R5, #0;
CMP R7,R0
BLS toto1;
MOV R7, R0 ;
SUB R5, R4, R6
toto1 SUBS R6,R6,#1
BNE loop1 ;

SVC 0x01;
ALIGN
TAB1 DCD 0xE123, 0x981,0xFFFFFFFC,0x73,0x61B1,0xC54,0xD01A,0x720,0x4C15
END
27
Program 6
GLOBAL __main GLOBAL __count_ones
EXTERN __count_ones AREA Program, CODE, READONLY

AREA Program, CODE, READONLY __count_ones MOV R1,#0


__main MOV R2, #32
MOV R6,#8 ; MOV R3,#1
MOV R7, #0 ; loop ANDS R4,R0,R3
LDR R8,=TAB1 BEQ toto
loop1 LDR R0,[R8], #4 ADD R1, R1, #1
BL __count_ones toto LSL R3,#1
CMP R7,R1 SUBS R2, R2, #1
BGT toto1; BNE loop
MOV R7, R1 ; BX LR ;return
MOV R5, R0
toto1 SUBS R6,R6,#1 END
BNE loop1

SVC 0x01
ALIGN
TAB1 DCD 1,68,2,6,24,123,720,15
END

28

You might also like