Showing posts with label ARM Core A Tutorial. Show all posts
Showing posts with label ARM Core A Tutorial. Show all posts

Thursday, April 30, 2020

ARM Coretex A9 Tutorial | Core Register Access

Stack Pointer (SP/R13)
The processor uses SP as a pointer to the active stack. More...

Functions

__STATIC_INLINE __ASM void __set_SP (uint32_t stack)
 Set Stack Pointer. More...
 
__STATIC_INLINE __ASM void __set_SP_usr (uint32_t topOfProcStack)
 Set USR/SYS Stack Pointer. More...
 

Description

The Stack Pointer is banked per processor mode. Accessing the active stack pointer actually returns/modifies the stack pointer of the current processor execution mode.
ModeActual SP
User/SystemSP_usr
HypervisorSP_hyp
SupervisorSP_svc
AbortSP_abt
UndefinedSP_und
MonitorSP_mon
IRQSP_irq
FIQSP_fiq
Consider __set_SP and __set_SP_usr to access this register.

Function Documentation

__STATIC_INLINE __ASM void __set_SP(uint32_t stack)
Parameters
[in]stackStack Pointer value to set
This function assigns the given value to the current stack pointer.
__STATIC_INLINE __ASM void __set_SP_usr(uint32_t topOfProcStack)
Parameters
[in]topOfProcStackUSR/SYS Stack Pointer value to set
This function assigns the given value to the User/System Stack Pointer (SP_usr).

Example:
To set value for Stack Pointer Register:
uint32_t maskValue = 0x0001;

__set_SP(maskValue);








ARM Coretex A9 Tutorial | System and Clock Configuration

Functions

void SystemInit (void)
 Function to Initialize the system. More...
 
void SystemCoreClockUpdate (void)
 Function to update the variable SystemCoreClockMore...
 

Variables

uint32_t SystemCoreClock
 Variable to hold the system core clock value. More...
 

Description

Arm provides a template file system_device.c that must be adapted by the silicon vendor to match their actual device. As a minimum requirement, this file must provide:
  • A device-specific system configuration function, SystemInit().
  • A global variable that contains the system frequency, SystemCoreClock.
The file configures the device and, typically, initializes the oscillator (PLL) that is part of the microcontroller device. This file might export other functions or variables that provide a more flexible configuration of the microcontroller system.
Note
Please pay special attention to the static variable SystemCoreClock. This variable might be used throughout the whole system initialization and runtime to calculate frequency/time related values. Thus one must assure that the variable always reflects the actual system clock speed. Be aware that a value stored to SystemCoreClock during low level initialization (i.e. SystemInit()) might get overwritten by C library startup code. Thus its highly recommended to call SystemCoreClockUpdate at the beginning of the user main() routine.

Code Example

The code below shows the usage of the variable SystemCoreClock and the functions SystemInit() and SystemCoreClockUpdate() with an arbitrary Arm Cortex-A9.
#include "ARMCA9.h"
uint32_t coreClock_1 = 0; /* Variables to store core clock values */
uint32_t coreClock_2 = 0;
int main (void) {
coreClock_1 = SystemCoreClock; /* Store value of predefined SystemCoreClock */
SystemCoreClockUpdate(); /* Update SystemCoreClock according to register settings */
coreClock_2 = SystemCoreClock; /* Store value of calculated SystemCoreClock */
if (coreClock_2 != coreClock_1) { /* Without changing the clock setting both core clock values should be the same */
// Error Handling
}
while(1);
}

Function Documentation

void SystemCoreClockUpdate(void )
Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. The function evaluates the clock register settings and calculates the current core clock.
void SystemInit(void )
Initializes the microcontroller system. Typically, this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with a variable clock speed, it updates the variable SystemCoreClock. SystemInit is called from the file startup_device.

Variable Documentation


uint32_t SystemCoreClock
Holds the system core clock, which is the system clock frequency supplied to the SysTick timer and the processor core clock. This variable can be used by debuggers to query the frequency of the debug timer or to configure the trace clock speed.
Attention
Compilers must be configured to avoid removing this variable in case the application program is not using it. Debugging systems require the variable to be physically present in memory so that it can be examined to configure the debugger.

ARM Core A9 Tutorial | Basic CMSIS Example

#include <ARMCA9.h> // File name depends on device used
static const uint32_t TICK_RATE_HZ = 1000U;
uint32_t volatile msTicks; // Counter for millisecond Interval
static void SysTick_Handler( void )
{
msTicks++; // Increment Counter
}
// We use the Private Tiemer (PTIM) of the Cortex-A9 FVP Model here.
// In general the available Timers are highly vendor specific for Cortex-A processors.
void private_timer_init(void) {
PTIM_SetLoadValue ((SystemCoreClock/TICK_RATE_HZ) - 1U);
/* Install SysTick_Handler as the interrupt function for PTIM */
/* Determine number of implemented priority bits */
/* Set lowest priority -1 */
/* Enable IRQ */
IRQ_Enable ((IRQn_ID_t)PrivTimer_IRQn);
}
/* Delay execution for given amount of ticks */
void Delay(uint32_t ticks) {
uint32_t tgtTicks = msTicks + ticks; // target tick count to delay execution to
while (msTicks == tgtTicks) {
__WFE (); // Power-Down until next Event/Interrupt
}
}
/* main function */
int main(void)
{
/* Initialize device HAL here */
private_timer_init();
static uint8_t ledState = 0;
/* Infinite loop */
while (1)
{
/* Add application code here */
ledState = !ledState;
Delay(500);
}
}
Back to Top