0% found this document useful (0 votes)
113 views29 pages

Software Libraries: CMSIS and Mbed SDK: ARM University Program

Uploaded by

Oussama Tarkhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views29 pages

Software Libraries: CMSIS and Mbed SDK: ARM University Program

Uploaded by

Oussama Tarkhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Software Libraries: CMSIS and

mbed SDK

ARM University Program


Copyright © ARM Ltd 2013 1
Module Syllabus
 Overview of Software Libraries
 Cortex Microcontroller Software Interface Standard (CMSIS)
 What is CMSIS

 What is Standardized in CMSIS

 Benefits of CMSIS

 CMSIS Functions

 mbed Software Development Kit (SDK)


 What is mbed SDK

 Features of mbed SDK

 mbed SDK Library Structure

 Example of mbed SDK Library Layers

ARM University Program


Copyright © ARM Ltd 2013 2
Overview of Software Libraries
 In the previous modules, we have learned how to control a GPIO
peripheral (connected to digital IOs such as LEDs) at a low-level.
However, there are a number of disadvantages when programing in low-
level, such as:

Low productivity

Less portable from one device to another device

Resulting code is more difficult for others to read,


reuse, and maintain

Can result in inefficient code as high level


optimization are missed (low code density)

ARM University Program


Copyright © ARM Ltd 2013 3
Overview of Software Libraries
 With support from software libraries or Application Programming
Interfaces (APIs), we could ease our application development in a variety
of ways to achieve:

 Higher productivity (less development time)

 Portability across devices

 Resulting code is easier code to read, reuse and maintain by others

 More efficient code (code density and performance)

ARM University Program


Copyright © ARM Ltd 2013 4
ARM CMSIS and mbed SDK
 In this module, we will introduce two libraries/APIs:
 CMSIS-CORE – Cortex Microcontroller Software Interface Standard
 mbed SDK – mbed Software Development Kit

End-user

mbed API

mbed Common MCU independent

mbed SDK mbed HAL API

mbed HAL Implementation


MCU dependent
CMSIS-CORE

Cortex-M3 MCU Registers MCU hardware

ARM University Program


Copyright © ARM Ltd 2013 5
CMSIS – Cortex Microcontroller
Software Interface Standard

ARM University Program


Copyright © ARM Ltd 2013 6
What is CMSIS
 CMSIS – Cortex Microcontroller Software Interface Standard
 CMSIS is a vendor-independent hardware abstraction layer for the Cortex-M processor
series
 CMSIS provides a standardized software interface, such as library functions which help
you control the processor more easily, e.g. configuring the Nested Vectored Interrupt
Controller (NVIC)
 Main reason is to improve software portability across different Cortex-M processors and
Cortex-M based microcontrollers

Configure
Configure Cortex-M3
Cortex-M3 by by directly
directly accessing
accessing Configure
Configure Cortex-M
Cortex-M processors
processors
registers
registers in its internal memory space
in its internal memory space by using CMSIS libraries
by using CMSIS libraries
e.g.
e.g. *(unsigned
*(unsigned int*)
int*) NVIC_INT_ENABLE
NVIC_INT_ENABLE == 0x01; 0x01; e.g.
e.g. NVIC_EnableIRQ(Timer_IRQn);
NVIC_EnableIRQ(Timer_IRQn);

ARM
ARM CMSIS-Core
CMSIS-Core

Cortex-M0

Cortex-M
ARM
ARM Cortex-M0
Cortex-M0 Cortex-M3
Processor
Processor
Cortex-M4

ARM University Program


Copyright © ARM Ltd 2013 7
What is Standardized in CMSIS
 Standardized functions to access NVIC, System Control Block (SCB), and System
