analogdevicesinc / msdk

Software Development Kit for Analog Device's MAX-series microcontrollers
Apache License 2.0
60 stars 75 forks source link

feat(Examples): Add RTOS Debug Features to MAX78000 FreeRTOSDemo #962

Closed Brandon-Hurst closed 3 months ago

Brandon-Hurst commented 3 months ago

Description

Added Debug features to the FreeRTOSDemo for MAX78000. These features are added in such a way as to be easily copyable to most other MCUs in the MSDK.

Summary:

Ideally this would be available at some point for all FreeRTOSDemo Examples or placed inside the MSDK FreeRTOS library. Exposing it inside an example may be preferable as an instructive inclusion for developers. This PR is meant to initiate a dialogue and add some more RTOS Debug features to MSDK. I am also happy to modify anything needed for this PR.

Regarding the HardFault Handler...

Credit to @BrentK-ADI for this portion of the example. The code included is recommended in the FreeRTOS Documentation to improve debugging Hard Faults by grabbing the stack context from which the code failed. Debugging Hard Faults can be notoriously tricky without this information. Link: https://www.freertos.org/Debugging-Hard-Faults-On-Cortex-M-Microcontrollers.html

Testing

RTOS Stats Test

The build was completed and ran successfully on MAX78000FTHR, and RTOS Stats were gathered via the "RTOS Views" extension in VSCode, image below. RTOS Stats

Worth noting is that FreeRTOS's kernel does not smartly handle Timer Overflow on the RTOS Stats Timer, so overflowing the provided counter will give inaccurate results. This is documented within FreeRTOS_Debug.c provided. The default 32-bit, 32 kHz configuration provides nearly 100 days before overflow.

HardFault Handler Test

Hard Fault Analysis was tested via a privileged memory read of address 0xFFFFFFFF inserted into the example. image image

The values shown are from the context which caused the HardFault, not from within the HardFault itself. This streamlines the process of finding the code which caused the fault (in this case located at address 0x1000_083e)