tentang arm cmsis

21
Department of Computer Science and Electronics Fac. Of Mathematics and Natural Sciences Universitas Gadjah Mada, Yogyakarta - Indonesia

Upload: muhammadagussalim

Post on 05-Jan-2016

261 views

Category:

Documents


4 download

DESCRIPTION

MICROCONTROLLER

TRANSCRIPT

Page 1: Tentang Arm Cmsis

Department of Computer Science and Electronics

Fac. Of Mathematics and Natural Sciences

Universitas Gadjah Mada, Yogyakarta - Indonesia

Page 2: Tentang Arm Cmsis

Dr. Agfianto Eko Putra, M.Sc.

http://agfi.staff.ugm.ac.id

[email protected] [email protected]

Tentang ARM CMSIS

Page 3: Tentang Arm Cmsis

Apa itu CMSIS?

• The Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for the Cortex-M processor series and defines generic tool interfaces.

• The CMSIS...• enables consistent device support and simple software

interfaces to the processor and the peripherals, • simplifying software re-use, • reducing the learning curve for microcontroller

developers, and • reducing the time to market for new devices.

Page 4: Tentang Arm Cmsis

Cortex Microcontroller Software Interface Standard

Page 5: Tentang Arm Cmsis

Komponen2 CMSIS (1/4)

• CMSIS-CORE: API for the Cortex-M processor core and peripherals.

• It provides at standardized interface for Cortex-M0, Cortex-M3, Cortex-M4, SC000, and SC300.

• Included are also SIMD intrinsic functions for Cortex-M4 SIMD instructions.

• CMSIS-Driver: defines generic peripheral driver interfaces for middleware making it reusable across supported devices.

• The API is RTOS independent and connects microcontroller peripherals with middleware that implements for example communication stacks, file systems, or graphic user interfaces.

Page 6: Tentang Arm Cmsis

Komponen2 CMSIS (2/4)

• CMSIS-DSP: DSP Library Collection with over 60 Functions for various data types: fix-point (fractional q7, q15, q31) and single precision floating-point (32-bit). The library is available for Cortex-M0, Cortex-M3, and Cortex-M4.

• The Cortex-M4 implementation is optimized for the SIMD instruction set.

• CMSIS-RTOS API: Common API for Real-Time operating systems.

• It provides a standardized programming interface that is portable to many RTOS and enables therefore software templates, middleware, libraries, and other components that can work across supported the RTOS systems.

Page 7: Tentang Arm Cmsis

Komponen2 CMSIS (3/4)

• CMSIS-Pack: describes with a XML based package description (PDSC) file the user and device relevant parts of a file collection (called software pack) that includes source, header, and library files, documentation, Flash programming algorithms, source code templates, and example projects.

• Development tools and web infrastructures use the PDSC file to extract device parameters, software components, and evaluation board configurations.

• CMSIS-SVD: System View Description for Peripherals. • Describes the peripherals of a device in an XML file and can

be used to create peripheral awareness in debuggers or header files with peripheral register and interrupt definitions.

Page 8: Tentang Arm Cmsis

Komponen2 CMSIS (4/4)

• CMSIS-DAP: Debug Access Port. • Standardized firmware for a Debug Unit that connects to

the CoreSight Debug Access Port.

• CMSIS-DAP is distributed as separate package and well suited for integration on evaluation boards.

• This component is provided as separate download.

Page 9: Tentang Arm Cmsis

Untuk NUC100 apa yang dibutuhkan?

• NUC100.h (device header file)• Interrupt Number Definition• Device Peripheral Access Layer

• Provides definitions for all device peripherals. It contains all data structures and the address mapping for the device specific peripherals

• To define the peripherals for the actual device. It can use several other include files to define the peripherals of the actual devices

• startup_NUC100.s (startup_device assembly)• Cortex-M0 startup code and the complete Interrupt Vector Table

• system_NUC100.c (system_device)

• core_cm0.h

• core_cm0.c

ARM offer 2 files

IC Vendor Offer 3files

Page 10: Tentang Arm Cmsis

Definisi Nomor Interupsi pada NUC100typedef enum IRQn

{

/****** Cortex-M0 Processor Exceptions Numbers ***************************************************/

NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */

HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */

SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */

PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */

SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */

/****** ARMIKMCU Swift specific Interrupt Numbers ************************************************/

BOD_IRQn = 0,

WDT_IRQn = 1,

EINT0_IRQn = 2,

EINT1_IRQn = 3,

GPAB_IRQn = 4,

GPCDE_IRQn = 5,

PWM0_IRQn = 6,

PWM1_IRQn = 7,

TMR0_IRQn = 8,

TMR1_IRQn = 9,

TMR2_IRQn = 10,

TMR3_IRQn = 11,

UART0_IRQn = 12,

UART1_IRQn = 13,

SPI0_IRQn = 14,

SPI1_IRQn = 15,

SPI2_IRQn = 16,

SPI3_IRQn = 17,

I2C0_IRQn = 18,

I2C1_IRQn = 19,

CAN0_IRQn = 20,

CAN1_IRQn = 21,

SD_IRQn = 22,

USBD_IRQn = 23,

PS2_IRQn = 24,

ACMP_IRQn = 25,

PDMA_IRQn = 26,

I2S_IRQn = 27,

PWRWU_IRQn = 28,

ADC_IRQn = 29,

DAC_IRQn = 30,

RTC_IRQn = 31

} IRQn_Type;

