### Full Integration Example with FreeRTOS Source: https://context7.com/armink/cmbacktrace/llms.txt Integrate CmBacktrace into a FreeRTOS application on an STM32F103 microcontroller. This example demonstrates initializing CmBacktrace, triggering a fault, and starting the scheduler. ```c /* main.c */ #include "FreeRTOS.h" #include "task.h" #include "cm_backtrace.h" void app_task(void *arg) { /* Trigger a test fault (divide by zero) */ volatile int x = 0; volatile int y = 1 / x; /* → HardFault */ (void)y; vTaskDelete(NULL); } int main(void) { bsp_uart_init(); /* set up printf UART first */ cm_backtrace_init("FreeRTOS_Demo", "V1.0.0", "V0.1.0"); cm_backtrace_firmware_info(); xTaskCreate(app_task, "app", 512, NULL, 2, NULL); vTaskStartScheduler(); return 0; } /* Expected fault output: Firmware name: FreeRTOS_Demo, hardware version: V1.0.0, software version: V0.1.0 Fault on thread app ===== Thread stack information ===== addr: 20001800 data: deadbeef ... ==================================== =================== Registers information ==================== R0 : 00000001 R1 : 00000000 R2 : 00000000 R3 : 00000000 R12: 00000000 LR : 0800xxxx PC : 0800yyyy PSR: 61000000 ============================================================== Usage fault is caused by Indicates a divide by zero has taken place Show more call stack info by run: addr2line -e FreeRTOS_Demo.elf -afpiC 0800yyyy 0800xxxx */ ``` -------------------------------- ### STM32F10x CMSIS Example Application Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm A typical example demonstrating the usage of the CMSIS layer in an STM32F10x application. It includes SysTick configuration for delays, LED control, and a main loop for blinking an LED. ```c #include "stm32f10x.h" volatile uint32_t msTicks; /* timeTicks counter */ void SysTick_Handler(void) { msTicks++; /* increment timeTicks counter */ } __INLINE static void Delay (uint32_t dlyTicks) { uint32_t curTicks = msTicks; while ((msTicks - curTicks) < dlyTicks); } __INLINE static void LED_Config(void) { ; /* Configure the LEDs */ } __INLINE static void LED_On (uint32_t led) { ; /* Turn On LED */ } __INLINE static void LED_Off (uint32_t led) { ; /* Turn Off LED */ } int main (void) { if (SysTick_Config (SystemCoreClock / 1000)) { /* Setup SysTick for 1 msec interrupts */ ; /* Handle Error */ while (1); } LED_Config(); /* configure the LEDs */ while(1) { LED_On (0x100); /* Turn on the LED */ Delay (100); /* delay 100 Msec */ LED_Off (0x100); /* Turn off the LED */ Delay (100); /* delay 100 Msec */ } } ``` -------------------------------- ### Doxygen Example for NVIC Enable Interrupt Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm This is an example of Doxygen-formatted comments for a function that enables an interrupt in the NVIC. It details the function's purpose, parameters, and return values. ```c /** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */ ``` -------------------------------- ### Doxygen Example for CMSIS Function Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm This is an example of Doxygen-style comments used for CMSIS functions, providing a brief overview, parameter explanation, return value details, and a comprehensive function description. ```c /** * @brief Enable Interrupt in NVIC Interrupt Controller * @param IRQn interrupt number that specifies the interrupt * @return none. * Enable the specified interrupt in the NVIC Interrupt Controller. * Other settings of the interrupt such as priority are not affected. */ ``` -------------------------------- ### System Configuration Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides essential functions for microcontroller system configuration, including clock setup and updates. ```APIDOC ## SystemInit ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. ### Function Signature `void SystemInit (void)` ### Called By Startup file (`startup_device.c`) ``` ```APIDOC ## SystemCoreClockUpdate ### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### Function Signature `void SystemCoreClockUpdate (void)` ``` -------------------------------- ### Direct Peripheral Register Access Example Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Demonstrates how to access and modify peripheral registers using the defined access structures and base addresses. ```c SysTick->CTRL = 0; ``` -------------------------------- ### Using addr2line for Call Stack Resolution Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/rtthread/stm32f4xx/README.md This command-line example shows how to use the `addr2line` utility to translate memory addresses from a HardFault log into human-readable function names and source code line numbers. Ensure you are in the executable's directory. ```bash D:\Program\STM32\CmBacktrace\demos\os\rtthread\stm32f4xx\EWARM\STM32F405RG\Exe>addr2line -e CmBacktrace.out -a -f 0800035c 0800018d 080009e1 0x0800035c fault_test_by_div0 D:\Program\STM32\CmBacktrace\demos\os\rtthread\stm32f4xx\app\src/fault_test.c:38 0x0800018d thread_entry_sys_monitor D:\Program\STM32\CmBacktrace\demos\os\rtthread\stm32f4xx\app\src/app_task.c:36 0x080009e1 rt_list_remove D:\Program\STM32\CmBacktrace\demos\os\rtthread\stm32f4xx\RT-Thread-1.2.2\include/rtservice.h:95 D:\Program\STM32\CmBacktrace\demos\os\rtthread\stm32f4xx\EWARM\STM32F405RG\Exe> ``` -------------------------------- ### Control CPU Execution with J-Link Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/RVMDK/JLinkLog.txt Illustrates starting CPU execution with JLINK_Go and checking its halted state with JLINK_IsHalted. These functions are essential for managing the debug flow. ```c JLINK_Go() -- CPU_ReadMem(4 bytes @ 0xE0001000) (0003ms, 0535ms total) JLINK_IsHalted() returns FALSE (0001ms, 0536ms total) JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE (0007ms, 0542ms total) ``` ```c JLINK_Go() -- CPU_ReadMem(4 bytes @ 0xE0001000) (0004ms, 0550ms total) JLINK_IsHalted() returns FALSE (0001ms, 0551ms total) JLINK_IsHalted() returns FALSE (0001ms, 0551ms total) JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE (0005ms, 0555ms total) ``` -------------------------------- ### Control CPU Execution with J-Link Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/RVMDK/JLinkLog.txt Commands to control the CPU execution flow, including starting execution with JLINK_Go() and checking if the CPU is halted with JLINK_IsHalted(). ```c JLINK_Go() -- CPU_ReadMem(4 bytes @ 0xE0001000) JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE ``` ```c JLINK_Go() -- CPU_ReadMem(4 bytes @ 0xE0001000) JLINK_IsHalted() returns FALSE ``` ```c JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE ``` -------------------------------- ### SysTickConfig Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm Configures the SysTick timer and starts the SysTick interrupt. This function sets up the SysTick timer to create interrupts at a specified time interval. ```APIDOC ## SysTickConfig ### Description Sets up the SysTick timer and enables the SysTick interrupt. After this call, the SysTick timer creates interrupts with the specified time interval. ### Function Signature `uint32_t SysTickConfig (uint32_t ticks)` ### Parameters * `ticks` (uint32_t) - SysTick counter reload value. ### Return Value * `0` when successful. * `1` on failure. ``` -------------------------------- ### STM32F10x HardFault Output Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/README.md Example output from CmBacktrace when a HardFault occurs in a non-OS environment. It includes firmware information, stack details, register values, and the cause of the fault. ```text Firmware name: CmBacktrace, hardware version: V1.0.0, software version: V0.1.0 Fault on interrupt or bare metal(no OS) environment ====== Main stack information ====== addr: 20001140 data: 00000000 addr: 20001144 data: e000ed14 addr: 20001148 data: 0000000a addr: 2000114c data: 00000000 addr: 20001150 data: a046ac2b addr: 20001154 data: 08000145 addr: 20001158 data: e000ed14 addr: 2000115c data: 08003143 ==================================== =================== Registers information ==================== R0 : 00000000 R1 : 200012ec R2 : 00000000 R3 : 00000000 R12: 00008080 LR : 08000145 PC : 08000a60 PSR: 61000000 ============================================================== Usage fault is caused by Indicates a divide by zero has taken place (can be set only if DIV_0_TRP is set) Show more call stack info by run: addr2line -e CmBacktrace.out -a -f 08000a60 08000141 0800313f ``` -------------------------------- ### RTOS Kernel Debugging with ITM Channel 31 Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Example demonstrating the use of ITM Channel 31 for RTOS kernel debugging. It checks for debugger connection and ITM channel enablement before transmitting task ID and status information. ```c // check if debugger connected and ITM channel enabled for tracing if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) && (ITM->TCR & ITM_TCR_ITMENA) && (ITM->TER & (1UL << 31))) { // transmit trace data while (ITM->PORT31_U32 == 0); ITM->PORT31_U32 = task_id; // id of next task while (ITM->PORT31_U32 == 0); ITM->PORT31_U32 = task_status; // status information } ``` -------------------------------- ### J-Link Breakpoint and Execution Control Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/RVMDK/JLinkLog.txt Logs detailing the setup and clearing of J-Link breakpoints, along with CPU execution commands. These are crucial for controlling program flow during debugging. ```log T1730 001:686 JLINK_SetBPEx(Addr = 0x20000000, Type = 0xFFFFFFF2) -- CPU_ReadMem(2 bytes @ 0x20000000) returns 0x00000029 (0001ms, 0502ms total) T1730 001:687 JLINK_Go() -- CPU_WriteMem(2 bytes @ 0x20000000) -- CPU_ReadMem(4 bytes @ 0xE0001000) (0004ms, 0506ms total) T1730 001:691 JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE (0006ms, 0512ms total) T1730 001:697 JLINK_ReadReg(R15 (PC)) returns 0x20000000 (0000ms, 0506ms total) T1730 001:697 JLINK_ClrBPEx(BPHandle = 0x00000029) returns 0x00 (0000ms, 0506ms total) ``` ```log T1730 001:709 JLINK_SetBPEx(Addr = 0x20000000, Type = 0xFFFFFFF2) returns 0x0000002A (0000ms, 0517ms total) T1730 001:710 JLINK_Go() -- CPU_ReadMem(4 bytes @ 0xE0001000) (0003ms, 0521ms total) T1730 001:713 JLINK_IsHalted() returns FALSE (0001ms, 0522ms total) T1730 001:803 JLINK_IsHalted() -- CPU_ReadMem(2 bytes @ 0x20000000) returns TRUE (0006ms, 0527ms total) T1730 001:809 JLINK_ReadReg(R15 (PC)) returns 0x20000000 (0000ms, 0521ms total) T1730 001:809 JLINK_ClrBPEx(BPHandle = 0x0000002A) returns 0x00 (0000ms, 0521ms total) ``` -------------------------------- ### RT-Thread HardFault Log Output Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/rtthread/stm32f4xx/README.md This is an example of the log output generated when a HardFault occurs in the RT-Thread system. It includes firmware information, thread stack details, register states, and the cause of the fault. ```text Firmware name: CmBacktrace, hardware version: V1.0.0, software version: V0.1.0 Fault on thread sys_monitor ===== Thread stack information ===== addr: 10002d58 data: 00000000 addr: 10002d5c data: 00000000 addr: 10002d60 data: deadbeef addr: 10002d64 data: deadbeef addr: 10002d68 data: deadbeef addr: 10002d6c data: 08000191 addr: 10002d70 data: deadbeef addr: 10002d74 data: 080009e5 ==================================== =================== Registers information ==================== R0 : 00000000 R1 : 00000000 R2 : 00000000 R3 : 00000000 R12: 00000000 LR : 08000191 PC : 0800035c PSR: 41000000 ============================================================== Usage fault is caused by Indicates a divide by zero has taken place (can be set only if DIV_0_TRP is set) Show more call stack info by run: addr2line -e CmBacktrace.out -a -f 0800035c 0800018d 080009e1 ``` -------------------------------- ### RTOS Kernel ITM Debug Trace Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Example demonstrating the use of ITM Channel 31 for RTOS kernel tracing. It checks for debugger connection and ITM channel enablement before transmitting task ID and status. ```c // check if debugger connected and ITM channel enabled for tracing if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA) && (ITM->TCR & ITM_TCR_ITMENA) && (ITM->TER & (1UL << 31))) { // transmit trace data while (ITM->PORT31_U32 == 0); ITM->PORT31.u8 = task_id; // id of next task while (ITM->PORT31.u32 == 0); ITM->PORT31.u32 = task_status; // status information } ``` -------------------------------- ### Initialize CmBacktrace Library Source: https://github.com/armink/cmbacktrace/blob/master/README.md Call this function during project initialization. It sets up the library with firmware and version information for retrospective purposes. ```c void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, const char *software_ver) ``` -------------------------------- ### Initialize CmBacktrace in main() Source: https://context7.com/armink/cmbacktrace/llms.txt Call `cm_backtrace_init` once at system startup before any faults can occur. This function records firmware identity and resolves stack/code boundaries. ```c #include /* Call from main() or the RTOS startup task, before scheduler starts */ int main(void) { /* Arguments: firmware name (must match the ELF/AXF filename), hardware version string, software version string */ cm_backtrace_init("MyApp", "V2.0.0", "V1.3.5"); /* The firmware info can be printed any time after init */ cm_backtrace_firmware_info(); /* Output: "Firmware name: MyApp, hardware version: V2.0.0, software version: V1.3.5" */ app_run(); return 0; } ``` -------------------------------- ### Interrupt Number Definition Example (IRQn_Type) Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm An example enum typedef from _device.h_ defining interrupt request numbers (IRQn) for Cortex-M3 processor exceptions and STM32 specific interrupts. ```c typedef enum IRQn { /****** Cortex-M3 Processor Exceptions/Interrupt Numbers ************************************************************************/ NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ HardFault_IRQn = -13, /*!< 3 Cortex-M3 Hard Fault Interrupt */ MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ /****** STM32 specific Interrupt Numbers ******************************************************************************************/ WWDG_STM_IRQn = 0, /*!< Window WatchDog Interrupt */ PVD_STM_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */ : : } IRQn_Type; ``` -------------------------------- ### Library Initialization Source: https://github.com/armink/cmbacktrace/blob/master/README.md Initializes the CmBacktrace library with firmware and version information. This function should be called during project initialization. ```APIDOC ## Library Initialization ### Description Initializes the CmBacktrace library with firmware and version information. This function should be called during project initialization. ### Function Signature ```c void cm_backtrace_init(const char *firmware_name, const char *hardware_ver, const char *software_ver) ``` ### Parameters #### Path Parameters - **firmware_name** (const char *) - Description: Firmware name, which must correspond to the firmware name generated by the compiler. - **hardware_ver** (const char *) - Description: The hardware version number corresponding to the firmware. - **software_ver** (const char *) - Description: Software version number of the firmware. ### Notes The input parameters will be output in case of assertion or failure, mainly for retrospective purposes. ``` -------------------------------- ### cm_backtrace_init - Library Initialization Source: https://context7.com/armink/cmbacktrace/llms.txt Initializes the CmBacktrace library by recording firmware identity strings and resolving stack and code-section boundaries. This function must be called once at system startup before any faults or assertions occur. ```APIDOC ## cm_backtrace_init ### Description Initializes the CmBacktrace library. It records the firmware identity strings and resolves the main C-stack boundaries and code-section boundaries from linker symbols. This allows the call-stack walker to identify valid return addresses. ### Function Signature ```c int cm_backtrace_init(const char *firmware_name, const char *hardware_version, const char *software_version); ``` ### Parameters - **firmware_name** (const char *) - The name of the firmware (must match the ELF/AXF filename). - **hardware_version** (const char *) - The hardware version string. - **software_version** (const char *) - The software version string. ### Usage Example ```c #include int main(void) { cm_backtrace_init("MyApp", "V2.0.0", "V1.3.5"); cm_backtrace_firmware_info(); app_run(); return 0; } ``` ### Notes If the main-stack block name differs from the compiler default, it can be overridden in `cmb_cfg.h` using `CMB_CSTACK_BLOCK_NAME` or `CMB_CSTACK_BLOCK_START`/`CMB_CSTACK_BLOCK_END`. ``` -------------------------------- ### SystemInit Function Definition Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm This function is responsible for setting up the microcontroller system, typically configuring the oscillator (PLL). It's called from the startup file and updates SystemCoreClock if the clock speed is variable. ```c void SystemInit (void) ``` -------------------------------- ### NVIC Access Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Helper functions to simplify the setup and management of the Nested Vectored Interrupt Controller (NVIC). ```APIDOC ## NVIC Access Functions ### `NVIC_SetPriorityGrouping(uint32_t PriorityGroup)` - **Description**: Set the Priority Grouping (Groups . Subgroups). - **Core**: M3 - **Parameter**: Priority Grouping Value ### `NVIC_GetPriorityGrouping(void)` - **Description**: Get the Priority Grouping (Groups . Subgroups). - **Core**: M3 - **Parameter**: (void) ### `NVIC_EnableIRQ(IRQn_Type IRQn)` - **Description**: Enable IRQn. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_DisableIRQ(IRQn_Type IRQn)` - **Description**: Disable IRQn. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_GetPendingIRQ(IRQn_Type IRQn)` - **Description**: Return 1 if IRQn is pending else 0. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_SetPendingIRQ(IRQn_Type IRQn)` - **Description**: Set IRQn Pending. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_ClearPendingIRQ(IRQn_Type IRQn)` - **Description**: Clear IRQn Pending Status. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_GetActive(IRQn_Type IRQn)` - **Description**: Return 1 if IRQn is active else 0. - **Core**: M3 - **Parameter**: IRQ Number ### `NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)` - **Description**: Set Priority for IRQn (not threadsafe for Cortex-M0). - **Core**: M0, M3 - **Parameter**: IRQ Number, Priority ### `NVIC_GetPriority(IRQn_Type IRQn)` - **Description**: Get Priority for IRQn. - **Core**: M0, M3 - **Parameter**: IRQ Number ### `NVIC_EncodePriority(uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)` - **Description**: Encode priority for given group, preemptive and sub priority. - **Core**: M3 - **Parameter**: IRQ Number, Priority Group, Preemptive Priority, Sub Priority ### `NVIC_DecodePriority(uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)` - **Description**: Decode given priority to group, preemptive and sub priority. - **Core**: M3 - **Parameter**: IRQ Number, Priority, pointer to Priority Group, pointer to Preemptive Priority, pointer to Sub Priority ### `NVIC_SystemReset(void)` - **Description**: Resets the System. - **Core**: M0, M3 - **Parameter**: (void) ``` -------------------------------- ### System Initialization Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm These functions are part of the system configuration and are typically found in system\__device_.c. They are crucial for setting up the microcontroller's clock and core frequency. ```APIDOC ## SystemInit ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. ### Function Signature `void SystemInit (void)` ### Called By `SystemInit` is called from startup_\__device_ file. ``` ```APIDOC ## SystemCoreClockUpdate ### Description Updates the variable `SystemCoreClock` and must be called whenever the core clock is changed during program execution. `SystemCoreClockUpdate()` evaluates the clock register settings and calculates the current core clock. ### Function Signature `void SystemCoreClockUpdate (void)` ``` -------------------------------- ### Get Control Register Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the CONTROL register using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_CONTROL (void) ``` -------------------------------- ### Print CmBacktrace Firmware Information Source: https://context7.com/armink/cmbacktrace/llms.txt Use `cm_backtrace_firmware_info` to print the firmware name, hardware version, and software version strings previously supplied to `cm_backtrace_init`. Useful for startup banners or annotating logs. ```c #include void print_boot_banner(void) { cm_backtrace_firmware_info(); /* Output: Firmware name: MyApp, hardware version: V2.0.0, software version: V1.3.5 */ } ``` -------------------------------- ### Device Specific Interrupts in Vector Table Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Example of how device-specific interrupts are listed in the vector table. These correspond to external interrupt sources. ```Assembly ; External Interrupts DCD WWDG_IRQHandler ; Window Watchdog DCD PVD_IRQHandler ; PVD through EXTI Line detect DCD TAMPER_IRQHandler ; Tamper ``` -------------------------------- ### System Configuration Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides essential functions for system initialization and clock updates. ```APIDOC ## SystemInit ### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. SystemInit is called from startup_device file. ### Function Signature ```c void SystemInit (void) ``` ``` ```APIDOC ## SystemCoreClockUpdate ### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### Function Signature ```c void SystemCoreClockUpdate (void) ``` ``` -------------------------------- ### System Configuration Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/ucosii/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Provides essential functions for system initialization and clock configuration. ```APIDOC ## System Configuration ### void SystemInit (void) #### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable SystemCoreClock. SystemInit is called from startup_device file. ### void SystemCoreClockUpdate (void) #### Description Updates the variable SystemCoreClock and must be called whenever the core clock is changed during program execution. SystemCoreClockUpdate() evaluates the clock register settings and calculates the current core clock. ### uint32_t SystemCoreClock #### Description Contains 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 the user application to setup the SysTick timer or configure other parameters. It may also be used by debugger to query the frequency of the debug timer or configure the trace clock speed. SystemCoreClock is initialized with a correct predefined value. ``` -------------------------------- ### Get Base Priority Register Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Base Priority Register (BASEPRI) using the MRS instruction. Available only for Cortex-M3. ```c uiuint32_t __get_BASEPRI (void) ``` -------------------------------- ### Get Fault Mask Register Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Fault Mask Register (FAULTMASK) using the MRS instruction. Available only for Cortex-M3. ```c uint32_t __get_FAULTMASK (void) ``` -------------------------------- ### System Configuration Functions Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/ucosii/stm32f10x/Libraries/CMSIS_EWARM/Documentation/CMSIS_Core.htm Provides essential functions for microcontroller system initialization and core clock updates. ```APIDOC ## System Configuration ### `void SystemInit (void)` #### Description Setup the microcontroller system. Typically this function configures the oscillator (PLL) that is part of the microcontroller device. For systems with variable clock speed it also updates the variable `SystemCoreClock`. `SystemInit` is called from startup_`device`.c file. ### `void SystemCoreClockUpdate (void)` #### Description Updates the variable `SystemCoreClock` and must be called whenever the core clock is changed during program execution. `SystemCoreClockUpdate()` evaluates the clock register settings and calculates the current core clock. ``` -------------------------------- ### Get Main Stack Pointer Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Main Stack Pointer (MSP) using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_MSP (void) ``` -------------------------------- ### Get Process Stack Pointer Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Process Stack Pointer (PSP) using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_PSP (void) ``` -------------------------------- ### Get Priority Mask Register Source: https://github.com/armink/cmbacktrace/blob/master/demos/os/freertos/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Returns the current value of the Priority Mask Register (PRIMASK) using the MRS instruction. Available for Cortex-M0 and M3. ```c uint32_t __get_PRIMASK (void) ``` -------------------------------- ### CmBacktrace Configuration for FreeRTOS Source: https://context7.com/armink/cmbacktrace/llms.txt Configure CmBacktrace for a FreeRTOS environment by defining macros in `cmb_user_cfg.h`. Ensure that FreeRTOS helper functions for task information are integrated. ```c /* cmb_user_cfg.h */ #include #define cmb_println(...) do { printf(__VA_ARGS__); printf("\r\n"); } while(0) #define CMB_USING_OS_PLATFORM #define CMB_OS_PLATFORM_TYPE CMB_OS_PLATFORM_FREERTOS #define CMB_CPU_PLATFORM_TYPE CMB_CPU_ARM_CORTEX_M3 #define CMB_USING_DUMP_STACK_INFO /* Note: FreeRTOS requires adding vTaskStackAddr/vTaskStackSize/vTaskName helper functions to tasks.c — see demos/os/freertos/stm32f10x for patch */ ``` -------------------------------- ### Cortex-M0 Vector Table Source: https://github.com/armink/cmbacktrace/blob/master/demos/non_os/stm32f10x/Libraries/CMSIS_RVMDK/Documentation/CMSIS_Core.htm Defines the fixed exception names for the start of the vector table on a Cortex-M0 processor. Interrupt handlers are defined as weak functions. ```Assembly __Vectors DCD __initial_sp ; Top of Stack DCD Reset_Handler ; Reset Handler DCD NMI_Handler ; NMI Handler DCD HardFault_Handler ; Hard Fault Handler DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD 0 ; Reserved DCD SVC_Handler ; SVCall Handler DCD 0 ; Reserved DCD 0 ; Reserved DCD PendSV_Handler ; PendSV Handler DCD SysTick_Handler ; SysTick Handler ```