Tick timer (SysTick), for example:

 Enables an interrupt or exception: NVIC_EnableIRQ (IRQn_Type IRQn)


 Sets pending status of interrupt: void NVIC_SetPendingIRQ (IRQn_Type IRQn)

 Standardized access of special registers, for example:

 Read PRIMASK register: uint32_t __get_PRIMASK (void)


 Set CONTROL register: void __set_CONTROL (uint32_t value)

 Standardized functions to access special instructions, e.g.

 REV: uint32_t __REV(uint32_t int value)


 NOP: void __NOP(void)

 Standardized names for system initialization functions, e.g.

 System initialization: void SystemInit(void)

ARM University Program


Copyright © ARM Ltd 2013 8
Benefits of CMSIS
 Easier to port application code from one Cortex-M based microcontroller to
another Cortex-M based microcontroller
 Less effort to reuse the same code between different Cortex-M based
microcontrollers

 Better compatibility when integrating


third-party software components,
since all the third-party components
such as applications, embedded OS,
middleware etc., can share the same
standard CMSIS interface

 Better code density and smaller


memory footprint, since the codes in
CMSIS have been optimised and
tested

ARM University Program


Copyright © ARM Ltd 2013 9
CMSIS Components
 The CMSIS consists of the following components:
 CMSIS-CORE
 CMSIS-DSP, CMSIS-RTOS API and CMSIS-SVD
 In this module, we will focus on using CMSIS-CORE

ARM University Program


Copyright © ARM Ltd 2013 10
CMSIS Components
 CMSIS-CORE
 Provides an interface to Cortex-M0, Cortex-M3, Cortex-M4, SecureCore™
SC000 and SC300 processors, and peripheral registers  

 CMSIS-DSP
 DSP library with over 60 functions in fixed-point (fractional q7, q15, q31) and
single precision floating-point (32-bit) implementation

 CMSIS-RTOS API
 Standardized programming interface for real-time operating systems, for
thread control, resource, and time management

 CMSIS-SVD:
 System View Description XML files that contain the programmer's view of a
complete microcontroller system including peripherals  

ARM University Program


Copyright © ARM Ltd 2013 11
CMSIS Functions: Access NVIC
CMSIS function Description

void NVIC_EnableIRQ (IRQn_Type IRQn) Enables an interrupt or exception.

void NVIC_DisableIRQ (IRQn_Type IRQn) Disables an interrupt or exception.

Sets the pending status of interrupt or


void NVIC_SetPendingIRQ (IRQn_Type IRQn)
exception to 1.

void NVIC_ClearPendingIRQ (IRQn_Type Clears the pending status of interrupt or


IRQn) exception to 0.

Reads the pending status of interrupt or


uint32_t NVIC_GetPendingIRQ (IRQn_Type
exception. This function returns non-zero
IRQn)
value if the pending status is set to 1.

void NVIC_SetPriority (IRQn_Type IRQn, Sets the priority of an interrupt or exception


uint32_t priority) with configurable priority level to 1.

Reads the priority of an interrupt or exception


uint32_t NVIC_GetPriority (IRQn_Type IRQn) with configurable priority level. This function
return the current priority level.

ARM University Program


Copyright © ARM Ltd 2013 12
CMSIS Functions: Access Special Registers
Special register Access CMSIS function

Read uint32_t __get_PRIMASK (void)


PRIMASK
Write void __set_PRIMASK (uint32_t value)

Read uint32_t __get_CONTROL (void)


CONTROL
Write void __set_CONTROL (uint32_t value)

Read uint32_t __get_MSP (void)


MSP
Write void __set_MSP (uint32_t TopOfMainStack)

Read uint32_t __get_PSP (void)


PSP
Write void __set_PSP (uint32_t TopOfProcStack)

ARM University Program


Copyright © ARM Ltd 2013 13
CMSIS Functions: Execute Special Instructions
Instruction CMSIS intrinsic function
CPSIE i void __enable_irq(void)
CPSID i void __disable_irq(void)
ISB void __ISB(void)
DSB void __DSB(void)
DMB void __DMB(void)
NOP void __NOP(void)
REV uint32_t __REV(uint32_t int value)
REV16 uint32_t __REV16(uint32_t int value)
REVSH uint32_t __REVSH(uint32_t int value)
SEV void __SEV(void)
WFE void __WFE(void)
WFI void __WFI(void)