The interrupt number is defined in

the “NUC1xx.h” file

Page 11: Tentang Arm Cmsis

startup_NUC100Series.s (1/2)

_Vectors DCD __initial_sp ; Top of Stack

DCD Reset_Handler ; Reset Handler

DCD NMI_Handler ; NMI Handler

DCD HardFault_Handler ; Hard Fault Handler

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD SVC_Handler ; SVCall Handler

DCD 0 ; Reserved

DCD 0 ; Reserved

DCD PendSV_Handler ; PendSV Handler

DCD SysTick_Handler ; SysTick Handler

These exception names

are fixed and define the

start of the vector table

for a Cortex-M0

Page 12: Tentang Arm Cmsis

startup_NUC100Series.s (2/2); External Interrupts

DCD BOD_IRQHandler

DCD WDT_IRQHandler

DCD EINT0_IRQHandler

DCD EINT1_IRQHandler

DCD GPAB_IRQHandler

DCD GPCDE_IRQHandler

DCD PWMA_IRQHandler

DCD PWMB_IRQHandler

DCD TMR0_IRQHandler

DCD TMR1_IRQHandler

DCD TMR2_IRQHandler

DCD TMR3_IRQHandler

DCD UART02_IRQHandler

DCD UART1_IRQHandler

DCD SPI0_IRQHandler

DCD SPI1_IRQHandler

DCD SPI2_IRQHandler

DCD SPI3_IRQHandler

DCD I2C0_IRQHandler

DCD I2C1_IRQHandler

DCD CAN0_IRQHandler

DCD Default_Handler

DCD Default_Handler

DCD USBD_IRQHandler

DCD PS2_IRQHandler

DCD ACMP_IRQHandler

DCD PDMA_IRQHandler

DCD I2S_IRQHandler

DCD PWRWU_IRQHandler

DCD ADC_IRQHandler

DCD Default_Handler

DCD RTC_IRQHandler

These interrupt names are

fixed and define the start of the

vector table for a Cortex-M0

Page 13: Tentang Arm Cmsis

PWRCON Register (Structure Bit Field SYSCLK_PWRCON_T Data Type)

/*---------------------------- Clock Controller ------------------------------*/

typedef struct

{

__IO uint32_t XTL12M_EN:1;

__IO uint32_t XTL32K_EN:1;

__IO uint32_t OSC22M_EN:1;

__IO uint32_t OSC10K_EN:1;

__IO uint32_t WU_DLY:1;

__IO uint32_t WINT_EN:1;

__IO uint32_t INTSTS:1;

__IO uint32_t PWR_DOWN:1;

__IO uint32_t PD_WAIT_CPU:1;

__I uint32_t RESERVE:23;

} SYSCLK_PWRCON_T;

31 30 29 28 27 26 25 24

RESERVED

23 22 21 20 19 18 17 16

RESERVED

15 14 13 12 11 10 9 8

PD_WAIT_CPU

7 6 5 4 3 2 1 0

PWR_DOWN PD_WU_STS WINT_EN WU_DLY OSC10K_EN OSC22M_EN XTL32K_EN XTL12M_EN

LSB

MSB

New Data Type

Page 14: Tentang Arm Cmsis

Group Registers for fixed CLK_BA BaseAddr (SYSCLK_T Data Type)

Register Offset

PWRCON CLK_BA + 00

AHBCLK CLK_BA + 04

APBCLK CLK_BA + 08

CLKSEL0 CLK_BA + 10

CLKSEL1 CLK_BA + 14

CLKSEL2 CLK_BA + 1C

CLKDIV CLK_BA_+ 18

PLLCON CLK_BA + 20

FRQDIV GCR_BA + 24

typedef struct

{

SYSCLK_PWRCON_T PWRCON;

SYSCLK_AHBCLK_T AHBCLK;

SYSCLK_APBCLK_T APBCLK;

uint32_t RESERVED;

SYSCLK_CLKSEL0_T CLKSEL0;

SYSCLK_CLKSEL1_T CLKSEL1;

SYSCLK_CLKDIV_T CLKDIV;

uint32_t RESERVED2;

SYSCLK_PLLCON_T PLLCON;

uint32_t RESERVED3[3];

SYSCLK_TREG_T TREG;

} SYSCLK_T;

