Cortex Authority Manual – Software Porting to ARM Architecture

Differences Between 8-bit/16-bit and ARM Architecture

Data Types

Data Type 8-bit/16-bit Microcontroller ARM Architecture
char 8-bit 8-bit
short int 16-bit 16-bit
int 16-bit 32-bit
Pointer 8/16/24-bit 32-bit
float 32-bit 32-bit
double 32-bit 64-bit

Memory Storage Methods

  • Data Alignment: 8-bit processors typically do not have data alignment issues, while ARM architecture requires consideration of data alignment.

Cortex Authority Manual - Software Porting to ARM Architecture

  • Local Variable Storage: 8-bit processors may place local variables in static storage locations, while ARM architecture typically places them in stack space.

General Steps for Software Porting

Startup Code and Vector Table

  • Differences: Different processor architectures have different startup codes and interrupt vector tables.

  • Porting: During porting, the startup code and vector table need to be rewritten to accommodate ARM Cortex-M processors.

Stack Allocation Adjustment

  • Differences: ARM Cortex-M processors have different stack size requirements compared to 8-bit or 16-bit architectures.

  • Porting: The stack size and position need to be adjusted to meet ARM architecture requirements.

Architecture-Related/C Language Extensions

  • Differences: 8-bit and 16-bit C compilers may provide specific extensions, such as special function registers (SFR) in 8051.

  • Porting: Under ARM architecture, standard C language or functions provided by CMSIS should be used, avoiding 8-bit or 16-bit specific extensions.

Interrupt Control

  • Differences: 8-bit and 16-bit microcontrollers typically manipulate interrupt control registers directly.

  • Porting: The interrupt configuration code should be modified to use CMSIS Core interrupt control functions, such as using <span>NVIC_EnableIRQ</span> and <span>NVIC_DisableIRQ</span>.

Peripheral Programming

  • Differences: Peripheral programming in 8-bit and 16-bit microcontrollers typically involves direct register writes.

  • Porting: Functions from device driver libraries can be used or registers can be accessed directly.

Assembly Code and Inline Assembly

  • Differences: All assembly and inline assembly code needs to be rewritten.

  • Porting: In most cases, functions can be rewritten in C to improve portability.

Unaligned Data Handling

  • Differences: 8-bit or 16-bit microcontrollers may support unaligned data, while ARM Cortex-M3/M4 handle unaligned data less efficiently, and Cortex-M0/M0+ do not support it.

  • Porting: Modifications to data structure definitions or pointer operation code may be necessary to improve efficiency and portability.

Data Size Differences

  • Differences: Most integers in 8-bit and 16-bit processors are 16-bit, while integers in ARM architecture are 32-bit.

  • Porting: It may be necessary to change <span>int</span> in the code to <span>short int</span> or <span>int16_t</span>.

Floating Point Processing

  • Differences: The implementation and efficiency of floating-point operations may differ across architectures.

  • Porting: Adjustments to floating-point operation code may be necessary to accommodate ARM architecture.

Adding Error Handling

  • Differences: Many 8-bit and 16-bit microcontrollers do not have error exceptions.

  • Porting: Implementing error handling mechanisms to enhance system robustness.

Stack Changes Due to Porting

Stack Increase

  • Reason: ARM architecture uses 4 bytes for each register pushed onto the stack, and local variables are typically located on the stack.

  • Impact: The stack size needs to be adjusted to accommodate new requirements.

Stack Decrease

  • Reason: ARM architecture has more powerful addressing modes and more registers.

  • Impact: This reduces the demand on the stack.

Memory Size Changes

Memory Size Decrease

  • Reason: 16-bit and 32-bit data processing is more efficient, with stronger addressing modes.

  • Impact: This can reduce memory usage.

Memory Size Increase

  • Reason: The vector table of Cortex-M microcontrollers may be larger.

  • Impact: More memory space is required.

Interrupt Handling

CMSIS-Core Interrupts

  • Pseudoinstruction: Use <span>_irq</span> to define interrupt functions.

  • Functions: Use <span>disable_irq()</span> and <span>enable_irq()</span><span> to disable and enable all interrupts.</span>

  • Configuration: Use <span>NVIC_EnableIRQ</span>, <span>NVIC_DisableIRQ</span>, and <span>NVIC_SetPriority</span> to configure interrupts.