ARM University Program


Copyright © ARM Ltd 2013 14
CMSIS Functions: Access System
CMSIS function Description

void NVIC_SystemReset(void) Initiate a system reset request

Initialize and start the SysTick counter and its


uint32_t SysTick_Config(uint32_t ticks)
interrupt

void SystemInit (void) Initialize the system

void SystemCoreClockUpdate(void) Update the SystemCoreClock variable

ARM University Program


Copyright © ARM Ltd 2013 15
MBED SOFTWARE
DEVELOPMENT KIT (SDK)

ARM University Program


Copyright © ARM Ltd 2013 16
What is mbed SDK
 mbed platform includes:
 A standards-based C/C++ Software Development Kit (SDK)
 A microcontroller Hardware Development Kit (HDK) and supported development boards
 Integrated Development Environment (IDE), including an online compiler and online
developer collaboration tools

 mbed Software Development Kit (SDK) includes:


 Software libraries
 Official C/C++ software libraries
Start-up code, peripheral drivers, networking, RTOS and runtime environment
 Customer-developed libraries and codes
Cookbook of hundreds of reusable peripheral and module libraries have been
built on top of the SDK, which can be used to build your projects faster
 Software tools, such as build tools, test and debug scripts

ARM University Program


Copyright © ARM Ltd 2013 17
Features of mbed SDK
 Legal – are you allowed to use mbed SDK?
 mbed SDK is licensed under the permissive Apache 2.0 licence

 All codes can be used in both commercial and personal projects with confidence

 Supported Toolchains and IDEs


 GCC ARM: GNU Tools for ARM Embedded Processors
 ARMCC (standard library and MicroLib): uVision
 IAR: IAR Embedded Workbench
 GCC code_red: Red Suite
 GCC CodeSourcery: Sourcery CodeBench

ARM University Program


Copyright © ARM Ltd 2013 18
Features of mbed SDK
 Compatible with different hardware platforms
 NXP series MCUs, including:

 Cortex-M0: LPC11U24, LPC1114, LPC11C24, LPC4330


mbed LPC1768
 Cortex-M0+: LPC810, LPC812
 Cortex-M3: LPC1768, LPC1347
 Cortex-M4: LPC4088, LPC4330
 ARM7TDMI-S: LPC2368 mbed LPC11U24

 Freescale series MCUs including:

 Cortex-M0+: KL25Z , KL05Z


 STMicroelectronics series MCUs including:

 Cortex-M4: STM32F407 Freescale KL25Z

ARM University Program


Copyright © ARM Ltd 2013 19
mbed SDK Library Structure
 The mbed SDK library provides abstractions for:
 MCU independent layer – mbed API, mbed common, and mbed HAL API

 MCU dependent layer – mbed HAL Implementation and CMSIS-CORE

 MCU hardware – MCU Registers

mbed API

mbed Common MCU independent

mbed HAL API

mbed HAL Implementation


MCU dependent
CMSIS-CORE

MCU Registers MCU hardware

ARM University Program


Copyright © ARM Ltd 2013 20
Example of mbed SDK Library Layers
 To understand how the mbed SDK library is structured and layered, we will use
the GPIO example that we have been familiar with in the previous modules

 We will explain it using a LED blinky example, which can be programmed at


different levels, using libraries from the lowest layer to the highest layer:

 MCU register layer


High-level
 Blinky example by poking registers
Control GPIO using mbed API
 CMSIS-CORE
 Blinky example using CMSIS-CORE Control GPIO using mbed HAL API
structures
 mbed HAL API GPIO mbed HAL Implementation

 Blinky example using mbed HAL API CMSIS-CORE Targeting at LPC17xx


