1 basics of exceptions cortex m4 core peripherals
play

1 Basics of Exceptions Cortex-M4 Core Peripherals System Control - PowerPoint PPT Presentation

1 Basics of Exceptions Cortex-M4 Core Peripherals System Control Block (SCB) SCB Registers SysTick Timer Registers Configuration Code Example Nested Vectored Interrupt Controller (NVIC) Exception/Interrupt


  1. 1

  2. � Basics of Exceptions � Cortex-M4 Core Peripherals › System Control Block (SCB) � SCB Registers › SysTick Timer � Registers � Configuration � Code Example › Nested Vectored Interrupt Controller (NVIC) � Exception/Interrupt Vector Table � Exception States � NVIC Registers 2

  3. � Handling External Interrupts › System Configuration Controller (SYSCFG) � SYSCFG external interrupt configuration registers (EXTICRx) › Extended Interrupts and Events Controller (EXTI) � EXTI0 › Registers › EXTI0 Configuration › EXTI0 Code Example � COMP › Registers › Configuration › Code Example 3

  4. 4

  5. • situations where the Exceptions processor needs to stop executing the current code • asynchronous • synchronous Software Hardware • also called • also called interrupts exceptions Debug System Nonmaskable Maskable Fault event service call • cannot be • can be • related to an • used by operating ignored ignored error condition systems • signaled via • signaled via • caused by the SVC RESET or NMI IRQ instruction 5

  6. � What is an exception? A special event that requires the CPU to stop normal › program execution and perform some service related to the event. Examples of exceptions include › I/O completion, timer time-out, end of conversion, � � illegal opcodes, arithmetic overflow, divide-by-0, etc. � Functions of exceptions Respond to infrequent but important events › � Alarm conditions like low battery power � Error conditions I/O synchronization › � Trigger interrupt when signal on a port changes Periodic interrupts › � Generated by the timer at a regular rate � Systick timer can generate interrupt when it hits zero Reload value + frequency determine interrupt rate � 6

  7. polling interrupt 7

  8. � Interrupt maskability Interrupts that can be ignored by the CPU are called maskable › interrupts. A maskable interrupt must be enabled before it can interrupt the › CPU. An interrupt is enabled by setting an enable bit. › Interrupts that can’t be ignored by the CPU are called › nonmaskable interrupts. � Exception priority Allow multiple pending interrupt requests › Resolve the order of service for multiple pending interrupts › � Interrupt service routine An interrupt handler, also known as an Interrupt Service Routine › (ISR), is a callback subroutine in microcontroller firmware whose execution is triggered by the reception of an interrupt. Interrupt handlers have a multitude of functions, which vary › based on the reason the interrupt was generated. 8

  9. STM32 Vector Table 0x0000 � Interrupt vector Initial Value of SP 0x0004 Vector for Exception 1 Starting address of the interrupt › (0X8000) handler 0x0008 Vector for Exception 2 � Interrupt vector table (0X8200) 0x000C Vector for Exception 3 table of interrupt vectors that › 0x0010 associates an interrupt handler Interrupt Vector for Exception 4 with an interrupt request � Methods of determining interrupt 0x8000 vectors Predefined locations (Microchip › Exception 1Handler PIC18, 8051 variants) Fetching the vector from a › predefined memory location 0x8200 (HCS12, STM32) Executing an interrupt › Exception 2 Handler acknowledge cycle to fetch a vector number in order to locate the interrupt vector (68000 and x86 families) 9

  10. A complete interrupt service cycle includes � Saving the program counter value in the stack � Saving the CPU status (including the CPU status overhead register and some other registers) in the stack � Identifying the cause of interrupt � Resolving the starting address of the corresponding interrupt service routine � Executing the interrupt service routine � Restoring the CPU status and the program overhead counter from the stack � Restarting the interrupted program 10

  11. Interrupt is a powerful concept in embedded systems for � separating the time-critical events from the others and execute them in a prioritized manner. In a typical embedded system, the embedded processor � (microcontroller) is responsible for doing more than one task (but can do only one at a time). Programmable Room Temperature Control 11

  12. A thermoelectric cooler (TEC) is a device based on the Peltier effect. It typically comprises two kinds of materials and transfers heat from one side of the device to the other while a DC current is forced through it. The side from which heat is removed becomes cold. Contrastingly, the side to which heat is moved becomes hot. When the current reverses its direction, the previously "cold" side becomes hot and the previously "hot" side becomes cold. A TEC has no moving parts or working fluids, so it is very reliable and can be very small in size. TECs are used in many applications that require precision temperature control, including optical modules. 12

  13. 13

  14. Cor e pe r iphe r al De sc r iption It provides system implementation information and System Control control. In particular It supports e xc e ption Block configuration, control, and processing. Nested Vectored It supports low latency inte r upt configuration, control, r Interrupt and processing. Controller Use this 24-bit count-down timer as a Real Time System timer Operating System (RTOS) tick timer or as a simple (SysTick) counter. Memory It improves system reliability by defining the memory Protection Unit attributes for different memory regions. Floating-point It provides IEEE754-compliant operations on single- Unit precision, 32-bit, floating-point values. STM32F3 Microcontroller Programming Manual, pages 180-241 14

  15. 15

  16. Provides: � Exception enables. � Setting or clearing exceptions to/from the pending state. � Exception status (Inactive, Pending, or Active). Inactive is when an exception is neither Pending nor Active. � Priority setting (for configurable system exceptions) � The exception number of the currently executing code and highest pending exception. STM32F3 Microcontroller Programming Manual, pages 206-227 16

  17. IRQ # -14 -13 -12 -11 -10 Exceptions -09 -08 -07 -06 -05 -04 -03 -02 -01 00 01 02 03 04 05 06 startup_stm32f30x.s 17

  18. E xc IRQn E xc e ption Pr ior ity De sc r iption Ve c tor No. T ype Addr e ss Initial SP 0 Reset -3 (F) Reset 0x04 1 -14 NMI -2 (F) Non-Maskable Interrupt 0x08 2 Default fault if other handler not 0x0C -13 HardFault -1 (F) 3 implemented -12 MemManage 0 (P) MPU violation or access to illegal 0x10 4 locations Fault if AHB interface receives error 0x14 -11 BusFault 1 (P) 5 Exception due to program errors 0x18 -10 UsageFault 2 (P) 6 Reserved 7-10 System service call via SWI instruction 0x2C -5 SVCall 3 (P) 11 Break points, watch points, external 0x30 -4 Debug 4 (P) 12 debug Monitor -3 Reserved 13 -2 PendSV 4 (P) Pendable request for System Device 0x38 14 System tick timer 0x3C -1 SysTick 6 (P) 15 These exceptions are controlled by the System Control Block (SCB). • If the priority of an exception is programmable, its default value is zero. • 18

  19. Name De sc r iption Ope r ation disables certain aspects of functionality within • ACT L R Auxiliar y the processor. Contr ol Re giste r specifies the ID and version numbers, and • CPUID CPUID Base the implementation details of the processor Re giste r core. Used to: ICSR Inte r r upt Contr ol set a pending No n-Maskable I nte rrupt (NMI) • State Re giste r set or clear a pending PendSV • set or clear a pending SysTick • check for pending exceptions • check the vector number of the highest • priority pended exception check the vector number of the active • exception. indicates the offset of the vector table base • VT OR Ve c tor T able address from memory address 0x00000000. Offse t Re giste r 19

  20. Name De sc r iption Ope r ation provides priority grouping control for the • AIRCR Applic ation exception model, endian status for data Inte r r upt and accesses, and reset control of the system. Re se t Contr ol Re giste r controls features of entry to and exit from low • SCR Syste m Contr ol power state. Re giste r permanently enables stack alignment and • CCR Configur ation causes unaligned accesses to result in a and Contr ol Hard Fault. Re giste r set the priority level of the exception • SHPRx Syste m handle r handlers that have configurable priority. pr ior ity r e giste r s 20

  21. � The SCB_AIRCR provides priority grouping control for the exception model, endian status for data accesses, and reset control of the system. � To write to this register, you must write 0x5FA to the VECTKEY field, otherwise the processor ignores the write. STM32F3 Microcontroller Programming Manual, page 211 21

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend