Steve Evans of Open Pilot Next Generation (OPNG) explains how they have used Percepio Tracealyzer to finely tune their flight controllers and ensure deterministic performance. They needed to perform some in depth analysis of their code timing, which runs on an STM32F4xx MCU under FreeRTOS.
The best single characteristic of Tracealyzer for FreeRTOS can be summed up in one word… “Visualization”
It displays, with dramatic clarity, what might otherwise go un-noticed, particularly important for a software developer needing to get familiar with a large body of software, especially open-source software which has seen many contributors, not all of whom are available to explain what they’ve done.
An example here is from an interrupt handler used by the Open Pilot Next Generation (OPNG) flight controllers.
In its default display Tracealyzer displays tasks and ISRs (Interrupt Service Routines) as “swim lanes”. Each is labelled at regular intervals and CPU usage by that task or ISR is shown by a solid block of colour. In the above image, clicking on the orange representation of the CPU usage of the EXTI15_10_IRQn ISR in its swim lane causes Tracealyzer to display in the top right pane that the duration of this ISR is 93us. This is rather a long time for an interrupt to execute and has the potential to negatively impact the real time performance of the system. Even an inexperienced developer would find their eye drawn to this large block of time in comparison to the RTC_WKUP_IRQn and OTG_FS_IRQn ISR shown in the same display. Percepio Tracealyzer thus intuitively guides the user to issues worthy of investigation through its visualization. This is something that simply wouldn’t be apparent from conventional source line debugging.
Some quick code inspection revealed that this ISR was performing some SPI bus accesses. Adding some User Events to the code using the Tracealyzer Recorder Library and enabling them by simply checking “User Events” in the lower right pane, gives a very telling picture.
There is clearly time being spent between the claiming of the bus and it’s release, but how much? Clicking on the first event, and then Clicking on the second and FreeRTOS+Trace reveals that 41us is being spent waiting for the second bus access.
Based on this observation, the driver was amended to use SPI DMAs. The end result is shown below, combining the above techniques to show the ISR is now reduced to 26us, with the SPI bus access taking slightly longer at 65us (which meets our requirements). It can be seen that the bus is now being released by the DMA ISR which takes 15us, so the total ISR execution time was reduced from 93us to 26+15=41us, a significant saving.
Percepio’s Tracealyzer has given the OpenPilot Next Generation developers great insight into many such issues resulting in flight controller software with unparalleled performance. Check it out:
Tracealyzer provides over 20 interactive views of the runtime world, connected in clever ways. It is available for several leading real-time operating systems as well as for Linux.
Want to learn more about RTOS-based development and Tracealyzer? More articles here!