SlideShare a Scribd company logo
© 2017 Arm Limited
Arm CMSIS and
Software Drivers
© 2017 Arm Limited
2
Module Syllabus
The Cortex Microcontroller Software Interface Standard (CMSIS)
Design and Implementation of Standard Low-level Software Drivers for Peripherals
© 2017 Arm Limited
3
Building a System on a Chip (SoC)
Memory
VGA
Peripheral
UART
Peripheral
Timer
Peripheral
GPIO
Peripheral
7-Segment
Peripheral
Arm CMSIS-Core
Application Programming Interface (API)
Application Design (e.g., Game)
Arm Cortex-M0
Processor
Hardware design
Software low-level drivers
& libraries programming
Software high-level
application development
Peripheral Drivers
AHB
Interrupt
© 2017 Arm Limited
4
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 that can help us control the processor
easily; e.g., configuring the nested vectored interrupt controller (NVIC).
• Main function is to improve the software portability between different Cortex-M serial processors and
microcontrollers
Arm CMSIS-Core
Arm Cortex-M0
Processor
Cortex-M0
Cortex-M3
Cortex-M4
Cortex-M
Configure Cortex-M0 by directly accessing its
registers in its internal memory space,
e.g., *(unsigned int*) NVIC_INT_ENABLE = 0x01;
Configure Cortex-M serial processors
by using CMSIS libraries,
e.g., NVIC_EnableIRQ(Timer_IRQn);
© 2017 Arm Limited
5
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; for example:
• REV: uint32_t __REV(uint32_t int value)
• NOP: void __NOP(void)
Standardized name of system initialization functions; for example:
• System initialization: void SystemInit(void)
© 2017 Arm Limited
6
CMSIS Components
The CMSIS consists of the following components:
• CMSIS-CORE
• CMSIS-DSP, CMSIS-RTOS API, and CMSIS-SVD
This course focuses on CMSIS-CORE.
© 2017 Arm Limited
7
Access NVIC Using CMSIS
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
void NVIC_SetPendingIRQ (IRQn_Type IRQn) Sets the pending status of interrupt or exception to 1
void NVIC_ClearPendingIRQ (IRQn_Type IRQn) Clears the pending status of interrupt or exception to 0
uint32_t NVIC_GetPendingIRQ (IRQn_Type IRQn)
Reads the pending status of interrupt or exception. This function
returns a non-zero value if the pending status is set to 1.
void NVIC_SetPriority (IRQn_Type IRQn, uint32_t priority)
Sets the priority of an interrupt or exception with configurable
priority level to 1
uint32_t NVIC_GetPriority (IRQn_Type IRQn)
Reads the priority of an interrupt or exception with configurable
priority level. This function returns the current priority level.
© 2017 Arm Limited
8
Access Special Registers Using CMSIS
Special register Access CMSIS function
PRIMASK
Read uint32_t __get_PRIMASK (void)
Write void __set_PRIMASK (uint32_t value)
CONTROL
Read uint32_t __get_CONTROL (void)
Write void __set_CONTROL (uint32_t value)
MSP
Read uint32_t __get_MSP (void)
Write void __set_MSP (uint32_t TopOfMainStack)
PSP
Read uint32_t __get_PSP (void)
Write void __set_PSP (uint32_t TopOfProcStack)
© 2017 Arm Limited
9
Execute Special Instructions Using CMSIS
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)
© 2017 Arm Limited
10
Access System Using CMSIS
CMSIS function Description
void NVIC_SystemReset(void) Initiate a system reset request.
uint32_t SysTick_Config(uint32_t ticks) Initialize and start the SysTick counter and its interrupt.
void SystemInit (void) Initialize the system.
void SystemCoreClockUpdate(void) Update the SystemCoreClock variable.
© 2017 Arm Limited
11
Benefits of CMSIS
Easier to port application code from one Cortex-M microcontroller to another Cortex-M
microcontroller
Less effort to reuse the same code between different Cortex-M-based microcontrollers
Better compatibility when integrating third-party software components; applications,
embedded OS, middleware, etc., can share the standard CMSIS interface
Better code density and smaller memory footprint, since the codes in CMSIS have been
tested and optimized
© 2017 Arm Limited
12
Device Driver
What is a device driver?
• The software program used to control a particular hardware peripheral
What is the purpose of drivers?
• Providing a simplified, easy-to-use interface for application developers
Video driver Mouse driver
Memory driver
Audio driver
Source: https://en.wikipedia.org/wiki/Device_driver
© 2017 Arm Limited
13
Device Driver
In OS development, drivers are normally low level components that directly interface with
physical devices.
The development of drivers commonly involves both the physical device vendors (physical
level) and the OS vendors (logical level).
Most drivers can provide generic functions that allow developers to write higher-level
applications independently from specific hardware.
Video Driver Audio Driver Memory Driver Mouse Driver
OS Kernel
OS Shell
User Application
Low-level
Programming
High-level
Programming
© 2017 Arm Limited
14
AHB Peripheral Drivers
In this course:
• We will write the software driver for each peripheral (except memory controller).
• No OS is required.
• Software drivers should provide basic functions to ease the access to peripherals.
VGA
Peripheral
UART
Peripheral
Timer
Peripheral
GPIO
Peripheral
7-Segment
Peripheral
VGA
Software Driver
UART
Software Driver
Timer
Software Driver
GPIO
Software Driver
7-Segment
Software Driver
Functions to access peripherals
© 2017 Arm Limited
15
Using Pointer to Access Peripherals
Peripherals and their registers are mapped to the global memory space; hence, they can
be accessed using memory pointers.
#define AHB_TIMER_BASE 0x52000000
#define AHB_TIMER_INITVALUE (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x00)))
#define AHB_TIMER_CURVALUE (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x04)))
#define AHB_TIMER_CONTROL (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x08)))
#define AHB_TIMER_CLEAR (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x0C)))
// timer initialization function
void timer_init (int value, int control) {
AHB_TIMER_INITVALUE = value;
AHB_TIMER_CONTROL = control;
AHB_TIMER_CLEAR = 0;
}
© 2017 Arm Limited
16
Define Data Structure for Peripherals
To further simplify the code and reduce code length, we can:
• Define the peripheral register set as a data structure.
• Define the peripheral as a memory pointer to this data structure.
typedef struct {
volatile unsigned int INITVALUE;
volatile unsigned int CURVALUE;
volatile unsigned int CONTROL;
volatile unsigned int CLEAR;
} TIMER_TypeDef;
#define AHB_TIMER_BASE 0x52000000
#define TIMER ((TIMER_TypeDef *) AHB_TIMER_BASE )
void timer_init (int value, int control) {
TIMER->INITVALUE = value;
TIMER->CONTROL = control;
TIMER-> CLEAR = 0;
}
© 2017 Arm Limited
17
Functions Reuse Between Multiple Units
For example, the same function can be reused by passing different base pointers:
typedef struct {
volatile unsigned int INITVALUE;
volatile unsigned int CURVALUE;
volatile unsigned int CONTROL;
volatile unsigned int CLEAR;
} TIMER_TypeDef;
#define AHB_TIMER0_BASE 0x52000000
#define AHB_TIMER1_BASE 0x52100000
#define TIMER0 ((TIMER_TypeDef *) AHB_TIMER0_BASE )
#define TIMER1 ((TIMER_TypeDef *) AHB_TIMER1_BASE )
void timer_init (TIMER_TypeDef *timer_pointer) {
timer_pointer >INITVALUE = value;
timer_pointer >CONTROL = control;
timer_pointer > CLEAR = 0;
}
© 2017 Arm Limited
18
Define AHB Peripherals
Now we can define all the AHB peripherals in the device header file (e.g., edk_cm0.h)
using the same standard format:
#define AHB_VGA_BASE 0x51000000
#define AHB_UART_BASE 0x52000000
#define AHB_TIMER_BASE 0x52000000
#define AHB_GPIO_BASE 0x53000000
#define AHB_7SEG_BASE 0x54000000
typedef struct{
…
} VGA_TypeDef;
typedef struct{
…
} UART_TypeDef;
…
#define VGA ((VGA_TypeDef *) AHB_VGA_BASE )
#define UART ((UART_TypeDef *) AHB_UART_BASE )
#define TIMER ((TIMER_TypeDef *) AHB_TIMER_BASE )
#define GPIO ((GPIO_TypeDef *) AHB_GPIO_BASE )
#define SEVSEG ((SEVENSEG_TypeDef *) AHB_7SEG_BASE )
© 2017 Arm Limited
19
Examples of Simple Functions
Peripheral Function Description
VGA void VGA_plot_pixel (int x, int y, int col); Plot a pixel in the image region.
7-segment display
void seven_seg_write(char dig1, char dig2,char
dig3,char dig4);
Write four digits on the 7-segment display.
Timer
void timer_init (int load_value, int prescale, int
mode);
Initialize the timer.
void timer_enable(void); Enable the timer.
void timer_irq_clear(void); Clear interrupt request from the timer.
GPIO
int GPIO_read(void) Return with the value read from the input port.
void GPIO_write(int data) Write a value to the GPIO output.