Page 15: Tentang Arm Cmsis

Untuk mengakses register...

#define AHB_BASE 0x50000000

#define SYSCLK_BASE (AHB_BASE + 0x00200)

#define SYSCLK ((SYSCLK_T *) SYSCLK_BASE)

AHB Modules Space (0x5000_0000 – 0x501F_FFFF)

0x5000_0000 – 0x5000_01FF GCR_BA System Global Control Registers

0x5000_0200 – 0x5000_02FF CLK_BA Clock Control Registers

0x5000_0300 – 0x5000_03FF INT_BA Interrupt Multiplexer Control Registers

0x5000_4000 – 0x5000_7FFF GPIO_BA GPIO Control Registers

0x5000_8000 – 0x5000_BFFF PDMA_BA SRAM_APB DMA Control Registers

0x5000_C000 – 0x5000_FFFF FMC_BA Flash Memory Control Registers

SYSCLK->PWRCON.XTL12M_EN = 1;

Page 16: Tentang Arm Cmsis

Cortex-M0 Core Registers Access (core_cm0.h)

Function Definition Core Register Description

void __enable_irq (void) PRIMASK = 0 Global Interrupt enable (using the instruction CPSIE i)

void __disable_irq (void) PRIMASK = 1 Global Interrupt disable (using the instruction CPSID i)

void __set_PRIMASK (uint32_t

value)

PRIMASK = value Assign value to Priority Mask Register (using the instruction MSR)

uint32_t __get_PRIMASK

(void)

return PRIMASK Return Priority Mask Register (using the instruction MRS)

void __set_CONTROL

(uint32_t value)

CONTROL = value Set CONTROL register value (using the instruction MSR)

uint32_t __get_CONTROL

(void)

return CONTROL Return Control Register Value (using the instruction MRS)

void __set_PSP (uint32_t

TopOfProcStack)

PSP =

TopOfProcStack

Set Process Stack Pointer value (using the instruction MSR)

uint32_t __get_PSP (void) return PSP Return Process Stack Pointer (using the instruction MRS)

void __set_MSP (uint32_t

TopOfMainStack)

MSP =

TopOfMainStack

Set Main Stack Pointer (using the instruction MSR)

uint32_t __get_MSP (void) return MSP Return Main Stack Pointer (using the instruction MRS)

Page 17: Tentang Arm Cmsis

Cortex-M0 Instruction Access

Function Name CPU Instruction Description

void __WFI (void) WFI Wait for Interrupt

void __WFE (void) WFE Wait for Event

void __SEV (void) SEV Set Event

void __ISB (void) ISB Instruction Synchronization Barrier

void __DSB (void) DSB Data Synchronization Barrier

void __DMB (void) DMB Data Memory Barrier

uint32_t __REV (uint32_t value) REV Reverse byte order in integer value.

uint32_t __REV16 (uint16_t value) REV16 Reverse byte order in unsigned short

value.

sint32_t __REVSH (sint16_t value) REVSH Reverse byte order in signed short

value with sign extension to integer.

Page 18: Tentang Arm Cmsis

NVIC Setup Function CallFunction Name Parameter Description

void NVIC_SetPriorityGrouping (uint32_t

PriorityGroup)

Priority Grouping Value Set the Priority Grouping (Groups .

Subgroups)

void NVIC_EnableIRQ (IRQn_Type IRQn) IRQ Number Enable IRQn

void NVIC_DisableIRQ (IRQn_Type IRQn) IRQ Number Disable IRQn

uint32_t NVIC_GetPendingIRQ (IRQn_Type

IRQn)

IRQ Number Return 1 if IRQn is pending else 0

void NVIC_SetPendingIRQ (IRQn_Type IRQn) IRQ Number Set IRQn Pending

void NVIC_ClearPendingIRQ (IRQn_Type IRQn) IRQ Number Clear IRQn Pending Status

void NVIC_SetPriority (IRQn_Type IRQn,

uint32_t priority)

IRQ Number, Priority Set Priority for IRQn

uint32_t NVIC_GetPriority (IRQn_Type IRQn) IRQ Number Get Priority for IRQn

uint32_t NVIC_EncodePriority (uint32_t

PriorityGroup, uint32_t PreemptPriority,

uint32_t SubPriority)

IRQ Number, Priority Group,

Preemptive Priority,

Sub Priority

Encode priority for given group,

preemptive and sub priority

NVIC_DecodePriority (uint32_t Priority, uint32_t

PriorityGroup, uint32_t* pPreemptPriority,

uint32_t* pSubPriority)

IRQ Number, Priority,

pointer to Priority

Group, pointer to

Preemptive Priority,

pointer to Sub Priority

Decode given priority to group,

preemptive and sub priority

void NVIC_SystemReset (void) (void) Resets the System

