0% found this document useful (0 votes)
90 views

3 - Cortex-M3 Programming

CMSIS (Cortex Microcontroller Software Interface Standard) provides tools and standards for developing microcontroller software. It includes components for core peripheral access, real-time operating systems, digital signal processing, peripheral drivers, and access to reusable software components. The goal of CMSIS is to simplify and reduce the cost of developing software for Cortex-M microcontrollers.

Uploaded by

Nghĩa Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

3 - Cortex-M3 Programming

CMSIS (Cortex Microcontroller Software Interface Standard) provides tools and standards for developing microcontroller software. It includes components for core peripheral access, real-time operating systems, digital signal processing, peripheral drivers, and access to reusable software components. The goal of CMSIS is to simplify and reduce the cost of developing software for Cortex-M microcontrollers.

Uploaded by

Nghĩa Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Principle of Microcomputer

Based on ARM Technology

Cortex-M3
Programming
CONTENTS

• Objectives

• Assembly and C

• A Typical Development Flow

• Introduction to CMSIS

2
★Objectives:

▪ Know the relation between Assembly and C

▪ Familiarize with Development of Cortex-M3

▪ At the end of the lecture you will be able to


▪ Understand the development of Cortex-M3.

3
Assembly and C - Using Assembly

• For small projects, it is possible to develop the whole


application in assembly language.
• Characteristics:
➢ get the best optimization you want
➢ Increase your development time
➢ easy to make mistakes
➢ handling complex data structures or function library
management can be extremely difficult

4
Assembly and C - Using Assembly
In many situations, part of the program is implemented in
assembly language:

• Functions that cannot be implemented in C, such as special


register accesses and exclusive accesses

• Timing-critical routines

• Tight memory requirements, causing part of the program to


be written in assembly to get the smallest memory size

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:

#define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))

*NVIC_CCR = *NVIC_CCR | 0x200; /* Set STKALIGN */

Using this feature ensures that the system conforms to


Procedure Call Standards for the ARM Architecture (AAPCS).

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,

pass parameters --- use registers R0 to R3

return value --- R0

R0–R3 and R12 can be changed by a function or subroutine,


whereas the contents of R4–R11 should be restored to the previous
state before entering the function, usually handled by stack PUSH
and stack POP.

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.

If the contents of these registers are needed at a later stage,


these registers might need to be saved on the stack and restored
after the C function completes. Since the example codes mostly
only call assembly functions or subroutines that affect a few
registers or restore the register contents at the end, it’s not
necessary to save registers R0–R3 and R12.

11
A Typical Development Flow

Example Flow Using ARM Development Tools


MDK contains a large number of utilities, including an Integrated
Development Environment (IDE) and debuggers.
12
CONTENTS
• Objectives

• Assembly and C

• A Typical Development Flow

• Introduction to CMSIS

13
★Objectives:

▪ Know the structure of CMSIS.

▪ Grasp using the CMSIS in MDK.

14
Cortex Microcontroller Software
Interface Standard (CMSIS)

CMSIS enables consistent device support and simple


software interfaces to the processor and its peripherals,
simplifying software reuse, reducing the learning curve for
microcontroller developers, and reducing the time to market
for new devices.

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.

CMSIS-RTOS: Deterministic Real-Time Software Execution A super-loop


concept is only adequate for simple embedded applications. Cortex-M
microcontrollers are designed for real-time operating systems that give you
resource and time control.

CMSIS-RTOS is an API that enables consistent software layers with


middleware and library components. CMSIS-RTOS RTX runs on every
Cortex-M device and is the proven reference implementation that is easy to
learn and use.

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.

CMSIS-Driver: Generic peripheral interfaces for middleware and


application code
Interfacing microcontroller peripherals with middleware or generic
application code can be challenging as each device is different. Ready-to
use CMSIS-Driver interfaces are today available for many microcontroller
families and avoid cumbersome and time consuming driver porting.

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.

CMSIS-SVD: Consistent view to device and peripherals


For every supported microcontroller, debuggers can provide detailed views
to the device peripherals that display the current register state.
CMSIS-SVD files enable these views, and ensure that the debugger view
matches the actual implementation of the device peripherals.

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.

CMSIS-NN: Efficient neural network kernels. Neural network-based


solutions are becoming increasingly popular for embedded machine
learning applications.
CMSIS-NN is a collection of efficient neural network kernels developed to
maximize the performance and minimize the memory footprint of neural
networks on Cortex-M processor cores.

22
Package organization

23

You might also like