More Related Content

PPTX
unit 5.pptx
PPTX
Mces MOD 1.pptx
PDF
Arm based controller - basic bootcamp
PDF
Lecture Presentation 9.pdf fpga soc using c
PDF
Chapter_2_Embedded Systems Design_introduction_ARM.pdf
PPTX
PDF
Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc
PPT
12429908.ppt
unit 5.pptx
Mces MOD 1.pptx
Arm based controller - basic bootcamp
Lecture Presentation 9.pdf fpga soc using c
Chapter_2_Embedded Systems Design_introduction_ARM.pdf
Lecture Presentation 11.pdfLecture Presentation 9.pdf fpga soc
12429908.ppt

Similar to Lecture Presentation 10.pdfLecture Presentation 10.pdf (20)

ODP
STM32 Peripheral Drivers
PDF
Lecture Presentation 7 timer , gpio , 7 segment
PPTX
Embedded Systems Overview
PPT
Computer function-and-interconnection 3
PPT
Computer function-and-interconnection 3
PPTX
ESD Presenation.pptx All about embeded system
PDF
Expanding The Micro Blaze System
PPTX
The primary purpose of memory interfacing is to facilitate the transfer of da...
PDF
PILOT Session for Embedded Systems
PPT
lecture1-244.ppt
PDF
Creating an Embedded System Lab
PPT
Ch_3.pptInnovation technology Innovation technology pptppt
PPTX
ARM Cortex-M3 Training
PPTX
IO hardware
PDF
Blackfin Device Drivers
PDF
15CS44 MP & MC Module 4
PPTX
8259 Programmable Interrupt Controller.pptx
PPTX
Module-3 ADVANCED MICROCONTROLLER IMP.pptx
PPTX
3_Arch_and_Kernels_for_computer_systems.pptx
PPTX
Introduction to embedded System.pptx
STM32 Peripheral Drivers
Lecture Presentation 7 timer , gpio , 7 segment
Embedded Systems Overview
Computer function-and-interconnection 3
Computer function-and-interconnection 3
ESD Presenation.pptx All about embeded system
Expanding The Micro Blaze System
The primary purpose of memory interfacing is to facilitate the transfer of da...
PILOT Session for Embedded Systems
lecture1-244.ppt
Creating an Embedded System Lab
Ch_3.pptInnovation technology Innovation technology pptppt
ARM Cortex-M3 Training
IO hardware
Blackfin Device Drivers
15CS44 MP & MC Module 4
8259 Programmable Interrupt Controller.pptx
Module-3 ADVANCED MICROCONTROLLER IMP.pptx
3_Arch_and_Kernels_for_computer_systems.pptx
Introduction to embedded System.pptx
Ad

