Migration From Microchip to ARM Cortex

39
1 Migration from Microchip PIC18/PIC24 to ARM Cortex Microcontrollers Bryan Lawrence - Solutions Marketing Manager Richard York - Director of Product Marketing

Transcript of Migration From Microchip to ARM Cortex

Page 1: Migration From Microchip to ARM Cortex

1

Migration from MicrochipPIC18/PIC24 to ARM

Cortex Microcontrollers

Bryan Lawrence - Solutions Marketing Manager

Richard York - Director of Product Marketing

Page 2: Migration From Microchip to ARM Cortex

2

Today’s Presenters

About Richard York

Richard is director of product marketing in the ARM processor division

with responsibility for the team marketing the ARM embedded and

microcontroller CPU products including the Cortex-M and Cortex-R

series. He is also responsible for the overall embedded roadmap for

these products and also for specialised derivatives such as the ARM

SecurCore processor family. He has worked at ARM for over fourteen

years, during which time he has been closely involved with the design

of ARM7TDMI core and was an architect in ARM’s advanced research

and development group. He is also the principal architect of the ARM

RealTrace debug system.

About Bryan Lawrence

Bryan Lawrence currently runs a team of Solutions Architects who

demonstrate and promote the integration of ARM IP into large SOC

devices required by an application. For the past two years he has had

a particular focus on microcontroller applications and the use of 32bit

processing in this market. He has worked for ARM for 8 years and was

the product manager for the system level design product ; PrimeXsys

and was a system design consultant within ARM working with silicon

partners who were designing ARM based ASICs.

Before joining ARM Bryan was a project manager with VLSI

Technology designing ARM processors into mobile phone devices.

Page 3: Migration From Microchip to ARM Cortex

3

Agenda

Part 1 – Introduction

Part 2 – Hardware Overview

Part 3 – Software Overview

Part 4 – Tools and debug

Part 5 – Getting Started

Page 4: Migration From Microchip to ARM Cortex

4

Touch screen controller

Accelerometer

GPS / Bluetooth

Battery monitor

Joystick/touchpad controller

Introduction

PIC microcontrollers can certainly handle some embeddedapplications

They work and are fairly affordable but …

limited memory, fairly low performance

Many architectural limitations that make code reuse difficult

hardware stack, inefficient indirect addressing and so on

Page 5: Migration From Microchip to ARM Cortex

5

Introduction

Why ARM Cortex Microcontrollers?

Multiple vendors – much more choice

Very low power

Very easy to use (completely programmable in C)

Excellent software development support

Much more performance available if you need it

In many cases cheaper! (now as low as 65 cents)*

*

*

Page 6: Migration From Microchip to ARM Cortex

6

ARM Founded 27th Nov 1990

A barn, some energy, experience and belief:“We’re going to be the Global Standard”

Originally 12 employees, now >1,700

IP (Intellectual Property) company

we design and license processor technologyto chip vendors – Semiconductor Partners

Focus on low power and energy efficiency

Two decades of Partnership success

memorymemory

SoCSoC

Page 7: Migration From Microchip to ARM Cortex

7

The ARM Business Model

ARM enables chip manufacturers to:

Develop robust and powerful MCUs fast

Share cost

Focus on their areas of expertise, adding value

Take advantage of the expertise of others tobring their own products to market in the fastestpossible time

You

Page 8: Migration From Microchip to ARM Cortex

8

ARM microcontroller architectureHighest

IRQ1

IRQ2

PopISR 3Push

NMI

IRQ3

NMI ISR 1 ISR 2Push

implementation

Page 9: Migration From Microchip to ARM Cortex

9

ARM microcontroller architectureimplementation

Page 10: Migration From Microchip to ARM Cortex

10

ARM microcontroller architecture

A mixed 16-bit and 32-bit instruction set – Thumb®-2

Excellent code density, better than any 8 or 16-bit architecture

High performance, often 10x better than the fastest 8051 and2 – 3x better than 16-bit MCU

Build-in Nested Vector Interrupt Controller (NVIC) providefast interrupt response

Very easy to use with a strong focus on clean C programming

Interrupt handlers can be a normal C subroutine

Low power by design with consistent power managementmodes

Driving into very low cost designs; a 32-bit MCU starting fromjust 65 cents

Page 11: Migration From Microchip to ARM Cortex

11

Why switch to ARM?

Much better performance at same or lower clock speeds!

You can use that additional performance in a variety of ways:

Simpler coding, avoiding careful hand optimisations, more features,lower clock speed …

0

10

20

30

40

50

60

70

