MCU Kornilin
MCU Kornilin
1
Main problems
2
ARM ARCHITECTURES
3
NXP CPUs for laboratories
• LPC2148 ARM7TDMI
• LPC2388
• LPC1768 CORTEX-M3
• LPC1114 CORTEX-M0
4
LPC2142/44/46/48 Block Diagram 64-pin LQFP
RST
Vdd
TRST
Vss
16-32KB 64-512 KB
TMS
TDO
TCK
X1
X2
TDI
SRAM FLASH
System Clock PLL1 System
Test/Debug ETM
PLL2 Functions
USB Clock
SRAM Memory
ARM 7TDMI-S BrownOutDetect
Controller Accelerator VIC PowerOnReset
Local Bus AMBA AHB Bus
D+
AHB to 8 KB SRAM USB 2.0 Full D-
32 kHz shared w/ DMA
Real Time Watchdog VPB Speed Device Up_LED OR
(LPC2148 only) Connect
Vbat
Clock Timer Bridge w/ DMA Vbus
I2C 0/1 SPI Port SSP Port UART0/1 ADC 0/1 DAC Fast I/O Timer0/1 PWM
PWM1 - 6
Tx/RX 0,1
CAP x 8
MAT x 8
6+8 pins
1-10-bit
pins (6)
Modem
46 max
GPIO
SDA
SSEL
SSEL
SCK
MOSI
MOSI
SCL
MISO
MISO
SCK
5
6
7
ARM7TDMI CORE
8
9
ARM/Thumb interaction
10
ARM7TDMI Processor Modes
ARM has seven operating modes
– User unprivileged mode under which most applications run
– FIQ entered, when a high priority (fast) interrupt is raised
– IRQ general purpose interrupt handling
– Supervisor protected mode for the operating system
entered on reset or software interrupt
instruction
– System privileged mode using the same registers as user
mode
– Abort used to handle memory access violations
– Undefined used to handle undefined instructions
11
Exception Vectors
• Vector Table
.
.
.
0x1C FIQ
0x18 IRQ
Valid user program key:
0x14 (Reserved) Must contain a value that
Data Abort ensures that the checksum of
0x10
all vectors is zero
0x0C Prefetch Abort
0x08 Software Interrupt
0x04 Undefined Instruction
0x00 Reset
12
CORTEX MCU Modes
13
CORTEX Operation modes
14
15
User and System
r0 Register Banking
r1
r2
r3
r4
Banked registers
r5
r6 FIQ IRQ Supervisor Abort Undefined
r7
r8 r8_fiq
r9 r9_fiq
r10 r10_fiq
r11 r11_fiq
r12 r12_fiq
r13 (SP) r13_fiq (SP) r13_irq (SP) r13_svc (SP) r13_abt (SP) r13_und (SP)
r14 (LR) r14_fiq (LR) r14_irq (LR) r14_svc (LR) r14_abt (LR) r14_und (LR)
r15 (PC)
CPSR
SPSR_fiq SPSR_irq SPSR_svc SPSR_abt SPSR_und
16
17
Load-And-Store Architecture
18
19
ARM7TDMI Memory Map
4.0 GB
AHB Peripherals 0xFFFF FFFF
3.75 GB 0xF000 0000
VPB Peripherals 0xEFFF FFFF
3.5 GB 0xE000 0000
20
21
Memory Accelerator Module
Address Bus
ARM7
Bus Interface
Core
Flash Memory Flash Memory
Bank 1 Bank 2
Data Buffer
Selection
22
Phase Locked Loop (LPC21xx/22xx)
FOSC
XTAL1 FCCO
Current cclk
Phase
Oscillator Controlled ÷P
Detector
Oscillator
XTAL2 Divider
Value Default: 4
10 to 25 MHz
VPB pclk
1 to 30 MHz ÷M Divider
without PLL ÷ 1/2/4
Multiplier Value
23
Handling of the exceptions
24
Exception / Interrupt Handling
• Entering an exception the ARM core
– saves the address of the next instruction in the appropriate LR
PC + 4 or PC + 8
r15 (PC) r14_<mode> (LR)
CPSR: mode
• mode field bits I F T
25
Leaving Exception
• To leave an exception, the exception handler must
– copy SPSR back into CPSR
SPSR_<mode> CPSR
CPSR: I F T mode
Control bits
PC - offset
r14_<mode> (LR) r15 (PC)
26
Multiple Exceptions
• Exception priorities
– When multiple exceptions arise at the same time, a fixed priority
system determines the order in which they are handled
27
Vectored Interrupt Controller
FIQStatus
Interrupt Source FIQ
FIQ
IntEnableClear
RawInterrupt
32
IntEnable
High Priority
OR VectorCntl
SoftIntClear
En Channel VICVectorAddr 0
SoftInt
IRQStatus 5 0:4
IRQ
...
16 Prioritized
32
Low Priority
28
CORTEX’s NVIC
29
30
Peripherals
31
Pin Connect Block
• Many on-chip functions can use I/O pins
• Number of I/O-pins is limited
32
General Purpose I/O
Register
IOxPIN The current state of the port pins is read from this register
IOxSET Writing "1" sets pins high, writing "0" has no effect
IOxCLR Writing "1" sets pins low and clears corresponding bits in IOSET
8/27/2018
33
TIMERS
34
PWM
InitPWM ():
PWMMR0 = 0x000FFFFF;→PWMMR0 = 0x00000FFF;.
35
Real Time Clock
• Full Clock/Calendar function with alarms
– Generates its own 32.768 kHz reference clock from any crystal
frequency
– Counts seconds, minutes, hours, day of month, month, year, day of
week and day of year
– Can generate an interrupt or set an alarm flag for any combination
of the counters
36
Real Time Clock
PCLK
Clock Divider
(prescaler)
Time Alarm
Comparators
Counters Registers
Clock
37
Watchdog Timer
Watchdog Timer
WDFEED Constant
UNDERFLOW
Current Timer Count
(WDTC)
40
41
Interfaces
• SPI
• I2C
• I2S
• RS-232/RS-485
• Ethernet
• USB
• CAN
42
Programming tips
43
44
45
C/C++ basics
• C file usually has .c extension
• C++ file usually has .cpp extension
• Any program should have main function
int main(void)
{
Code here;
}
46
C/C++ basics
• All used functions has to be preliminary
declared – int main(void);
• Program can include header file with .h
extension, containing declarations
• All used variables should be anywhere
declared
• Variables, declared inside the function, are
available only within that function
47
C/C++ basics
• C++ can use structures, that include sets
of data - variables and functions
• C/C++ can operate with the pointers =
addresses of the data/functions
• Symbol * denotes, that it is a pointer
• Symbol & before the name denotes the
link (address will be used instead of the
value)
48
C/C++ notations
• X++ equals to X=X+1
• X-- equals to X=X-1
• X op=N equals to X=X op N
• !X equals NOT X (logical)
• (A==B) is TRUE, then operands are equal
• X&Y Bitwise operation X AND Y
• X^Y Bitwise operation X XOR Y
• X|Y Bitwise operation X OR Y
• ~X Bitwise operation NOT X
49
C/C++ notations
• Static means, that variable keeps its value always,
till the program is being executed
• Extern means, that the function is defined outside
the current file
• 0xNNN represents hexadecimal value
• 123…45 represents decimal value
• __fiq FIQ handler
• __irq IRQ handler
• __arm to be compiled in ARM instruction set
50
Thank you for your attention !
Good luck in your trainings !
51