System Control#

ARM Cortex-M System Control Functions#

Defined in namespace hal::cortex_m

#include <libhal-arm-mcu/system_control.hpp>

void hal::cortex_m::initialize_floating_point_unit()#

Enable the floating point unit coprocessor.

WARNING: If the coprocessor does not exist, as it is optional, a UsageFault will occur. Floating point units are only found within Cortex M4 and above processors.

void *hal::cortex_m::get_interrupt_vector_table_address()#

Get the address of the systems interrupt vector table.

On reset the VTOR register is set to 0x0000’0000 or nullptr.

Returns:

void* - address within VTOR the interrupt vector table relocation register.

void hal::cortex_m::set_interrupt_vector_table_address(void *p_table_location)#

Set the address of the systems interrupt vector table.

The interrupt vector table (IVT) is held in ROM which means that, either the interrupt service routines (ISR) had to be defined at compile time making them immutable at runtime, or that each ISR calls a mutable function pointer which can be changed at runtime.

The problem with the first option is that it makes writing and using libraries difficult. Usually requiring updates to the IVT manually by the application designer based on what libraries and drivers the application is using.

The second solution has a problem where the additional another layer of indirection increases interrupt latency. A more critical problem of this approach is that many ISRs take advantage of the state of the system when the ISR runs. For example, context switching in an RTOS needs to be able to see the address of where code was when the interrupt occurred and having an additional point of indirection (i.e. calling a function pointer) will change that location from the task to the ISR that called the context switch function. This will usually result in a fault of some sort.

Creating an interrupt vector table in RAM and relocating the ISRs there consumes RAM space, but gives great flexibility over the table at runtime.

Parameters:

p_table_location – - address of the interrupt vector table.

void hal::cortex_m::reset()#

Request reset from CPU.

void hal::cortex_m::wait_for_interrupt()#

Executes WFI instruction.

The WFI instruction stops the CPU, reducing power, and wakes up on interrupt.

void hal::cortex_m::wait_for_event()#

Executes WFE instruction.

The WFE instruction stops the CPU, reducing power, and wakes up on event.

bool hal::cortex_m::debugger_connected()#

Check if debugger is connected via CoreDebug->DHCSRd.

Returns:

true - debugger connected

Returns:

false - debugger is not connected