functions
 mbed API LPC17xx GPIO Registers

 Blinky example using mbed API


functions Low-level

ARM University Program


Copyright © ARM Ltd 2013 21
MCU Register Example
 Similar as we did in the previous labs, the GPIO peripheral can be directly
accessed by writing/ reading specific memory addresses

 Assign a pointer to the address of each register

 Registers can be read / written to using the pointer

Access MCU registers directly

ARM University Program


Copyright © ARM Ltd 2013 22
CMSIS-CORE Example
 Alternatively, we have also defined a structure for the peripheral and used it to
access registers

 Similar to what we did, the CMSIS-CORE library defines a structure for accessing
the peripherals of the LPC17xx MCUs, for instance:

Data structure provided by CMSIS-CORE

ARM University Program


Copyright © ARM Ltd 2013 23
CMSIS-CORE Example
 The mbed library also provides certain additions to the CMSIS-CORE layer, such
as:
 Startup file for each of the supported Toolchains
 Linker file and support functions to define the Memory Map
 Functions to set and get Interrupt Service Routines (ISR) addresses from the Nested Vectored
Interrupt Controller (NVIC) and to program Vector Table Offset Register (VTOR)

Blink an LED using the data structure provided by CMSIS-CORE

ARM University Program


Copyright © ARM Ltd 2013 24
HAL API Example
 The Hardware Abstraction Layer (HAL) Application Programming Interface (API) is
a library layer that provides easy-to-use functions which are hardware platform
independent
 For example, the GPIO HAL API defines the following functions:

GPIO functions defined in HAL API

 The HAL API is an internal interface


 Used to help porting the mbed library to a new target and is subject to change
 If you want to "future proof" your application avoid using this API and use the mbed API
instead

ARM University Program


Copyright © ARM Ltd 2013 25
mbed API Example
 The mbed API provides the actual
user-friendly object-oriented API to
the final user

 More friendly functions/ APIs

 Object oriented API (using C++)

 Top-level API used by the


majority of the programs
developed on the mbed platform

 Define basic operators to provide


intuitive casting to primitive types
and assignments

 A digital IO class is defined as


shown in the code clip

ARM University Program


Copyright © ARM Ltd 2013 26
mbed API Example
 With the support of the mbed API, the same blinky example can be programed
in a much simpler and ,ore intuitive way:

 Note that the mbed API is programed using the object-oriented language C++,
which originated from C language with object oriented features such as classes

 Deep knowledge of C++ is not necessary to use the mbed API. However, there
is a large number of tutorials and books on C++ programming that you can avail of to
learn C++

ARM University Program


Copyright © ARM Ltd 2013 27
mbed SDK Library Directory Structure
 Three target independent directories:
 mbed/api
 The headers defining the actual mbed library API
 mbed/common
 mbed common sources
 mbed/hal
 The HAL API to be implemented for every target
 Two target dependent directories:
 mbed/targets/hal
 The HAL implementations
 mbed/targets/cmsis
 CMSIS-CORE sources

 The directory structure of the sources constituting the mbed library is published on
the official mbed github repository at:
 https://github.com/mbedmicro/mbed/tree/master/libraries

ARM University Program


Copyright © ARM Ltd 2013 28
Useful Resources
 CMSIS webpage
 http://www.arm.com/products/processors/cortex-m/cortex-microcontroller-software-
interface-standard.php

 Explore the mbed platform


 http://mbed.org/explore/

 Official mbed github repository


 https://github.com/mbedmicro/mbed/tree/master/libraries

 mbed SDK porting


 http://mbed.org/handbook/mbed-SDK-porting

 mbed library internals


 http://mbed.org/handbook/mbed-library-internals

 Book: “The Definitive Guide to the ARM Cortex-M3” by Joseph Yiu, ISBN-10:
0123854776, ISBN-13: 978-1856179638, 12 Jan 2010

ARM University Program


Copyright © ARM Ltd 2013 29

You might also like