3 - Cortex-M3 Programming
3 - Cortex-M3 Programming
Cortex-M3
Programming
CONTENTS
• Objectives
• Assembly and C
• Introduction to CMSIS
2
★Objectives:
3
Assembly and C - Using Assembly
4
Assembly and C - Using Assembly
In many situations, part of the program is implemented in
assembly language:
• Timing-critical routines
5
Assembly and C - Using C
C has the advantage of being portable and easier for
implementing complex operations, compared to assembly language.
Characteristics:
➢ speed up application development
In many cases, low-level system control will still require assembly
code.
• accessing special registers (MRS and MSR instructions; for
example, setting up stack memory)
• use instructions that cannot be generated using C (for example,
sleep [WFI and WFE], exclusive accesses, and memory barrier
operations)
6
Assembly and C - Using C
Method of MDK: Embedded Assembler
For example,
__STATIC_INLINE void __set_PRIMASK(uint32_t
priMask)
{
register uint32_t __regPriMask
__ASM("primask");
__regPriMask = (priMask);
}
7
Assembly and C - Using C
When you’re developing applications in C, it is recommended
that you use the double word stack alignment function (configured
by the STKALIGN bit in the NVIC Configuration Control register). This
can be set in the startup code. For example:
8
Assembly and C
- The Interface Between Assembly and C
In various situations, assembly code and the C program interact.
For example:
• When embedded assembly is used in C program code
• When C program code calls a function or subroutine implemented in
assembler in a separate file
• When an assembly program calls a C function or subroutine
In these cases, it is important to understand how parameters and return
results are passed between the calling program and the function being called.
The mechanisms of these interactions are specified in the ARM Architecture
Procedure Call Standard (AAPCS).
9
Assembly and C
- The Interface Between Assembly and C
For simple cases,
10
Assembly and C
- The Interface Between Assembly and C
If a C function is called by an assembly code, the effect of a
possible register change to R0–R3 and R12 will need to be taken
into account.
11
A Typical Development Flow
• Assembly and C
• Introduction to CMSIS
13
★Objectives:
14
Cortex Microcontroller Software
Interface Standard (CMSIS)
15
Cortex Microcontroller Software
Interface Standard (CMSIS)
Starting from CMSIS-CORE, a vendor-independent hardware
abstraction layer for Cortex-M processors, CMSIS has since expanded
into areas such as software component management and reference
debugger interfaces. Creation of software is a major cost factor in the
embedded industry. Standardizing the software interfaces across all
Cortex-M silicon vendor products, especially when creating new projects
or migrating existing software to a new device, means significant cost
reductions.
16
Cortex Microcontroller Software
Interface Standard (CMSIS)
CMSIS is defined in close cooperation with various silicon
and software vendors and provides a common approach to
interface to peripherals, real-time operating systems, and
middleware components. It simplifies software reuse,
reducing the learning curve for new microcontroller
developers and cutting the time-to-market for devices.
17
CMSIS Diagram
https://developer.arm.com/embedded/cmsis
18
CMSIS Components(1/4)
CMSIS-CORE: Consistent system startup and peripheral access System
startup, processor core access, and peripheral definitions are essential for
every embedded application. The standardized CMSIS-CORE is implemented
for over 3900 different devices and makes it easy to get started with a new
device or migrate software across microcontrollers.
19
CMSIS Components(2/4)
CMSIS-DSP: Fast implementation of digital signal processing Developing a
real-time digital signal processing (DSP) system is not trivial as the DSP
algorithms rely heavily on complex mathematical operations that are even
time-critical.
CMSIS-DSP library is a rich collection of DSP functions that Arm has
optimized for the various Cortex-M processor cores. CMSIS-DSP is widely
used in the industry and enables also optimized C code generation from
various third-party tools.
20
CMSIS Components(3/4)
CMSIS-Pack: Easy access to reusable software components
Previously, software modules were hard to integrate as the source and header
files had unclear requirements, inconsistent documentation, or missing license
information.
Because CMSIS-Pack defines the structure of a software pack containing
software components, these issues are addressed. Software components are
easily selectable, and any dependencies on other software are highlighted.
21
CMSIS Components(4/4)
CMSIS-DAP: Connectivity to low-cost evaluation hardware Inexpensive
development boards are available from many microcontroller vendors.
Frequently, a low-cost debug unit is included, but different interfaces need a
specific tool setup.
CMSIS-DAP is a standardized interface to the Cortex Debug Access
Port (DAP) and is used by many starter kits and supported by various
debuggers.
22
Package organization
23