Recently uploaded (20)

PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Construction Project Organization Group 2.pptx
PDF
composite construction of structures.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Welding lecture in detail for understanding
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Geodesy 1.pptx...............................................
DOCX
573137875-Attendance-Management-System-original
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
Mechanical Engineering MATERIALS Selection
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Construction Project Organization Group 2.pptx
composite construction of structures.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
Structs to JSON How Go Powers REST APIs.pdf
Foundation to blockchain - A guide to Blockchain Tech
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
bas. eng. economics group 4 presentation 1.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Lesson 3_Tessellation.pptx finite Mathematics
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Welding lecture in detail for understanding
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Geodesy 1.pptx...............................................
573137875-Attendance-Management-System-original
UNIT 4 Total Quality Management .pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Mechanical Engineering MATERIALS Selection
Ad

Lecture Presentation 10.pdfLecture Presentation 10.pdf

  • 1. © 2017 Arm Limited Arm CMSIS and Software Drivers
  • 2. © 2017 Arm Limited 2 Module Syllabus The Cortex Microcontroller Software Interface Standard (CMSIS) Design and Implementation of Standard Low-level Software Drivers for Peripherals
  • 3. © 2017 Arm Limited 3 Building a System on a Chip (SoC) Memory VGA Peripheral UART Peripheral Timer Peripheral GPIO Peripheral 7-Segment Peripheral Arm CMSIS-Core Application Programming Interface (API) Application Design (e.g., Game) Arm Cortex-M0 Processor Hardware design Software low-level drivers & libraries programming Software high-level application development Peripheral Drivers AHB Interrupt
  • 4. © 2017 Arm Limited 4 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 that can help us control the processor easily; e.g., configuring the nested vectored interrupt controller (NVIC). • Main function is to improve the software portability between different Cortex-M serial processors and microcontrollers Arm CMSIS-Core Arm Cortex-M0 Processor Cortex-M0 Cortex-M3 Cortex-M4 Cortex-M Configure Cortex-M0 by directly accessing its registers in its internal memory space, e.g., *(unsigned int*) NVIC_INT_ENABLE = 0x01; Configure Cortex-M serial processors by using CMSIS libraries, e.g., NVIC_EnableIRQ(Timer_IRQn);
  • 5. © 2017 Arm Limited 5 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; for example: • REV: uint32_t __REV(uint32_t int value) • NOP: void __NOP(void) Standardized name of system initialization functions; for example: • System initialization: void SystemInit(void)
  • 6. © 2017 Arm Limited 6 CMSIS Components The CMSIS consists of the following components: • CMSIS-CORE • CMSIS-DSP, CMSIS-RTOS API, and CMSIS-SVD This course focuses on CMSIS-CORE.
  • 7. © 2017 Arm Limited 7 Access NVIC Using CMSIS 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 void NVIC_SetPendingIRQ (IRQn_Type IRQn) Sets the pending status of interrupt or exception to 1 void NVIC_ClearPendingIRQ (IRQn_Type IRQn) Clears the pending status of interrupt or exception to 0 uint32_t NVIC_GetPendingIRQ (IRQn_Type IRQn) Reads the pending status of interrupt or exception. This function returns a non-zero value if the pending status is set to 1. void NVIC_SetPriority (IRQn_Type IRQn, uint32_t priority) Sets the priority of an interrupt or exception with configurable priority level to 1 uint32_t NVIC_GetPriority (IRQn_Type IRQn) Reads the priority of an interrupt or exception with configurable priority level. This function returns the current priority level.
  • 8. © 2017 Arm Limited 8 Access Special Registers Using CMSIS Special register Access CMSIS function PRIMASK Read uint32_t __get_PRIMASK (void) Write void __set_PRIMASK (uint32_t value) CONTROL Read uint32_t __get_CONTROL (void) Write void __set_CONTROL (uint32_t value) MSP Read uint32_t __get_MSP (void) Write void __set_MSP (uint32_t TopOfMainStack) PSP Read uint32_t __get_PSP (void) Write void __set_PSP (uint32_t TopOfProcStack)
  • 9. © 2017 Arm Limited 9 Execute Special Instructions Using CMSIS 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)
  • 10. © 2017 Arm Limited 10 Access System Using CMSIS CMSIS function Description void NVIC_SystemReset(void) Initiate a system reset request. uint32_t SysTick_Config(uint32_t ticks) Initialize and start the SysTick counter and its interrupt. void SystemInit (void) Initialize the system. void SystemCoreClockUpdate(void) Update the SystemCoreClock variable.
  • 11. © 2017 Arm Limited 11 Benefits of CMSIS Easier to port application code from one Cortex-M microcontroller to another Cortex-M microcontroller Less effort to reuse the same code between different Cortex-M-based microcontrollers Better compatibility when integrating third-party software components; applications, embedded OS, middleware, etc., can share the standard CMSIS interface Better code density and smaller memory footprint, since the codes in CMSIS have been tested and optimized
  • 12. © 2017 Arm Limited 12 Device Driver What is a device driver? • The software program used to control a particular hardware peripheral What is the purpose of drivers? • Providing a simplified, easy-to-use interface for application developers Video driver Mouse driver Memory driver Audio driver Source: https://en.wikipedia.org/wiki/Device_driver
  • 13. © 2017 Arm Limited 13 Device Driver In OS development, drivers are normally low level components that directly interface with physical devices. The development of drivers commonly involves both the physical device vendors (physical level) and the OS vendors (logical level). Most drivers can provide generic functions that allow developers to write higher-level applications independently from specific hardware. Video Driver Audio Driver Memory Driver Mouse Driver OS Kernel OS Shell User Application Low-level Programming High-level Programming
  • 14. © 2017 Arm Limited 14 AHB Peripheral Drivers In this course: • We will write the software driver for each peripheral (except memory controller). • No OS is required. • Software drivers should provide basic functions to ease the access to peripherals. VGA Peripheral UART Peripheral Timer Peripheral GPIO Peripheral 7-Segment Peripheral VGA Software Driver UART Software Driver Timer Software Driver GPIO Software Driver 7-Segment Software Driver Functions to access peripherals
  • 15. © 2017 Arm Limited 15 Using Pointer to Access Peripherals Peripherals and their registers are mapped to the global memory space; hence, they can be accessed using memory pointers. #define AHB_TIMER_BASE 0x52000000 #define AHB_TIMER_INITVALUE (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x00))) #define AHB_TIMER_CURVALUE (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x04))) #define AHB_TIMER_CONTROL (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x08))) #define AHB_TIMER_CLEAR (*((volatile unsigned long *)(AHB_TIMER_BASE + 0x0C))) // timer initialization function void timer_init (int value, int control) { AHB_TIMER_INITVALUE = value; AHB_TIMER_CONTROL = control; AHB_TIMER_CLEAR = 0; }
  • 16. © 2017 Arm Limited 16 Define Data Structure for Peripherals To further simplify the code and reduce code length, we can: • Define the peripheral register set as a data structure. • Define the peripheral as a memory pointer to this data structure. typedef struct { volatile unsigned int INITVALUE; volatile unsigned int CURVALUE; volatile unsigned int CONTROL; volatile unsigned int CLEAR; } TIMER_TypeDef; #define AHB_TIMER_BASE 0x52000000 #define TIMER ((TIMER_TypeDef *) AHB_TIMER_BASE ) void timer_init (int value, int control) { TIMER->INITVALUE = value; TIMER->CONTROL = control; TIMER-> CLEAR = 0; }
  • 17. © 2017 Arm Limited 17 Functions Reuse Between Multiple Units For example, the same function can be reused by passing different base pointers: typedef struct { volatile unsigned int INITVALUE; volatile unsigned int CURVALUE; volatile unsigned int CONTROL; volatile unsigned int CLEAR; } TIMER_TypeDef; #define AHB_TIMER0_BASE 0x52000000 #define AHB_TIMER1_BASE 0x52100000 #define TIMER0 ((TIMER_TypeDef *) AHB_TIMER0_BASE ) #define TIMER1 ((TIMER_TypeDef *) AHB_TIMER1_BASE ) void timer_init (TIMER_TypeDef *timer_pointer) { timer_pointer >INITVALUE = value; timer_pointer >CONTROL = control; timer_pointer > CLEAR = 0; }
  • 18. © 2017 Arm Limited 18 Define AHB Peripherals Now we can define all the AHB peripherals in the device header file (e.g., edk_cm0.h) using the same standard format: #define AHB_VGA_BASE 0x51000000 #define AHB_UART_BASE 0x52000000 #define AHB_TIMER_BASE 0x52000000 #define AHB_GPIO_BASE 0x53000000 #define AHB_7SEG_BASE 0x54000000 typedef struct{ … } VGA_TypeDef; typedef struct{ … } UART_TypeDef; … #define VGA ((VGA_TypeDef *) AHB_VGA_BASE ) #define UART ((UART_TypeDef *) AHB_UART_BASE ) #define TIMER ((TIMER_TypeDef *) AHB_TIMER_BASE ) #define GPIO ((GPIO_TypeDef *) AHB_GPIO_BASE ) #define SEVSEG ((SEVENSEG_TypeDef *) AHB_7SEG_BASE )
  • 19. © 2017 Arm Limited 19 Examples of Simple Functions Peripheral Function Description VGA void VGA_plot_pixel (int x, int y, int col); Plot a pixel in the image region. 7-segment display void seven_seg_write(char dig1, char dig2,char dig3,char dig4); Write four digits on the 7-segment display. Timer void timer_init (int load_value, int prescale, int mode); Initialize the timer. void timer_enable(void); Enable the timer. void timer_irq_clear(void); Clear interrupt request from the timer. GPIO int GPIO_read(void) Return with the value read from the input port. void GPIO_write(int data) Write a value to the GPIO output.