04 - Cortex-M0 & NUC029 Introduction
04 - Cortex-M0 & NUC029 Introduction
04 - Cortex-M0 & NUC029 Introduction
Introduction to Cortex-M0
A Leading MCU Platform Provider
ARM Architecture Roadmap
2
Reference from ARM
Cortex-M0 Function Block
• Cortex-M0 processor includes
- Cortex-M0 processor core
- Nested Vectored Interrupt Controller (NVIC)
Nuvoton provider
- System Timer (SysTick)
Nested AHB-Lite
Vectored Cortex-M0 interface
Interrupts Interrupt Processor
Controller core ROM
(NVIC)
RAM
Peripherals
System Timer
(SysTick)
Cortex-M0
6
Cortex-M0 Architecture Overview
• ARMv6-M (which is a subset of ARMv7-M, upward
compatible)
• It supports only the Thumb instruction set. No Interworking code is
required.
• Total are 56 instructions. 6 are 32-bit length, the others are 16-bit
length
32-bit instructions : BL, DMB, DSB, ISB, MRS, MSR
7
Cortex-M0 Architecture Overview – cont.
• Processor modes are Thread and Handler.
• Always in privilege
• Supports hardware key context state saving and restoring (Need not
Assembly coding for ISR).
• Built-in timer and interrupt controller
• NVIC, Systick
• Memory mapped I/O
• Use same instructions to access memory and registers
• Ex : LDR, STR
8
Memory Model
• 32-bit address space
• Virtual memory is not supported in ARMv6-M.
• Instruction fetches are always halfword-aligned
• Data accesses are always naturally aligned
• Ex : word at address A : A, A+1, A+2 and A+3.
9
System Memory Map
0xE000_EFFF
0xE000_E000
Cortex M0 System Register System
Reserved
0x501F_FFFF
AHB peripherals
0x5000_0000
Reserved Peripheral
0x401F_FFFF
APB peripherals
0x4000_0000
Reserved
0x2000_3FFF
0x2000_0000
16KB RAM SRAM
Reserved
0x0010_1FFF
ISP Loader Program Memory (8KB LDROM)
0x0010_0000
Reserved Code
0x0001_FFFF
Application Program Memory (128KB APROM)
0x0000_0000
10
Memory Setting in Keil
Code region
SRAM region
11
System Timer - SysTick
• SysTick provides a simple, 24-bit clear-on-write,
decrementing, wrap-on-zero counter.
• When enabled, the timer will count down. When the
counter transitions to zero, the COUNTFLAG status bit is set.
• The reference clock can be the core clock or an external
clock source.
SysTick request
CPU clock Reference when counter
clock 24-bit reaches 0
down count counter
external clock
Reload counter
15
Exception Model – cont.
• Exceptions defined in Cortex-M0
Exception
Exception Priority level
number
1 Reset -3
2 NMI -2
Cortex M0 Core 3 HardFault -1
Exception
11 SVCall configured by register SHPR2
14 PendSV configured by register SHPR3
15 SysTick configured by register SHPR3
External Interrupt
16 configured by register NVIC_IPRx
(0)
IP Exception … … …
External Interrupt
47 configured by register NVIC_IPRx
(31)
19
Exception Model – cont.
• Exception priorities and pre-emption
• Lower numbers (0-3) take higher precedence
• If multiple exceptions have the same priority number, the pending
exception with the lowest exception number takes precedence.
• Only exceptions with a higher priority (lower priority number) can pre-
empt an active exception.
20
Context Saving and Restoring
• Key context saving and restoring
• Using full-descending stack format (decremented immediately before
storing, incremented after reading)
• xPSR, ReturnAddress(), LR (R14), R12, R3, R2, R1, and R0
SP’ H
xPSR
ReturnAddress Loaded into PC on exception return
LR
r12
r3
r2
r1
SP r0
L
21
Nested Vectored Interrupt Controller (NVIC)
• Supports up to 32 (IRQ[31:0]) discrete interrupts which can
be either level-sensitive or pulse-sensitive.
• NVIC interrupts can be enabled/disabled, pended/un-
pended and prioritized by setting NVIC control registers
Exception 47
22
Summary
• Cortex-M0 is always in privileged mode and supports Thumb
instruction only.
• Supports key context saving and restoring
• xPSR, return address, r14, r12, r3, r2, r1, r0
• System address map is defined in advance.
• Code, SRAM, Peripheral, System
• Contains SysTick and NVIC
29
NuMicro
Cortex-M0 NUC029 Series
A Leading MCU Platform Provider
NuMicro® M0 Microcontroller introduction 5V MCU
New
Platform
Ultra Low Power
512 KB
M031 NUC029 M251 Series
1.8V Series 5V Series M252 Series
256 KB
128 KB
Nano130
M0564 NUC126 NUC240 Nano120
M0518 NUC125 NUC220 Nano110
NUC140 Nano130
M0516 NUC121 NUC140 Nano100
64 KB
NUC130 Nano110
M058 NUC123
NUC131 NUC240
M054 NUC120
M052 NUC230 Nano103
32 KB
QFN33(4x4) QFN48
TSSOP20 LQFP64(7x7)
QFN33(5x5) LQFP48(7x7) 33
NUC029 Series Features
System Analog
• Arm® Cortex® -M0, CPU speed up to 72 MHz • Up to 15-channels high performance 12bit ADC
• 16 ~ 256 KB Flash / 2 ~ 20 KB SRAM • Up to 1MSPS 12bit ADC
• Supply voltage 2.5 ~ 5.5V • Build-in analog comparator x2
• Operating temperature -40 ~ 105 °C • Support BOD/LVR function
Peripherals Others
• UART, SPI, I2C, LIN interface • Support crystal-less USB 2.0 FS device
• USCI support to configure as UART, SPI, I2C • HID, MSD, VCOM
• Up to 12-channels 144MHz resolution PWM,
• Support Hardware Divider
with programmable dead-zone
• 16/8 bit EBI
34
NUC029FAE/ZAN/TAN/NAN/LAN Feature
The NuMicro NUC029FAE/ZAN/TAN/NAN/LAN is embedded with the Cortex™-M0 core
running up to 50 MHz (NUC029FAE: 24MHz) and features 64K/32K/16K bytes flash, 4K bytes SRAM, and
4 Kbytes loader ROM for the ISP. It is also equipped many system level peripheral functions, such as
Timers, Watchdog Timer (WDT), Window Watchdog Timer (WWDT), UART, SPI, I2C, PWM, GPIO, 800
kSPS high speed 12-bit ADC, Low Voltage Reset Controller and Brown-out Detector.
• Memories
• Flash/SRAM Optional • Differentiated Features
16/32/64 KB Flash & SRAM 2/4 KB • Analog Comparator
NUC029
• Communication Interfaces
• Up to 8-ch PWM • Analog Features
• Up to UARTx4, SPI/I2Cx2 • 8-channel 12-bit ADC, up to 800 KSPS.
• 16/8 bit EBI interface
35
NUC029FAE/ZAN/TAN/NAN/LAN Function Blocks
36
NUC029LDE/SDE Feature
The NuMicro NUC029LDE/SDE is embedded with the Cortex™-M0 core running up to 50 MHz
and features 68 Kbytes flash, 8K bytes SRAM, and 4 Kbytes loader ROM for the ISP. It is also equipped with
plenty of peripheral devices, such as Timers, Watchdog Timer (WDT), Window Watchdog Timer (WWDT),
UART, SPI, I2C, PWM, GPIO, LIN, 1000 kSPS high speed 12-bit ADC, Low Voltage Reset Controller and
Brown-out Detector.
• Core
• Arm® Cortex®-M0 MCU
• Power Management and Robustness
• Frequency up to 50 MHz
• 2.5V to 5.5V wide operating voltage
• -40℃ ~ +105 ℃ Industrial Temperature
• Memories
• Flash 68 KB/SRAM 8 KB
38
NUC029LEE/SEE Feature
NUC029LEE/SEE which is a 32-bit Microcontroller based on Arm® Cortex® M0 Core can operate
at 72 MHz with wide supply voltage from 2.5V to 5.5V as well as -40oC to 105oC temperature range. It
integrates 12-channels 12-bit ADC that up to 1000K SPS conversion rate, a 16/8 bit EBI interface to
support display, and support USB 2.0 full-speed device function.
• Core
• Arm® Cortex®-M0 MCU
• Power Management and Robustness
• Frequency up to 72MHz
• 2.5V to 5.5V wide operating voltage
• -40℃ ~ +105 ℃ Industrial Temperature
• Memories
• Flash 128 KB/SRAM 16 KB
• Differentiated Features
• Independent power supply for RTC
• Communication Interfaces
• Up to 6-ch PWM NUC029
• Up to UARTx3, SPI/I2Cx2 • Analog Features
• 16/8 bit EBI interface • 12-channel 12-bit ADC, up to 1MSPS.
• USB 2.0 full-speed device
39
NUC029LEE/SEE Function Blocks
40
NUC029LGE/SGE Feature
NUC029LGE/SGE which is a 32-bit Microcontroller based on Arm® Cortex® M0 Core can operate at 72 MHz with
wide supply voltage from 2.5V to 5.5V as well as -40oC to 105oC temperature range. It integrates 15-channels
12-bit ADC that up to 800KSPS conversion rate, a 16/8 bit EBI interface to support display, have voltage
adjustable interface (up to 6 IOs) with supply VDDIO from 1.8V to 5.5V, and support USB 2.0 full-speed device
function (Crystal-less).
• Core
• Power Management and Robustness
• Arm® Cortex®-M0
MCU
• 2.5V to 5.5V wide operating voltage
• Frequency up to 72MHz
• -40℃ ~ +105 ℃ Industrial Temperature
• Memories
• Flash 256 KB/SRAM 20 KB • Differentiated Features
• Independent power supply for RTC
• Communication Interfaces • VAI (Voltage Adjustable Interface)
• USCIx3 (UART, I2C, SPI)
NUC029
• Up to 12-ch PWM • Analog Features
• Up to UARTx3, SPI/I2Cx2/I2Sx2 • Up to 15-channel 12-bit ADC, up to
• 16/8 bit EBI interface 800KSPS.
• USB 2.0 full-speed device
41
(Crystal-less)
NUC029LGE/SGE Function Blocks
Memory Speed Up RTC / PWM / Timer Analog Interface
ADC(12-Bit)
SRAM (KB)
Flash (KB)
Package
Divider
PDMA
ACMP
Timer
PWM
Part
CPU
CRC
RTC
LXT
PLL
I/O
EBI
USB FS
USCI*
UART
Number
LIN
SPI
I2C
I2S
NUC029FAE 16 2 24 2 17 2 3 - - 1 1 1 - - - - - - √ - 2 - 4 (10-bit) TSSOP20
NUC029TAN 32 4 50 4 24 4 5 - - 2 1 2 - - - - - √ - - 3 √ 5 QFN33*
NUC029ZAN 64 4 50 4 24 4 5 - - 2 1 2 - - - - - √ - - 3 √ 5 QFN33
NUC029NAN 64 4 50 4 40 4 8 - - 2 2 2 - - - √ - √ - - 4 √ 8 QFN48
NUC029LAN 64 4 50 4 40 4 8 - - 2 2 2 - - - √ - √ - - 4 √ 8 LQFP48
NUC029LDE 68 8 50 4 42 4 12 - - 4 1 2 - 3 - - - √ - - - - 8 LQFP48
NUC029SDE 68 8 50 4 56 4 12 - - 4 1 2 - 3 - - - √ - - - - 8 LQFP64*
43
NUC029 Series Naming Rule
NUC 029 T D E
Temperature
N - 40℃ ~ +85℃
E - 40℃ ~ +105℃
Package
F TSSOP20 4.4x6.5 (mm)
Flash Size
T QFN33 4x4 (mm)
A < 68K
Z QFN33 5x5 (mm)
D 68K
N QFN48 7x7 (mm)
E 128K
L LQFP48 7x7 (mm)
G 256K
S LQFP64 7x7 (mm)
44
ARM Cortex-M0 Function Block Diagram
4 Break Point
2 Watchpoint
Cortex-M0 components
Cortex-M0 processor Debug
Interrupts Nested
Cortex-M0 Breakpoint
Vectored
and
Interrupt Processor Watchpoint
Controller core unit
(NVIC)
Wakeup
Interrupt Debug
Controller Bus matrix Debugger
Access Port
(WIC) interface
(DAP)
45
System Memory Map
0xE000_EFFF
0xE000_E000
Cortex M0 System Register System
Reserved
0x501F_FFFF
AHB peripherals
0x5000_0000
Reserved Peripheral
0x401F_FFFF
APB peripherals
0x4000_0000
Reserved
0x2000_3FFF
0x2000_0000
16KB RAM SRAM
Reserved
0x0010_1FFF
ISP Loader Program Memory (8KB LDROM)
0x0010_0000
Reserved Code
0x0001_FFFF
Application Program Memory (128KB APROM)
0x0000_0000
46
Power Management (1/2)
• Idle mode
SYS_UnlockReg();
CLK_Idle();
• PowerDown mode
SYS_UnlockReg();
PowerDownFunction();
48
System Reset
• Hardware Reset
• The Power-On Reset
• nRESET pin Reset
• Watchdog Time Out Reset
• Low Voltage Detected Reset
• Brown-Out-Detected Reset
• Software Reset
• CPU_RST
“RSTSRC” register identify chip’s reset source from last operation
Just only reset CPU & flash controller
SYS_UnlockReg(); SYS_ResetCPU();
• CHIP_RST
To reset the whole chip like “Power-on reset”
SYS_UnlockReg(); SYS_ResetChip();
• MCU_RST
To reset the whole chip
49
SYS_UnlockReg(); NVIC_SystemReset();
RSTSRC (System Reset Source Register)
Register Address R/W Description Reset Value
52
IPRSTC2(Peripheral Reset Control Register 1 )
Register Offset R/W Description Reset Value
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
Reserved
7 6 5 4 3 2 1 0
53
IPRSTC2(Peripheral Reset Control Register 2 )
Register Offset R/W Description Reset Value
31 30 29 28 27 26 25 24
USBD_RST Reserved
Reserved ADC_RST
23 22 21 20 19 18 17 16
15 14 13 12 11 10 9 8
7 6 5 4 3 2 1 0
•Set these bit “1” will generate asynchronous reset signal to the correspond IP.
•User need to set bit to “0” to release IP from the reset state
54
Clock Control
56
Clock Control
57
IRC TRIM (SYS_IRCTCTL)
• SYS_IRCTCTL : IRC Trim Control Register
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
CLKERR_
Reserved
STOP_EN
7 6 5 4 3 2 1 0
TRIM_RETRY_CNT TRIM_LOOP Reserved TRIM_SEL
7 6 5 4 3 2 1
RETRYCNT LOOPSEL Reserved FREQSEL
60
C ISR Function Call Name
61
General Purpose I/O Controller
• GPIO type
• Quasi-bidirectional
• Push-Pull output
• Open-Drain output
• Input only with high impendence
• Configurable default I/O mode of all pins after reset by Config0[10] setting
• 0 : all GPIO pins in input tri-state mode after chip reset
• 1 : all GPIO pins in Quasi-bidirectional mode after chip reset
• Support GPIO interrupt for each I/O PIN
• Level trigger or Edge trigger
Input Mode
CMOS Output
VDD
Port Pin
Port Latch N
Data
Input Data
Open-Drain Output
Port Latch N
Data
Input Data
Quasi-bidirectional
2 CPU
P P Very P
Clock Delay Strong
Weak
Weak
Port Pin
Port Latch N
Data
Input Data
PWRCON Register (Bit Field Definition)
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
7 6 5 4 3 2 1 0
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
PRIMASK = value Assign value to Priority Mask Register (using the instruction MSR)
(uint32_t value)
uint32_t __get_PRIMASK
return PRIMASK Return Priority Mask Register (using the instruction MRS)
(void)
void __set_CONTROL
CONTROL = value Set CONTROL register value (using the instruction MSR)
(uint32_t value)
uint32_t __get_CONTROL
return CONTROL Return Control Register Value (using the instruction MRS)
(void)
uint32_t __get_PSP (void) return PSP Return Process Stack Pointer (using the instruction MRS)
uint32_t __get_MSP (void) return MSP Return Main Stack Pointer (using the instruction MRS)
78
Cortex-M0 Instruction Access
Function Name CPU Instruction Description
uint32_t __REV (uint32_t value) REV Reverse byte order in integer value.
79
NVIC Setup Function Call
Function Name Parameter Description
void NVIC_SetPriorityGrouping (uint32_t Set the Priority Grouping (Groups .
Priority Grouping Value
PriorityGroup) 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
IRQ Number Return 1 if IRQn is pending else 0
IRQn)
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,
IRQ Number, Priority Set Priority for IRQn
uint32_t priority)
uint32_t NVIC_GetPriority (IRQn_Type IRQn) IRQ Number Get Priority for IRQn
uint32_t NVIC_EncodePriority (uint32_t IRQ Number, Priority Group,
Encode priority for given group,
PriorityGroup, uint32_t PreemptPriority, Preemptive Priority, Sub
preemptive and sub priority
uint32_t SubPriority) Priority
IRQ Number, Priority,
NVIC_DecodePriority (uint32_t Priority, uint32_t pointer to Priority Group,
Decode given priority to group,
PriorityGroup, uint32_t* pPreemptPriority, pointer to Preemptive
preemptive and sub priority
uint32_t* pSubPriority) Priority, pointer to Sub
Priority
void NVIC_SystemReset (void) (void) Resets the System
80
NuMicro
NUC029 SDK
A Leading MCU Platform Provider
Disc Content Introduction
82
Software Installation
88
Resource
• BSP (Board Support Package):
- https://www.nuvoton.com/opencms/system/modules/com.thesys.opencms.nuvoton/pages/download/download.jsp?file=http://www.nuv
oton.com/hq/resource-download.jsp?tp_GUID=SW0120180713155423&version=V3.00.001
• Data Sheet:
- http://www.nuvoton.com/resource-files/DS_NUC029xEE_EN_Rev1.00.pdf
• NuTiny-SDK_NUC029SEE_V1.01:
- Schematic:
https://www.nuvoton.com/opencms/system/modules/com.thesys.opencms.nuvoton/pages/download/download.jsp?file=http://w
ww.nuvoton.com/hq/resource-download.jsp?tp_GUID=HL0320181017105843&version=1.01
• DVD Content:
- http://www.nuvoton.com/NuMicroDVD/
89
Thank you!