Techniques for Dealing with SysTick’s 24-bit Counter (Cortex-M4)

The 24-bit SysTick counter in Cortex-M4 can be tricky to handle due to its limited range. Here are some techniques to deal with the counter wrapping around at 224: 1. Use a Larger Variable to Store the Counter Value The simplest way is to use a 32-bit or 64-bit variable to store the SysTick counter…

Reducing Load/Store Instruction Latency on Cortex M4

The Cortex-M4 processor is designed to provide high performance and low power consumption in embedded applications. However, the load and store instructions can exhibit high latency due to cache misses and bus contention. This article will examine techniques to reduce the load/store latency and improve overall performance on Cortex-M4 based systems. Understanding Load/Store Latency The…

Pipelining Instructions After LDR vs STR on Cortex M4

When executing load (LDR) and store (STR) instructions on the Cortex-M4, it is important to understand how pipelining works afterwards. The Cortex-M4 implements a 3-stage pipeline, so execution happens in fetch, decode, and execute stages. LDR and STR instructions can cause stalls and bubbles in this pipeline if subsequent instructions are not independent. Careful pipelining…

Demystifying Cortex M4 LDR/STR Instruction Timing

The Cortex-M4 processor implements the ARMv7E-M architecture. One of the key features of this architecture is the LDR (load register) and STR (store register) instructions which allow data to be transferred between memory and registers. However, the timing of these instructions can sometimes be unclear. This article will provide a detailed look at how the…

Understanding Pipeline Hazards in Cortex-M4 Microcontrollers

The Cortex-M4 processor implements a 3-stage pipeline to improve performance by allowing multiple instructions to be processed simultaneously. However, pipeline hazards can occur when the next instruction cannot execute in the following clock cycle, leading to bubbles and stalls in the pipeline. This article provides an in-depth explanation of the various types of hazards that…

Reducing Context Switch Overhead with FPU Registers on Cortex-M4

The Cortex-M4 processor includes a floating point unit (FPU) to support single precision floating point operations. However, saving and restoring the FPU registers during a context switch can add significant overhead. This article will discuss techniques to reduce this context switch overhead by avoiding unnecessary saving/restoring of the FPU registers. FPU Registers in Cortex-M4 The…

Tips for Using the FPU on Cortex-M4 Efficiently

The Cortex-M4 processor includes a single precision floating point unit (FPU) that can significantly improve the performance of math-intensive code. However, to utilize the FPU efficiently requires some care in coding and optimization. Here are some tips for getting the most out of the Cortex-M4 FPU: Enable the FPU in Your Toolchain The first step…

When to Use Intrinsics vs Assembler for Math Functions on Cortex-M4?

When programming for the Cortex-M4 chip, developers have a choice between using compiler intrinsics or handwritten assembly language for implementing mathematical functions. There are advantages and disadvantages to both approaches that should be considered when deciding which implementation to use for a particular application. Using Compiler Intrinsics Compiler intrinsics are functions provided by the compiler…