Beruflich Dokumente
Kultur Dokumente
STM32VL- Training
CONTENTS
PART I : CORTEX-M3
-CSF-Training-
PART - I
-CSF-Training-
CORTEX M3
CONTENTS
Objectives Introduction Cortex-M3 Processor Cortex M3 interrupt handling Cortex-M3 Memory Map Power Management System Timer (SysTick) Debug Capabilities
-CSF-Training-
OBJECTIVES
-CSF-Training-
Familiarize with Cortex M3 At the end of the part you will be able to List the main features of the Cortex M3
CONTENTS
Objectives Introduction Cortex-M3 Processor Cortex M3 interrupt handling Cortex-M3 Memory Map Power Management System Timer (SysTick) Debug Capabilities
-CSF-Training-
-CSF-Training-
-CSF-Training-
-CSF-Training-
Cortex-A Series, applications processors for complex OS and user applications. Cortex-R Series, real-time systems profile. Cortex-M Series, microcontroller profile optimized for cost-sensitive applications..
The number at the end of the Cortex name refers to the relative performance level, with 1 the lowest and 8 the highest.
9
-CSF-Training-
10
CONTENTS
Objectives Introduction Cortex-M3 Processor Cortex M3 interrupt handling Cortex-M3 Memory Map Power Management System Timer (SysTick) Debug Capabilities
-CSF-Training-
11
Cortex-M3 Processor
Interrupt controller: -1 to 240 interrupts. - 256 Priority levels - Hard Fault -SysTick (Porting !!!) Wakup Int. controller: Wakeup from Sleep modes throuht interrupts & exceptions Debug Access port
-CSF-Training-
4 Watch points 8 Hardware Breakpoints Multi layer Bus Matrix (Parallel transfers between core, memory, & peripherals
12
Cortex-M3 Processor
-CSF-Training-
Harvard architecture
Separate I & D buses allow parallel instruction fetching & data storage
Integrated Nested Vectored Interrupt Controller (NVIC) Vector Table is addresses. Integrated Bus Matrix Data memory management 3 Stage Pipeline Integrated System Timer (SysTick) for Real Time OS
13
-CSF-Training-
These technologies can dramatically improve data (SRAM) memory utilization, potentially enabling silicon designers and users to reduce the amount of SRAM required and dramatically impacting silicon usage.
14
-CSF-Training-
15
-CSF-Training-
long (32) char (8) long long (32) char (8) char (8) char (8) long (32) int (16)c int (16) long
Data aligned
int (16) long (32) int (16)c int (16) long (32) char (8)
char (8)
long (32)
16
-CSF-Training-
0 1 0 0 1 0 1 1
Mask and modify bit element
b0
X X X X X 1 X X
Write byte (RAM, register)
b31
0 1 0 0 1 1 1 1 b0
Enable external events
Bit Banding done by bus matrix. Single instruction Read/Modify/Write (no more masking). No new instruction set Use standard data one (AND, OR, XOR). Optimized RAM, peripherals and IOs registers accesses Easy multi-task semaphore management
17
-CSF-Training-
18
-CSF-Training-
Each bit of the bit band region (1MB) is mapped to one 32 bit address (32 MB Bit Band Alias = Virtual zone ). Each bit in the Bit Band region can be accessed separately through the corresponding 32 bits register in the alias region.
19
-CSF-Training-
bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number 4) where: bit_word_addr: is the address of the word in the alias memory region that maps to the targeted bit. bit_band_base is the starting address of the alias region (0x22000000 or 0x42000000 ) byte_offset is the number of the byte in the bit-band region that contains the targeted bit bit_number is the bit position of the targeted bit(0-7).
20
-CSF-Training-
How to map bit 15 of the byte located at address 0x40000300 in the alias region. Solution: We are accessing the peripheral bit band region beginning at 0x 0x40000000 and mapped to the bit band alias zone with bit_band_base = 0x42000000
Byte_offset = 0x40000300 - 0x40000000 = 0x300 0x42000000 + ( 0x301*32) + (7 * 4) = 0x4200603C =bit_word_addr Reading address 0x4200603C returns the value of bit 15 of the byte at address 0x40000300. Writing to address 0x4200609C has the same effect as a readmodify-write operation on bit 15 of the byte at address 0x40000300.
21
Instruction Pipeline(1/3)
PC points to fetch stage:
FETCH
Instruction fetched from memory
-CSF-Training-
DECODE
Instruction decoded
EXECUTE
Shift and ALU operation or memory access Write register(s) back to Register Bank
22
Instruction Pipeline(2/3)
Optimal Pipelining:
Cycle Operation ADD SUB ORR AND ORR EOR F- Fetch D - Decode F D F E D F E D F E D F E D F E - Execute E D E 1 2 3 4 5 6 7 8 9
-CSF-Training-
All operations here are registers (single cycle execution) In this example it takes 6 cycles to execute 6 instructions Clock cycles per Instructions (CPI) = 1
23
Instruction Pipeline(3/3)
Flushing : A flush of the pipeline can occur because of
A Branch An exception A breakpoint Branch Pipeline Example:
1 F D F E D F F D F E D F F- Fetch D - Decode E - Execute E D E 2 3 4 5 6 7 8
-CSF-Training-
Cycle Address Operation 0x8000 B 0x8FEC 0x8002 0x8004 0x8FEC 0x8FEE 0x8FF0 SUB ORR AND ORR EOR
24
Register Set(1/2)
Registers R0-R12 are simple registers that can be used to hold program variables. Registers R13-R15 have special functions within the Cortex CPU.
R13: Register R13 is used as the stack pointer R14: called the link register. used to store the return address when a call is made to a procedure R15: is the program counter
Register Set
R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13(SP) R14(LR) R15 (PC) xPSR
-CSF-Training-
xPSR:The Program Status Register contains status fields for instruction execution
25
CONTENTS
Objectives Introduction Cortex-M3 Processor Cortex M3 interrupt handling Cortex-M3 Memory Map System Timer (SysTick) Debug Capabilities
-CSF-Training-
26
Interrupt Handling
The Cortex-M3 processor integrates an advanced Nested Vectored Interrupt Controller (NVIC)
The NVIC supports up to 240 dynamically reprioritizes interrupts each with up to 256 levels of priority Supports advanced features for next generation real-time applications: Tail-chaining of pending interrupts Interrupt Pre-emption Late Arrival
-CSF-Training-
27
-CSF-Training-
ISR 1
POP 16
PUSH 26
ISR 2
POP 16
Interrupt handling in HW
Cortex-M3
PUSH 12
ISR 1 6 6 CYCLES
ISR 2
POP 12
ARM7 26 cycles from IRQ1 to ISR1 entered Up to 42 cycles 42 cycles from ISR1 exit to ISR2 entry 16 cycles to return from ISR2
Cortex-M3 12 cycles from IRQ1 to ISR1 entered 12 cycles 6 cycles from ISR1 exit to ISR2 entry 12 cycles to return from ISR2
28
-CSF-Training-
PUSH 2 26 ISR 2 6
ISR 2
POP 16
POP 12
7-18 CYCLES
29
-CSF-Training-
PUSH 26 ISR 1
TailChaining
ISR 1
POP 16
ISR 2
POP 16
ISR 2 6
POP 12
30
-CSF-Training-
NMI
ISR 1
POP
ISR 2
ISR 3
POP
ISR 2 Starts
Cortex-M3 Following NMI processor tail-chains into ISR1 ISR2 Completed Pop only occurs on return to Main
31
NVIC Registers
Each interrupt input has several registers to control it Enable/Disable Bit
Enable or disable the interrupt Can be set, cleared or read
-CSF-Training-
Pending Bit
If the pending bit is set, then the interrupt is pending A pending interrupt can only be taken (become active) if it is enabled and it has sufficient priority to run
-CSF-Training-
MPU violation or access to illegal locations Fault if AHB interface receives error Exceptions due to program errors
33
CONTENTS
Objectives Introduction Cortex-M3 Processor Cortex M3 interrupt handling Cortex-M3 Memory Map Power Management System Timer (SysTick) Debug Capabilities
-CSF-Training-
34
-CSF-Training-
35
CONTENTS
Objectives Introduction
What is ARM ? Why use an ARM-based processor? Cortex-M3 Processor Main Features Data Memory Instruction Pipeline Write Buffer
-CSF-Training-
Cortex-M3 Processor
Cortex-M3 Memory Map Power Management System Timer (SysTick) Debug Capabilities
36
Debug Capabilities
Three solutions are possible :
JTAG SWD
-CSF-Training-
ETM
37
PART - II
-CSF-Training-
STM32F10x Device
38
CONTENTS
Objectives STM32F10x Device
Block Diagram Memory mapping and boot modes System Architecture
-CSF-Training-
OBJECTIVES
Familiarize with STM32F10x device At the end of the training you will be able to
-CSF-Training-
List the main features of the STM32F10x system peripherals Configure the standard library environment Develop your applications using the STM32F10x standard library
40
CONTENTS
Objectives STM32F10x Device
Block Diagram Memory mapping and boot modes System Architecture
-CSF-Training-
-CSF-Training-
42
-CSF-Training-
43
-CSF-Training-
CORTEXTM-M3 CPU
24 MHz ARM Lite Hi-Speed Bus Matrix / Arbiter (max 24MHz)
Power Supply
Reg 1.8V
JTAG/SW Debug
Nested vect IT Ctrl
Int. RC oscillators
40KHz + 8MHz
Rich connectivity
5 communications peripherals
1 x Systick Timer
Advanced analog
12-bit1.2 s conversion time ADC Dual channel 12-bit DAC
DMA
7 Channels
Enhanced control
16-bit motor control timer 5x 16-bit PWM timers
Synchronized AC Timer
5 x 16-bit timer
(max 24MHz)
1 x CEC
2 x Watchdog
(independent & window)
1 x USART/LIN
Smartcard / IrDa Modem Control
LQFP48, LQFP/BGA64
1 x SPI 1 x USART/LIN
Smartcard/IrDa Modem Control
44
-CSF-Training-
Power Supply
Reg 1.8V
JTAG/SW Debug
Nested vect IT Ctrl
Int. RC oscillators
40KHz + 8MHz
Rich connectivity
8 communications peripherals
Advanced analog
12-bit1.2 s conversion time ADC Dual channel 12-bit DAC
1 x 16-bit PWM
Synchronized AC Timer
1 x CEC
Enhanced control
16-bit motor control timer 6x 16-bit PWM timers
2 x Watchdog
(independent & window)
2 x USART/LIN
Smartcard / IrDa Modem Control
1 x USART/LIN
Smartcard/IrDa Modem Control
1 x SPI 2 x I 2C
45
-CSF-Training-
Power Supply
Reg 1.8V
POR/PDR/PVD
XTAL oscillators
32KHz + 4~25MHz
JTAG/SW Debug
Nested vect IT Ctrl
Int. RC oscillators
40KHz + 8MHz
Rich connectivity
11 communications peripherals
1 x Systick Timer
FSMC
SRAM/ NOR/ LCD parallel interface
PLL
DMA up to 12 Channels
RTC / AWU
FSMC
SRAM, NOR, memories support. LCD Parallel interface 8/16-bit Intel 8080 and Motorola 68K
1 x 16-bit PWM
Synchronized AC Timer
Enhanced control
16-bit motor control timer 10x 16-bit PWM timers
1 x CEC
(max 24MHz)
4 x USART/LIN
2-channel 12-bit DAC
Smartcard / IrDa Modem Control
1 x USART/LIN
Smartcard/IrDa Modem Control
2 x SPI 2 x I2C
Temperature Sensor
46
-CSF-Training-
Boot modes:
Depending on the Boot configuration - Embedded Flash Memory - System Memory - Embedded SRAM Memory is aliased at @0x00
BOOT Mode Selection Pins BOOT1 x 0 BOOT0 0 1 1 User Flash User Flash is selected as boot space SystemMemory is selected as boot space Embedded SRAM is selected as boot space
0xE000 0000
Reserved
Boot Mode
Aliasing
0x1FFF F000
Reserved
0x4000 0000
Peripherals Reserved
Flash
0x0801 FFFF
0x0800 0000
0x2000 0000
SRAM Reserved
0x0000 0000
CODE
47
-CSF-Training-
System memory
The CPU executes the boot loader: 1) Data packets containing code are Received through through serial peripheral (UART). The Flash is reprogrammed with the new received code
CPU
(Boot Loader)
UART
Bus Matrix
2)
48
CONTENTS
Objectives STM32F10x Device
Block Diagram Memory mapping and boot modes System Architecture
-CSF-Training-
-CSF-Training-
Power Supply
Reg 1.8V
POR/PDR/PVD
XTAL oscillators
32KHz + 4~25MHz
JTAG/SW Debug
Nested vect IT Ctrl
Int. RC oscillators
40KHz + 8MHz
1 x Systick Timer
FSMC
SRAM/ NOR/ LCD parallel interface
PLL
DMA up to 12 Channels
RTC / AWU
1 x 16-bit PWM
Synchronized AC Timer
1 x CEC
(max 24MHz)
4 x USART/LIN
2-channel 12-bit DAC
Smartcard / IrDa Modem Control
2 x SPI 2 x I2C
Temperature Sensor
50
-CSF-Training-
51
Power Supply
Power Supply Schemes
VDD = 2.0 to 3.6 V: External Power Supply for I/Os and the internal regulator. VDDA = 2.0 to 3.6 V: External Analog Power supplies for ADC, Reset blocks, RCs and PLL. ADC working only if VDDA 2.4 V VBAT = 1.8 to 3.6 V: For Backup domain when VDD is not present.
VBAT
-CSF-Training-
VDDA domain
VREFVREF+ VDDA VSSA A/D converter Temp. sensor Reset block PLL
VDD domain
I/O Rings STANDBY circuitry (Wake-up logic, IWDG, RCC CSR reg) Voltage Regulator
V18 domain
VSS VDD
Backup domain
LSE crystal 32K osc BKP registers RCC BDCR register RTC
52
-CSF-Training-
VDD
Vtrh Vtrl
POR
40mv hysteresis
PDR
Tempo 2ms
Reset
53
-CSF-Training-
PVD Threshold
100mv hysteresis
PVD Output
Threshold
54
-CSF-Training-
STM32F10x typ
4.9mA 36mA 27mA 14A
(*)
2A 1.4 A
(*) : Typical
CONTENTS
Objectives STM32F10x Device
Block Diagram Memory mapping and boot modes System Architecture
-CSF-Training-
What is CMSIS?
Definition:
-CSF-Training-
The Cortex-M3 Microcontroller Software Interface Standard (CMSIS) is defined in close cooperation with various silicon and software vendors and provides a common approach to interface to peripherals, real-time operating systems and middleware components. For more details, please refer to www.onarm.com.
57
Package organization
-CSF-Training-
58
-CSF-Training-
Cortex-M3 exceptions
Low-level & API functions to Perform basic operations offered by the peripheral
59
-CSF-Training-
1) Before configuring a peripheral, you have to enable its clock by calling one of the
2) PPP_DeInit(..) function can be used to set all PPPs peripheral registers to their reset values: PPP_DeInit(PPPx); 3) If after peripheral configuration, the user wants to modify one or more peripheral settings he should proceed as following: PPP_InitStucture.memberX = valX; PPP_InitStructure.memberY = valY; PPP_Init(PPPx, &PPP_InitStructure);
60
-CSF-Training-
At this stage the PPP peripheral is initialized and can be enabled by making a call to PPP_Cmd(..) function: PPP_Cmd(PPPx, ENABLE); Note: This function is used only for communication peripherals like UART, SPI, To access the functionality of the PPP peripheral, the user can use a set of dedicated functions. These functions are specific to the peripheral and for more details refer to STM32F10x Firmware Library User Manual.
61
-CSF-Training-
RCC_APB2PeriphClockCmd( USART1, ENABLE ); /* set all UART1s peripheral registers to their reset values */ USART_DeInit( USART1 ) ;
/* USART1 configuration ------------------------------------------------------*/ /* USART1 configured as follow: - BaudRate = 19200 baud - Word Length = 8 Bits - One Stop Bit - Even parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */
USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USART1 */
-CSF-Training-
main.c
stm32f10x_It.h
stm32f10x.h
/* Uncomment the line below according to the target STM32 device used in your application */ #if !defined (STM32F10X_LD) && !defined (STM32F10X_MD) && !defined (STM32F10X_HD) /* #define STM32F10X_LD */ /*!< STM32 Low density devices */ #endif /* STM32F10x Interrupt Number Definition*/
EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */ EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */ DMA1_Channel1_IRQn = 11, /*!< DMA1 Channel 1 global Interrupt */
/* Exported functions ----------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); stm32f10x_It.c #include "stm32f10x_it.h" void EXTI1_IRQHandler(void) { GPIO_WriteBit(GPIOD, GPIO_Pin_1, Bit_SET); }
63
PART - III
-CSF-Training-
64
-CSF-Training-
65
-CSF-Training-
In circuit ST-LINK debugger / programmer included to debug Discovery kit applications or other target board applications. Ideal for quick evaluation, learning or prototyping Dedicated web site www.st.com/stm32-discovery
Examples ready to run Schematics Forums and more
66
-CSF-Training-
84mm
42mm
67
-CSF-Training-
Software examples available at www.st.com/stm32-discovery for a quick start to evaluate and develop with the STM32 Value line
68
-CSF-Training-
Self powered by USB cable between PC and STM32 Value line Discovery Can supply target application with 5 V and 3 V On-board ST-Link with USB interface for programming and debugging Selection mode switch to use the kit as a standalone ST-Link (with SWD connector) Extension header for all QFP64 I/Os Development toolchains from partners Large number of free, downloadable ready-touse software examples
More than 37 Videos are available on YouTube web site. example: link : http://www.youtube.com/watch?v=5Si0tgqrAd0
69
-CSF-Training-
STM32F10x Standard Peripheral Library V3.3.0: STM32 value Line Firmware library, examples AN3268 (STM32VLDISCOVERY firmware package): STM32 discovery Firmware library UM0919 (STM32VLDISCOVERY STM32 value line Discovery): STM32 discovery board description, schematics UM0985 (Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software): Tools description...
70
Contact us
-CSF-Training-
71
-CSF-Training-
72
Thank you
-CSF-Training-
73