Page 19: Tentang Arm Cmsis

Memory Map defined in NUC100Series.h

/* Peripheral and SRAM base address */#define FLASH_BASE (( uint32_t)0x00000000)#define SRAM_BASE (( uint32_t)0x20000000)#define AHB_BASE (( uint32_t)0x50000000)#define APB1_BASE (( uint32_t)0x40000000)#define APB2_BASE (( uint32_t)0x40100000)

/* Peripheral memory map */#define GPIO_BASE (AHB_BASE + 0x4000)

#define GPIOA_BASE (GPIO_BASE )#define GPIOB_BASE (GPIO_BASE + 0x0040)#define GPIOC_BASE (GPIO_BASE + 0x0080)#define GPIOD_BASE (GPIO_BASE + 0x00C0)#define GPIOE_BASE (GPIO_BASE + 0x0100)#define GPIO_DBNCECON_BASE (GPIO_BASE + 0x0180)

#define UART0_BASE (APB1_BASE + 0x50000)#define UART1_BASE (APB2_BASE + 0x50000)#define UART2_BASE (APB2_BASE + 0x54000)

#define TIMER0_BASE (APB1_BASE + 0x10000)

#define TIMER1_BASE (APB1_BASE + 0x10020)

#define TIMER2_BASE (APB2_BASE + 0x10000)

#define TIMER3_BASE (APB2_BASE + 0x10020)

#define WDT_BASE (APB1_BASE + 0x4000)

#define SPI0_BASE (APB1_BASE + 0x30000)

#define SPI1_BASE (APB1_BASE + 0x34000)

#define SPI2_BASE (APB2_BASE + 0x30000)

#define SPI3_BASE (APB2_BASE + 0x34000)

#define I2C0_BASE (APB1_BASE + 0x20000)

#define I2C1_BASE (APB2_BASE + 0x20000)

#define RTC_BASE (APB1_BASE + 0x08000)

#define ADC_BASE (APB1_BASE + 0xE0000)

#define ACMP_BASE (APB1_BASE + 0xD0000)

#define SYSCLK_BASE (AHB_BASE + 0x00200)

#define GCR_BASE (AHB_BASE + 0x00000)

#define INT_BASE (AHB_BASE + 0x00300)

#define FMC_BASE (AHB_BASE + 0x0C000)

#define PS2_BASE (APB2_BASE + 0x00000)

#define CAN0_BASE (APB2_BASE + 0x80000)

#define CAN1_BASE (APB2_BASE + 0x84000)

#define C_CAN_BASE (APB2_BASE + 0x88000)

Page 20: Tentang Arm Cmsis

Peripheral Name define its Base Address

#define GPIOA ((GPIO_T *) GPIOA_BASE)#define GPIOB ((GPIO_T *) GPIOB_BASE)#define GPIOC ((GPIO_T *) GPIOC_BASE)#define GPIOD ((GPIO_T *) GPIOD_BASE)#define GPIOE ((GPIO_T *) GPIOE_BASE)#define GPIO_DBNCECON ((GPIO_DBNCECON_T *) GPIO_DBNCECON_BASE)#define GPIO_BIT_ADDR_BASE (GPIO_BASE + 0x200)

#define UART0 ((UART_T *) UART0_BASE)#define UART1 ((UART_T *) UART1_BASE)#define UART2 ((UART_T *) UART2_BASE)#define TIMER0 ((TIMER_T *) TIMER0_BASE)#define TIMER1 ((TIMER_T *) TIMER1_BASE)#define TIMER2 ((TIMER_T *) TIMER2_BASE)#define TIMER3 ((TIMER_T *) TIMER3_BASE)#define WDT ((WDT_T *) WDT_BASE)#define SPI0 ((SPI_T *) SPI0_BASE)#define SPI1 ((SPI_T *) SPI1_BASE)#define SPI2 ((SPI_T *) SPI2_BASE)#define SPI3 ((SPI_T *) SPI3_BASE)

#define I2C0 ((I2C_T *) I2C0_BASE)

#define I2C1 ((I2C_T *) I2C1_BASE)

#define I2S ((I2S_T *) I2S_BASE)

#define RTC ((RTC_T *) RTC_BASE)

#define ADC ((ADC_T *) ADC_BASE)

#define ACMP ((ACMP_T *) ACMP_BASE)

#define SYSCLK ((SYSCLK_T *) SYSCLK_BASE)

#define SYS ((GCR_T *) GCR_BASE)

#define SYSINT ((GCR_INT_T *) INT_BASE)

#define FMC ((FMC_T *) FMC_BASE)

#define PS2 ((PS2_T *) PS2_BASE)

#define CAN ((CAN_T *) CAN0_BASE)

#define USBD ((USBD_T *) USBD_BASE))

Page 21: Tentang Arm Cmsis