PIC18 PIC24 dsPIC Cortex-M0 Cortex-M3

Relative performance (DMIPS/MHz)

Page 12: Migration From Microchip to ARM Cortex

12

Why switch to ARM?

Much better energy efficiency!

Helps you squeeze more functionality out of precious battery life

Enables you to meet the increasing demands for low energyproducts

0

0.5

1

1.5

2

2.5

PIC18 PIC32 Cortex-M3

Energy efficiency (DMIPS/mW)

Page 13: Migration From Microchip to ARM Cortex

13

Why switch to ARM?

Smallest code size of any microcontroller!

Reducing code size is key to squeezing your application codeinto the minimum amount of flash

Relative code size

0

0.5

1

1.5

2

2.5

Cortex-M0 PIC18F PIC24F

Page 14: Migration From Microchip to ARM Cortex

14

Agenda

Part 1 – Introduction

Part 2 – Hardware Overview

Part 3 – Software Overview

Part 4 – Tools and debug

Part 5 – Getting Started

Page 15: Migration From Microchip to ARM Cortex

15

Memory map of ARM Cortex-M processors

Simple linear addressing,

No memory page switching

Unified and flat memorymodel (4GB)

You can execute programsfrom on-chip flash, SRAMor external memory

Page 16: Migration From Microchip to ARM Cortex

16

Memory map of ARM Cortex-M processors

Consistent layout acrossthe Cortex-M family andfrom vendor to vendor

Peripherals alwaysmemory mapped in thesame space

Little or big endian

Page 17: Migration From Microchip to ARM Cortex

17

Cortex-M registers – simple to use

Indirect Address

TMR0

Status

PCL

Port A

FSR

Port B

-

0x00

0x01

0x02

0x03

0x04

0x05

0x06

0x07

0x08

0x09

0x0F

0x0A

0x0B

0x0C

0x0D

0x0E

0x10

General PurposeRegister File

Register bankaddress

Bank 0

ADRES

ADCON0

PCLATH

INTCON

Indirect Address

OPTION

Status

PCL

TRISA

FSR

TRISB

-

Mapped in Bank0

Bank 1

ADRES

ADCON1

PCLATH

INTCON

PIC16/18 requires register bankswitching for accessing I/O registers

PIC16/18 uses a special registerfor indirect addressing

ARM registers can hold data or pointers

Same register set for every ARM processor

No need for any sort of bank switching

Page 18: Migration From Microchip to ARM Cortex

18

Stacks and stack memory

Stack management is a very important part of an MCU

Cortex-M takes quite a different approach to PIC …

PIC16, PIC18 :

Use a hardware stack for interrupt andsubroutine returns : 2 to 8 levels inPIC16, 31 levels in PIC18 – relativelyinflexible and increases powerconsumption. Also some are notaddressable

A software-implemented stack isinefficient – difficult to support localvariables and re-entrant code.

Page 19: Migration From Microchip to ARM Cortex

19

Stacks and stack memory

ARM :Stack is in main memory –very flexible and lowestpower

Full descending stack model– efficient memory usage in C

PUSH, POP instructions cansave/restore multipleregisters in one instruction

Two stack pointers for flexibility: Main Stack Pointer (MSP) : default

Process Stack Pointer (PSP) : for application tasks in OSenvironments

Simple applications only use the MSP and one stack

Page 20: Migration From Microchip to ARM Cortex

20

Traditional approach

Exception table Fetch instruction to branch

Top-level handler Routine handles re-entrancy

IRQVECTOR

LDR PC, IRQHandler

.

.

IRQHandler PROC

STMFD sp!,{r0-r4,r12,lr}

MOV r4,#0x80000000

