Vous êtes sur la page 1sur 39

Migration from Microchip PIC18/PIC24 to ARM Cortex Microcontrollers

Bryan Lawrence - Solutions Marketing Manager Richard York - Director of Product Marketing

Todays Presenters

About Richard York

About Bryan Lawrence

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 ARMs advanced research and development group. He is also the principal architect of the ARM RealTrace debug system.

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.

Agenda
Part 1 Introduction Part 2 Hardware Overview Part 3 Software Overview Part 4 Tools and debug Part 5 Getting Started

Introduction
PIC microcontrollers can certainly handle some embedded
applications 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

Touch screen controller Accelerometer GPS / Bluetooth Battery monitor Joystick/touchpad controller

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)
* *

ARM Founded 27th Nov 1990


A barn, some energy, experience and belief:
Were going to be the Global Standard Originally 12 employees, now >1,700 IP (Intellectual Property) company we design and license processor technology
to chip vendors Semiconductor Partners

Focus on low power and energy efficiency Two decades of Partnership success

memory memory

SoC SoC

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 to bring their own products to market in the fastest possible time
You

ARM microcontroller architecture implementation


Highest NMI IRQ1 IRQ2 IRQ3

PushPush

NMI

ISR 1

ISR 2

ISR 3

Pop

ARM microcontroller architecture implementation

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 and 2 3x better than 16-bit MCU Build-in Nested Vector Interrupt Controller (NVIC) provide fast 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 management modes Driving into very low cost designs; a 32-bit MCU starting from just 65 cents

10

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
70 60 50 40 30 20 10 0 PIC18 PIC24 dsPIC Cortex-M0 Cortex-M3

Relative performance (DMIPS/MHz)

11

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 energy
products
2.5

Energy efficiency (DMIPS/mW)


2

1.5

0.5

0 PIC18
12

PIC32

Cortex-M3

Why switch to ARM?


Smallest code size of any microcontroller! Reducing code size is key to squeezing your application code
into the minimum amount of flash
2.5

Relative code size


2

1.5

0.5

0 Cortex-M0 PIC18F PIC24F

13

Agenda
Part 1 Introduction Part 2 Hardware Overview Part 3 Software Overview Part 4 Tools and debug Part 5 Getting Started

14

Memory map of ARM Cortex-M processors


Simple linear addressing,
No memory page switching Unified and flat memory
model (4GB)

You can execute programs


from on-chip flash, SRAM or external memory

15

Memory map of ARM Cortex-M processors


Consistent layout across
the Cortex-M family and from vendor to vendor Peripherals always memory mapped in the same space Little or big endian

16

Cortex-M registers simple to use


Bank 0 Register bank address 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 General Purpose Register File Mapped in Bank 0 Indirect Address TMR0 PCL Status FSR Port A Port B ADCON0 ADRES PCLATH INTCON Indirect Address OPTION PCL Status FSR TRISA TRISB ADCON1 ADRES PCLATH INTCON Bank 1

PIC16/18 uses a special register for indirect addressing PIC16/18 requires register bank switching for accessing I/O registers
17

ARM registers can hold data or pointers Same register set for every ARM processor No need for any sort of bank switching

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 and subroutine returns : 2 to 8 levels in PIC16, 31 levels in PIC18 relatively inflexible and increases power consumption. Also some are not addressable A software-implemented stack is inefficient difficult to support local variables and re-entrant code.

18

Stacks and stack memory


ARM : Stack is in main memory very flexible and lowest power Full descending stack model efficient memory usage in C PUSH, POP instructions can save/restore multiple registers in one instruction

Two stack pointers for flexibility:


environments

Main Stack Pointer (MSP) : default Process Stack Pointer (PSP) : for application tasks in OS

Simple applications only use the MSP and one stack


19

Interrupts high flexibility, ease of use


Traditional approach
IRQVECTOR LDR PC, IRQHandler . .

Exception table
Fetch instruction to branch

Top-level handler
Routine handles re-entrancy

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

Highest NMI IRQ1 IRQ2 IRQ3

Push Push

NMI

ISR 1

ISR 2

ISR 3

Pop

20

Interrupts high flexibility, ease of use


