ADVANCED
MICROCONTROLLER
INTRODUCTION
Lecturer: Dr. Bui Ha Duc
Dept. of Mechatronics
Email: [email protected]
1
INSTRUCTOR INTRODUCTION
• Full Name: Bui Ha Duc
• From: Vung Tau City
• Bachelor: HCMC University of Technology
• Ph.D: National University of Singapore
(NUS)
• Research fellow / TA in NUS
• Join HCMUTE in 2015
• Lecturer in Department of Mechatronics –
FME
• Teaching: Microcontroller, Embedded
system, Digital signal processing.
2
COURSE OBJECTIVES
• Provide advanced knowledge of microcontroller
• MCU: ARM Cortex M
• Apply microcontroller to solve real problems
• Problem solving skill and team-work skill
3
ORDER OF INTRUCTION
Review about microcontroller and its architecture
ARM microcontroller system
Peripheral modules – IO, Timer, Interrupt…
Wired Communication – UART, I2C, SPI, USB
Wireless communication – Bluetooth, wifi, zigbee
Storage module – SD card, external memory
…
4
ASSESSMENTS
• Assignments – 50%
• Group Project – 50%
o Progress report – 30%
o Final Product – 20%
5
References
• Joseph Yiu - The Definitive Guide to ARM Cortex®-M0 and Cortex-
M0, 2016.
• Joseph Yiu - The Definitive Guide to ARM Cortex®-M3 and
Cortex-M4 Processors, 2013
• MCU datasheets:
• Holtek 32F52352
• STM32F4 (Optional)
• Holtek ESK32-30501
• Expansion board ESK32-2x001
• ARM CMSIS
• …
• Devices datasheets
6
Software
• Keil Microcontroller Development Kit (MDK):
• Keil MDK helps you to create embedded applications for ARM Cortex-M
processor-based devices
http://www2.keil.com/mdk5/
• Documents:
http://www2.keil.com/mdk5/docs
• MDK consists of the MDK Core plus device-specific Software Packs
7
9
What is Microcontroller?
Wiki definition:
• a small digital computer on a single integrated circuit
• Contain processor core(s), memory, I/O peripherals
• Programmable
10
How does microcontroller work?
Algorithm
Code
(C / Assembly)
Compiler
List of Instructions
Inputs Outputs
MCU
• Instruction Fetch: get the instruction from memory into the processor
• Decode: decode the instruction to get the operation (what it has to do)
• Execute: Perform the operation
• Store: store the result back into another register
11
Pipelining
Instruction Pipeline stage
1 IF D EX STR
2 IF D EX STR
3 IF D EX STR
4 IF D EX
5 IF D
Clock cycle 1 2 3 4 5 6
RISC (Reduced instruction set computers)
architecture
12
Pipelining
• Laundry analogy
Can we make the
whole process faster ?
http://www.ece.arizona.edu/~ece462/Lec03-pipe/
13
Pipelining
Significantly speedup the operation!
http://www.ece.arizona.edu/~ece462/Lec03-pipe/
14
Inside a microcontroller
15
Central Processor Unit (CPU)
CPU monitors and controls all
processes within the microcontroller
• Instruction decoder
• Arithmetical Logical Unit (ALU)
• Accumulator
16
MEMORY
• Nonvolatile program memory
(ROM)
‒ store application software
‒ retain the information stored in
it even when power is removed
• Volatile variable memory
(RAM)
‒ Temporary storage of data
‒ Value will be lost when power is
removed
• Optional nonvolatile data
memory (EEPROM)
17
Oscillator
• enable harmonic and synchronous
operation
• program instructions are slower than
oscillator rate
Why do we need oscillator
clock?
http://www.npeducations.com/2013/10/introduction-to-basics-of.html
How can microcontroller
know when an instruction
finish?
18
Von Neumann architecture
• also known as the Princeton architecture
• Created in 1945 by the mathematician and physicist John
von Neumann
John von Neumann
(1903-1957)
19
Harvard architecture
• The Harvard architecture is a computer architecture with
physically separate storage and signal pathways for
instructions and data
20
21
Why ARM?
• ARM devices are steadily increasing in popularity.
22
Why ARM?
• The growth in 32-bit overtake 8/16-bits
• Traditional 8/16-bit applications migrating to 32-bit
23
Introduction to ARM microcontroller
HISTORY OF ARM Ltd
• Founded in November 1990 by a small group of engineers
• Advanced RISC Machines
• Company headquarters in Cambridge, UK
• Processor design in Cambridge, Austin, and Sophia Antipolis
• Sales, support, and engineering offices all over the world
• Best know for its range of RISC processor core designs
• Also produce software tools, models, cell libraries for partners
• ARM does not manufacture silicon
• ARM partners ship billion chips with ARM processors each year
24
Introduction to ARM microcontroller
25
ARM processor family
2003 2005 2009 2012
26
ARM Processor Performance
27
ARM Architecture Development
The evolution of ARM processor architecture
28
ARM Architecture Development
ARM Instruction set enhancement
Cortex family
30
Cortex family
• ARM Cortex™-A family:
• Applications processors for feature-rich OS and
3rd party applications
• ARM Cortex-R family:
• Embedded processors for real-time signal
processing, control applications
• ARM Cortex-M family:
• Microcontroller-oriented processors for MCU,
ASSP, and SoC applications
32
Cortex-M family
33
Cortex M0+ processors
• 2009 – ARM® Cortex™-M0 processor
released
• Low gate count
• High performance
• Easy to use
• Debug features
• 2012 – Cortex-M0+ processor released
• Same instruction set
• Supports all existing features of Cortex-M0
• New features
• Higher energy efficiency
• Ready for future applications
35
Overview of the Cortex-M0+ Processor
• Processor
• ARMv6-M architecture
• Easy to use, C friendly
• Cortex-M series compatibility
• Nested Vectored Interrupt
Controller (NVIC)
• Flexible interrupt handling
• WIC support
• Memory Protection Unit (MPU)
• Debug from just 2 pins
36
ARMv6-M architecture
• ARM is a 32-bit load / store RISC architecture
• The only memory accesses allowed are loads and stores
• Most internal registers are 32 bits wide
• Most instructions execute in a single cycle
• When used in relation to the ARM:
• Byte means 8 bits
• Halfword means 16 bits (two bytes)
• Word means 32 bits (four bytes)
• Doubleword means 64 bits (eight bytes)
• Most ARM’s implement two instruction sets
• 32-bit ARM Instruction Set: all instructions are 32 bits wide
• 16-bit Thumb Instruction Set: all instructions are 16 bits wide
37
Thumb
• Thumb is a 16-bit instruction set
• Optimised for code density from C code (~65% of ARM code size)
• Improved performance from narrow memory
• Subset of the functionality of the ARM instruction set
38
The Thumb-2 instruction set
• Variable-length instructions
• ARM instructions are a fixed length of 32
bits
• Thumb instructions are a fixed length of
16 bits
• Thumb-2 instructions can be either 16-bit
or 32-bit
• Thumb-2 gives approximately 26%
improvement in code density over
ARM
• Thumb-2 gives approximately 25%
improvement in performance over
Thumb
39
Cortex-M0+ Instruction Set
• Only 56 Instructions
• 100% compatible with existing
Cortex-M0 processor
• Mostly 16-bit instructions
• All instructions operate on the
32-bit registers
Upward compatibility to the
• Option for single cycle 32x32 ARM Cortex-M3/Cortex-M4
multiply
40
Cortex-M processors Instructions Set
41
Processor Design
• Small silicon area (from 12K gates)
• 2-stage pipeline processor for maximum energy efficiency
• Reduce ratio between flip-flops and combinatorial logic
• Lower average CPI (Cycles Per Instruction)
42
Processor Mode
• Cortex-M has only 2 processor mode
• Thread Mode for User tasks, is entered on Reset
• Handler Mode for OS task, is entered on all other exceptions
• Both modes have full access to all system resources
• No concept of privilege. Mechanism exists but has no meaning to M0
43
Cortex-M0 Register Set
• All registers are 32 bits wide
• 13 general purpose registers
• Registers r0 – r7 (Low registers)
• Registers r8 – r12 (High registers)
• 3 registers with special meaning/usage
• Stack Pointer (SP) – r13
• Link Register (LR) – r14
• Program Counter (PC) – r15
• Special-purpose registers xPSR
44
Programming with Cortex-M
• ARM Instruction sets are optimized for C Programming
• Programming tools:
• KEIL MDK 5
• IAR Embedded workbench
• ARM GNU
• ARM provided CMSIS (Cortex Microcontroller Software
Interface Standard), make it easier to port applications
within the ARM Cortex family
45
CMSIS
Cortex Microcontroller System Interface Standard
• CMSIS enables consistent device support and simple software interfaces to the
processor and its peripherals
CMSIS Components
• CMSIS-CORE: a vendor-independent hardware abstraction layer for Cortex-
M processors
• CMSIS-RTOS: API that enables consistent software layers with middleware
and library components, designed for real-time operating systems.
• CMSIS-DSP: Fast implementation of digital signal processing.
• CMSIS-Driver: Generic peripheral interfaces for middleware and application
code.
• CMSIS-Pack: Easy access to reusable software components.
• CMSIS-SVD: System View Description, give consistent view to device and
peripherals
• CMSIS-DAP: Debug Access Port, connectivity to low-cost evaluation
hardware
46
CMSIS
47
48
Holtek HT32F52352
• 32-Bit ARM® Cortex™-M0+ Microcontroller
• Operate at a frequency of up to 48 MHz
• Program memory: 128KB
• Data memory: 16KB
• Integrated Nested Vectored Interrupt Controller
• 24-bit SysTick timer
• ADC: 12 channel, 12-bit
• Operating voltage: 2V-3.6V
49
Holtek HT32F52352
USB 1
SPI 2
USART 2
2
Communication UART
I2C 2
I2S 1
SCI (ISO7816-3) 2
Communication interfaces
50
Clock structure
• External 4 to 16 MHz crystal oscillator
• External 32,768 Hz crystal oscillator
• Internal 8 MHz RC oscillator trimmed to ±2 % accuracy at
3.3V operating voltage and 25°C operating temperature
• Internal 32 kHz RC oscillator
• Integrated system clock PLL
• Independent clock divider and gating bits for peripheral
clock sources
51
52
Holtek HT32F52352 Diagram
53
Holtek ESK32-30501
54
Holtek ESK-2x001
55
Holtek ESK-2x001
• RS232 connector • Backup battery
• Wakeup and two key buttons • SWD-20P debug Port
• Touch keys interface
• Three LEDs • Smart card connector
• I2C – compatible serial • CMOS sensor connector
interface EEPROM • Multi interface including
• SPI – compatible serial UART, I2C, SPI and GPIO
interface Flash functions for connecting
• SPI and EBI extension various modules
interfaces for LCD display • Audio input contains
applications microphone and stereo jack
• SD card slot – SPI mode • Audio output contains speaker
• PWM output for Buzzer driving connector and stereo jack
56