LDR r0,[r4,#0]

SUB sp,sp,#4

CMP r0,#1

BLEQ C_int_handler

MOV r0,#0

STR r0,[r4,#4]

ADD sp,sp,#4

LDMFD sp!,{r0-r4,r12,lr}

SUBS pc,lr,#4

ENDP

Interrupts – high flexibility, ease of use

Highest

IRQ1

IRQ2

PopISR 3Push

NMI

IRQ3

NMI ISR 1 ISR 2Push

Page 21: Migration From Microchip to ARM Cortex

21

#include “vendor_device.h” /* lm3s_cmsis.h,LPC17xx.h, stm32f10x.h, etc */void main(void) {SystemInit();…NVIC_SetPriority(TIMER1_IRQn, 0x8);NVIC_EnableIRQ(TIMER1_IRQn, 0x0);…}void TIMER1_IRQHandler(void){ /* Timer 1 processing */}void SysTick_IRQHandler(void){ /* Systick timer processing */}

ARM Cortex-M based MCUs

Core automatically handles Saving corruptible registers

Exception prioritization

Exception nesting

No need for assembly, just C Pointer to C routine at vector

ISR is a C function

Faster interrupt response With less software effort

Interrupts – high flexibility, ease of use

Highest

IRQ1

IRQ2

PopISR 3Push

NMI

IRQ3

NMI ISR 1 ISR 2Push

Page 22: Migration From Microchip to ARM Cortex

22

Low power Cortex-M processors are designed for low power applications

and focus on energy efficiency:Device Active power Energy efficiency

Cortex-M3 - NXP1300 200uA/MHz 2.23 DMIPS/mW

PIC32MX3xx 680uA/MHz 0.31 – 0.95 DMIPS/mW

PIC18LF2x20 100-200uA/MHz 0.1 DMIPS/mW

Sleep modes arearchitectural andcommonto all devices:

normal sleep and …

deep sleep

Page 23: Migration From Microchip to ARM Cortex

23

Agenda

Part 1 – Introduction

Part 2 – Hardware Overview

Part 3 – Software Overview

Part 4 – Tools and debug

Part 5 – Getting Started

Page 24: Migration From Microchip to ARM Cortex

24

PIC specific C extensions

In general porting to an ARM MCU will be about simplification

PIC specific C extensions need to be removed:

No interrupt function type in PIC18, and separated handler for eachsource

Some C compiler directives need to be removed (#pragma configFOSC = INTOSC_EC and so on)

Some PIC-specific C compiler extensions (e.g. “bit” data type, binaryconstants) are not compatible and need to be adjusted

PIC assembly code need to be replaced (look out for asm, _asm,__asm), probably with more portable C

Peripherals:

Reserved words for PIC registers need to be replaced

Use device driver libraries to make software development easier

If you need to directly access to hardware registers, use pointers

Page 25: Migration From Microchip to ARM Cortex

25

Data type adjustments

Some data types have a different default size betweenPIC18/PIC24 compared to ARM

ARM architecture supportsvery efficient access to alldata types as long as youdeclare them correctly

Quite easy to deal with, e.g.const int mydata = {0x1234, 0x2345, … }; // 32-bit

becomes:

const short int mydata = {0x1234, 0x2345, … }; // 16-bit

Data Type PIC18/PIC24 ARM

Char 8 bits 8 bits

Short int 16 bits 16 bits

Integer 16 bits 32 bits

Pointers 8 or 16 bits 32 bits

Float 32 bits 32 bits

Double 32 bits 64 bits

Page 26: Migration From Microchip to ARM Cortex

26

Peripheral access - use a data structure

typedef struct {

volatile unsigned long DATA;

volatile unsigned long CTRL;

volatile unsigned long STAT;

volatile unsigned long BAUD;

} Uart_Type;

#define Uart0 ((Uart_Type *) 0x40030000) // Pointer to the structure

UART->BAUD = 3125; // 30MHz/9600

UART->CTRL = 0x7; // enable

if (UART->STAT & 0x4) {

c = UART->DATA;

}

This method is used in CMSIS(Cortex MicrocontrollerSoftware Interface Standard)

Accessing peripheralsin this way is clean,

efficient and scalable

Page 27: Migration From Microchip to ARM Cortex

27

Abstraction layer for all Cortex-M processor based devices

Developed in conjunction with silicon, tools and middleware Partners

ARM Cortex Microcontroller Standard

Benefits to the embedded developer Consistent software interfaces for silicon and middleware vendors Simplifies re-use across Cortex-M processor-based devices Reduces software development cost and time-to-market Reduces learning curve for new Cortex microcontroller developers

Page 28: Migration From Microchip to ARM Cortex

28

CMSIS example

#include “vendor_device.h” /* lm3s_cmsis.h, LPC17xx.h, stm32f10x.h, etc */

void main(void) {

SystemInit();

Just make sure the interrupthandler names match the ones inthe vector table

Interrupt Type constants aredefined in device header file

common name for system initialization (from CMSISv1.30 this function is called from startup code)

}

void TIMER1_IRQHandler(void)

{ /* Timer 1 processing */

}

void SysTick_IRQHandler(void)

{ /* Systick timer processing */

}

NVIC_SetPriority(TIMER1_IRQn, 0x8);

NVIC_EnableIRQ(TIMER1_IRQn, 0x0);

Page 29: Migration From Microchip to ARM Cortex

29

Real-time Library - ARM

A collection of resources for solving system challenges

Middleware components created and used by ARM engineers

All components are royalty-free

All library components supplied- no hidden costs

Delivered as librariesand source code

Flexible usage model(with or without theRTX Kernel)

Page 30: Migration From Microchip to ARM Cortex

Product Portfolio

µC/OS-II– Embedded RTOS– µC/OS-MMU– µC/OS-MPU

µC/OS-III– Embedded RTOS– Unlimited objects– Preemptive and Round-Robin Scheduling

µC/TCP-IP– Embedded TCP/IP v4 stack– DHCPc, DNSc, FTP, HTTPs, POP3c, SMTPc,

SNTPc,– TELNETs, Shell

µC/USB-Host– HID, CDC, MSD, Audio, Printer Classes– OHCI, EHCI, UHCI

µC/USB-Device– Bulk-device stack– HID, MSD, CDROM Classes

µC/USB-OTG

µC/Bluetooth– SPP, RFCOMM, L2CAP and HCI layers

µC/CAN– CAN Framework– µC/CANopen I (Small Sensor Slave)

µC/Modbus– Master and/or Slave, RS-232C or RS-485– ASCII and/or RTU

µC/GUI– Embedded Graphical User Interface

µC/FS– Embedded File System– FAT32, Long Filenames– Many media drivers

µC/BuildingBlocks– Software time-of-day clock (µC/CLK)– Character-based LCD (µC/LCD)– Shell (µC/Shell)– CRC Calculation (µC/CRC)–

µC/Probe– Run-time data monitor– Any CPU (8-, 16-, 32-, 64-bit or DSP)– Any compiler/linker (ELF or IEEE695)– Any interface (RS-232C, TCP/IP, USB, etc.)– With or without an RTOS

Page 31: Migration From Microchip to ARM Cortex

31

Agenda

Part 1 – Introduction

Part 2 – Hardware Overview

Part 3 – Software Overview

Part 4 – Tools and debug

Part 5 – Getting Started

Page 32: Migration From Microchip to ARM Cortex

32

Compiler suites

Keil Microcontroller Development Kit for ARM (MDK-ARM)

ARM RealView Development Suite (RVDS)

mbed

IAR Embedded Workbench for ARM

Code_red Technologies (Red Suite 2)

LPCXpresso from NXP

Raisonance (Rkit-ARM)

Rowley Associates (Crosswork 2)

National Instrument (LabVIEW Embedded Module for ARM)

Tasking (VX-toolset)

… more to come

Page 33: Migration From Microchip to ARM Cortex

33

Debug

Cortex-M processors include comprehensive debug features

Debug connectors

10 pins 20 pins inc.trace

Page 34: Migration From Microchip to ARM Cortex

34

Debug tools

Keil : ULINK2, ULINK-Pro

ARM : RealView-ICE, RealView Trace

Lauterbach : TRACE32

Segger : J-Link / IAR :J-Link

Signum : JTAGJet / JTAGJet-Trace

Code Red Technologies : Red probe, LPC-Link

ST-LINK… etc

Page 35: Migration From Microchip to ARM Cortex

35

Agenda

Part 1 – Introduction

Part 2 – Hardware Overview

Part 3 – Software Overview

Part 4 – Tools and debug

Part 5 – Getting Started

Page 36: Migration From Microchip to ARM Cortex

36

Development, Evaluation, Prototyping

Evaluation Kits

Development boards

Latest web-based rapid prototyping

http://mbed.org

Page 37: Migration From Microchip to ARM Cortex

37

Resources to get started

Keil web site (www.keil.com)

Document and Application notes on ARM “infocenter”(infocenter.arm.com)

MCU vendor web sites

For example Apps note AN01249 from TI

Training courses (MCU vendors,Doulos - www.doulos.com/arm)

ARM forums and forums in MCUvendor web sites

http://forums.arm.com

http://www.keil.com/forum/threads.asp

Books

Page 38: Migration From Microchip to ARM Cortex

38

Summary

The ARM approach to microcontrollers is somewhat differentto that of Microchip

We are committed to working with a wide number ofsuppliers, each bringing differentiation to their products

hundreds of silicon parts already available (Atmel, Ember,EnergyMicro, Luminary/TI, NXP,ST, Toshiba and so on) and manymore on the way

ARM and our licensees actively encourage a wide ecosystemthat helps you program faster and more efficiently; toolsdebug hardware, middleware, device drivers, libraries

We want to deliver technology benefits to help you buildbetter products:

Big steps forward delivering denser code, energy efficiency,performance headroom compared to 8 and 16-bit micros

Page 39: Migration From Microchip to ARM Cortex

39

Questions & Answers