ARM Cortex-M based MCUs Core automatically handles
Saving corruptible registers Exception prioritization Exception nesting
#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 */ }

No need for assembly, just C


Pointer to C routine at vector ISR is a C function

Faster interrupt response


With less software effort
Highest NMI IRQ1 IRQ2 IRQ3

Push Push

NMI

ISR 1

ISR 2

ISR 3

Pop

21

Low power
Cortex-M processors are designed for low power applications
and focus on energy efficiency:
Device PIC32MX3xx PIC18LF2x20 Active power 680uA/MHz 100-200uA/MHz Energy efficiency 2.23 DMIPS/mW 0.31 0.95 DMIPS/mW 0.1 DMIPS/mW Cortex-M3 - NXP1300 200uA/MHz

Sleep modes are architectural and common to all devices:

normal sleep and deep sleep

22

Agenda
Part 1 Introduction Part 2 Hardware Overview Part 3 Software Overview Part 4 Tools and debug Part 5 Getting Started

23

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 each
source Some C compiler directives need to be removed (#pragma config FOSC = INTOSC_EC and so on) Some PIC-specific C compiler extensions (e.g. bit data type, binary constants) 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
24

Data type adjustments


Some data types have a different default size between
PIC18/PIC24 compared to ARM ARM architecture supports Data Type very efficient access to all Char data types as long as you Short int declare them correctly
Integer Float Double Pointers PIC18/PIC24 8 bits 16 bits 16 bits 8 or 16 bits 32 bits 32 bits ARM 8 bits 16 bits 32 bits 32 bits 32 bits 64 bits

Quite easy to deal with, e.g.


const int mydata = {0x1234, 0x2345, }; // 32-bit

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

25

Peripheral access - use a data structure


typedef struct { volatile unsigned long DATA; This method is used in CMSIS (Cortex Microcontroller volatile unsigned long CTRL; Software Interface Standard) 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 Accessing peripherals in this way is clean, if (UART->STAT & 0x4) { efficient and scalable c = UART->DATA; }
26

ARM Cortex Microcontroller Standard


Abstraction layer for all Cortex-M processor based devices Developed in conjunction with silicon, tools and middleware Partners

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

27

CMSIS example
#include vendor_device.h /* lm3s_cmsis.h, LPC17xx.h, stm32f10x.h, etc */ void main(void) { common name for system initialization (from CMSIS SystemInit(); v1.30 this function is called from startup code) NVIC_SetPriority(TIMER1_IRQn, 0x8); NVIC_EnableIRQ(TIMER1_IRQn, 0x0); } void TIMER1_IRQHandler(void) { /* Timer 1 processing */ } void SysTick_IRQHandler(void) { /* Systick timer processing */ }
28

Interrupt Type constants are defined in device header file

Just make sure the interrupt handler names match the ones in the vector table

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

Flexible usage model (with or without the RTX Kernel)

Delivered as libraries and source code

29

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

Agenda
Part 1 Introduction Part 2 Hardware Overview Part 3 Software Overview Part 4 Tools and debug Part 5 Getting Started

31

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
32

Debug
Cortex-M processors include comprehensive debug features

Debug connectors 10 pins 20 pins inc. trace

33

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

34

Agenda
Part 1 Introduction Part 2 Hardware Overview Part 3 Software Overview Part 4 Tools and debug Part 5 Getting Started

35

Development, Evaluation, Prototyping


Evaluation Kits Development boards

Latest web-based rapid prototyping


http://mbed.org

36

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 MCU vendor web sites http://forums.arm.com http://www.keil.com/forum/threads.asp Books

37

Summary
The ARM approach to microcontrollers is somewhat different
to that of Microchip We are committed to working with a wide number of suppliers, each bringing differentiation to their products hundreds of silicon parts already available (Atmel, Ember,
EnergyMicro, Luminary/TI, NXP,ST, Toshiba and so on) and many more on the way

ARM and our licensees actively encourage a wide ecosystem


that helps you program faster and more efficiently; tools debug hardware, middleware, device drivers, libraries We want to deliver technology benefits to help you build better products: Big steps forward delivering denser code, energy efficiency,
performance headroom compared to 8 and 16-bit micros
38

Questions & Answers

39

Vous aimerez peut-être aussi