About

Work - Learn - Share

Lê Quang Thành : quangthanh010290@gmail.com | thanhlev@amazon.com.vn

Tiva ™ TM4C123GH6ZRB Microcontroller [phần 2]

Table of contents

  1. Tiva ™ TM4C123GH6ZRB Microcontroller [phần 2]
    1. Block Diagram
    2. Programming Model
      1. Processor Mode and Privilege Levels for Software Execution
      2. Stacks
      3. Register Map
      4. Register Descriptions
        1. Register 14: Stack Pointer (SP)
        2. Register 15: Link Register (LR)
        3. Register 16: Program Counter (PC)
        4. Register 17: Program Status Register (PSR)
    3. Memory Model
      1. Memory Regions, Types and Attributes
      2. Data Storage
    4. Exception Model
      1. Exception States
      2. Exception Types
      3. Exception Handlers
      4. Vector Table
      5. Exception Priorities
      6. Exception Entry and Return
        1. Exception Entry

Block Diagram

cpu_block_diagram

Programming Model

Processor Mode and Privilege Levels for Software Execution

The Cortex-M4F has two modes of operation:

the Cortex-M4F has two privilege levels:

In Thread mode, the CONTROL register (see page 89) controls whether software execution is privileged or unprivileged. In Handler mode, software execution is always privileged

Only privileged software can write to the CONTROL register to change the privilege level for software execution in Thread mode. Unprivileged software can use the SVC instruction to make a supervisor call to transfer control to privileged software

Stacks

The processor uses a full descending stack, meaning that the stack pointer indicates the last stacked item on the memory.

When the processor pushes a new item onto the stack, it decrements the stack pointer and then writes the item to the new memory location.

The processor implements two stacks: the main stack and the process stack, with a pointer for each held in independent registers (see the SP register on page 79).

In Thread mode, the CONTROL register (see page 89) controls whether the processor uses the main stack or the process stack. In Handler mode, the processor always uses the main stack. The options for processor operations are shown in Table 2-1 on page 75.

Processor Mode Use Privilege Level Stack Used
Thread Applications Privileged or unprivileged Main stack or process stack
Handler Exception handlers Always privileged Main stack

Register Map

Cortex_M4F_Register_Set

map1

Processor

Register Descriptions

Register 14: Stack Pointer (SP)

Exception

Register 16: Program Counter (PC)

Register 17: Program Status Register (PSR)

Note: This register is also referred to as xPSR.

The Program Status Register (PSR) has three functions, and the register bits are assigned to the different functions:

The PSR, IPSR, and EPSR registers can only be accessed in privileged mode; the APSR register can be accessed in either privileged or unprivileged mode

APSR contains the current state of the condition flags from previous instruction executions.

Memory Model

The processor has a fixed memory map that provides up to 4 GB of addressable memory.

MemoryMap1 MemoryMap2 MemoryMap3 MemoryMap4

Memory Regions, Types and Attributes

The memory map and the programming of the MPU split the memory map into regions. Each region has a defined memory type, and some regions have additional memory attributes. The memory type and attributes determine the behavior of accesses to the region

MemoryAccessBehavior

Note The Code, SRAM, and external RAM regions can hold programs. However, it is recommended that programs always use the Code region because the Cortex-M4F has separate buses that can perform instruction fetches and data accesses simultaneously.

Data Storage

Data is stored in little-endian format

DataStorage

Exception Model

The ARM Cortex-M4F processor and the Nested Vectored Interrupt Controller (NVIC) prioritize and handle all exceptions in Handler Mode

The processor state is automatically stored to the stack on an exception and automatically restored from the stack at the end of the Interrupt Service Routine (ISR).

The vector is fetched in parallel to the state saving, enabling efficient interrupt entry. The processor supports tail-chaining, which enables back-to-back interrupts to be performed without the overhead of state saving and restoration.

Priorities on the system handlers are set with the NVIC System Handler Priority n (SYSPRIn) registers

Interrupts are enabled through the NVIC Interrupt Set Enable n (ENn) register and prioritized with the NVIC Interrupt Priority n (PRIn) registers

Priorities can be grouped by splitting priority levels into preemption priorities and subpriorities. All the interrupt registers are described in “Nested Vectored Interrupt Controller (NVIC)” on page 126.

Internally, the highest user-programmable priority (0) is treated as fourth priority, after a Reset, Non-Maskable Interrupt (NMI), and a Hard Fault, in that order. Note that 0 is the default priority for all the programmable priorities.

Important: After a write to clear an interrupt source, it may take several processor cycles for the NVIC to see the interrupt source deassert. Thus if the interrupt clear is done as the last action in an interrupt handler, it is possible for the interrupt handler to complete while the NVIC sees the interrupt as still asserted, causing the interrupt handler to be re-entered errantly. This situation can be avoided by either clearing the interrupt source at the beginning of the interrupt handler or by performing a read or write after the write to clear the interrupt source (and flush the write buffer).

Exception States

Note: An exception handler can interrupt the execution of another exception handler. In this case, both exceptions are in the active state.

Exception Types

ExceptionTypes

In an OS environment, applications can use SVC instructions to access OS kernel functions and device drivers.

In an OS environment, use PendSV for context switching when no other exception is active. PendSV is triggered using the Interrupt Control and State (INTCTRL) register.

In an OS environment, the processor can use this exception as system tick.

In the system, peripherals use interrupts to communicate with the processor. Table 2-9 lists the interrupts on the TM4C123GH6ZRB controller.

Interrupts1 Interrupts2 Interrupts3 Interrupts4

Exception Handlers

The processor handles exceptions using:

Vector Table

The vector table contains the reset value of the stack pointer and the start addresses, also called exception vectors, for all exception handlers

The vector table is constructed using the vector address or offset shown in Exception Table 2-8

VectorTable

Note On system reset, the vector table is fixed at address 0x0000.0000. Privileged software can write to the Vector Table Offset (VTABLE) register to relocate the vector table start address to a different memory location, in the range 0x0000.0400 to 0x3FFF.FC00 (see “Vector Table” on page 108). Note that when configuring the VTABLE register, the offset must be aligned on a 1024-byte boundary.

lbr sp, =0xAAAA_BBBB

Exception Priorities

If multiple pending exceptions have the same priority, the pending exception with the lowest exception number takes precedence. For example, if both IRQ[0] and IRQ[1] are pending and have the same priority, then IRQ[0] is processed before IRQ[1].

When the processor is executing an exception handler, the exception handler is preempted if a higher priority exception occurs

When the processor is executing an exception handler, the exception handler is preempted if a higher priority exception occurs. If an exception occurs with the same priority as the exception being handled, the handler is not preempted, irrespective of the exception number. However, the status of the new interrupt changes to pending

Exception Entry and Return

Descriptions of exception handling use the following terms:

Exception Entry

Note: stack frame is use to store a bundle of processor’s registers

ExceptionStackFrame

When using floating-point routines, the Cortex-M4F processor automatically stacks the architected floating-point state on exception entry