Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MICROCONTROLLER
INTRODUCTION
Lecturer: Dr. Bui Ha Duc
Dept. of Mechatronics
Email: ducbh@hcmute.edu.vn
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
3
ORDER OF INTRUCTION
4
ASSESSMENTS
• Assignments – 50%
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
12
Pipelining
• Laundry analogy
http://www.ece.arizona.edu/~ece462/Lec03-pipe/
13
Pipelining
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
• 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
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
• ARM partners ship billion chips with ARM processors each year
24
Introduction to ARM microcontroller
25
ARM processor family
27
ARM Architecture Development
30
Cortex family
• ARM Cortex™-A family:
• Applications processors for feature-rich OS and
3rd party 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
35
Overview of the Cortex-M0+ Processor
• Processor
• ARMv6-M architecture
• Easy to use, C friendly
• Cortex-M series compatibility
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
Cortex-M0 processor
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)
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)
44
Programming with Cortex-M
• ARM Instruction sets are optimized for C Programming
• Programming tools:
• KEIL MDK 5
• IAR Embedded workbench
• ARM GNU
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