Sleep Mode

  • Instruction: Use <span>_WFI()</span> to enter sleep mode.

Hardware Differences

Memory Mapping

  • Differences: Memory mapping differs between different processors.

  • Porting: Adjustments need to be made according to the memory mapping of ARM processors.

Interrupt Controller

  • Differences: The design of interrupt controllers varies between different processors.

  • Porting: Configuration needs to be done according to ARM’s interrupt controller.

MPU

  • Differences: The configuration and functionality of the MPU may differ.

  • Porting: Configuration needs to be done according to ARM’s MPU.

System Control

  • Differences: System control registers and functionalities may differ.

  • Porting: Configuration needs to be done according to ARM’s system control.

Operating Modes

  • Differences: Operating modes may differ between different processors.

  • Porting: Adjustments need to be made according to ARM’s operating modes.

FIQ and Non-Maskable Interrupt Differences

  • Differences: The handling of FIQ and non-maskable interrupts may differ.

  • Porting: Adjustments need to be made according to ARM’s interrupt handling mechanisms.

Assembly Language File Porting

Thumb State

  • Switching to ARM State: Code needs to be modified to switch to ARM state.

  • SWI Instruction: Replace with SVC instruction.

  • Stack Mode: Ensure the stack is in full descending mode.

ARM State

  • Vector Table: The vector table needs to be redefined.

  • Register Initialization: Registers need to be initialized.

  • Interrupt Handling: Interrupt handling functions need to be re-implemented.

C Language Files

Inline Assembly

  • Differences: Inline assembly code needs to be rewritten.

  • Porting: Use C language implementation as much as possible to reduce the use of inline assembly.

Interrupt Handling

  • Differences: The definition and calling methods of interrupt handling functions may differ.

  • Porting: Use the interrupt handling mechanisms provided by CMSIS.

Pragma Pseudoinstructions

  • Differences: Different compilers have different support for pragma pseudoinstructions.

  • Porting: Use standard C language or functions provided by CMSIS.

Differences Between Different Processors

Instruction Set

  • Differences: The instruction sets of different processors differ.

  • Porting: Ensure that the instructions used exist in the target processor.

IT Instruction Blocks

  • Differences: IT instruction blocks are used for conditional execution.

  • Porting: Adjustments need to be made according to ARM’s conditional execution mechanisms.

Exclusive Access Instructions

  • Differences: Exclusive access instructions are used for atomic operations.

  • Porting: Use functions provided by CMSIS for exclusive access.

Programming Model

  • Differences: The programming models of different processors differ.

  • Porting: Adjustments need to be made according to ARM’s programming model.

NVIC

  • Differences: The NVIC configurations of different processors differ.

  • Porting: Use CMSIS provided NVIC functions for configuration.

System-Level Features

  • Differences: The system-level features of different processors differ.

  • Porting: Adjustments need to be made according to ARM’s system-level features.

Low Power Features

  • Differences: The low power features of different processors differ.

  • Porting: Optimizations need to be made according to ARM’s low power features.

Debugging and Tracing Features

  • Differences: The debugging and tracing features of different processors differ.

  • Porting: Adjustments need to be made according to ARM’s debugging and tracing features.

Required Software Changes

Replace Device Driver Header Files

  • Reason: Different processors have different peripheral drivers.

  • Porting: Replace with the device driver header files for ARM processors.

Replace Device-Specific Startup Code

  • Reason: Startup code is closely related to processor architecture.

  • Porting: Use the startup code for ARM processors.

Adjust Interrupt Priorities

  • Reason: The configuration methods for interrupt priorities may differ.

  • Porting: Use functions provided by CMSIS to adjust interrupt priorities.

Adjust Compiler Options for Processor Type, Floating Point Options, etc.

  • Reason: Compiler options affect code generation.

  • Porting: Adjust according to ARM processors.

Embedded OS

Create Portable Program Code for Cortex-M Processors

  • Use CMSIS-Core Functions: Use CMSIS-Core functions to access processor features instead of directly accessing system registers.

  • Avoid Using Specific Features: Avoid using features that only exist in Cortex-M3 and Cortex-M4.

  • Detect Unaligned Data Transfers: Enable the <span>UNALIGNTRP</span> bit to detect unaligned data access.

  • Assembly Code: Ensure that the instructions in the assembly code are supported in ARMv6-M.

Leave a Comment