Skip to main content
MSale.1
Senior
July 9, 2020
Question

How to measure MCU Load while using TouchGFX?

  • July 9, 2020
  • 2 replies
  • 1478 views

..

This topic has been closed for replies.

2 replies

Alexandre RENOUX
Visitor II
July 9, 2020

Hello,

You can refer to any Application Template available on TouchGFX Designer but for instance you can look at the Application Template STM32F746G-DISCO with the TouchGFX Demo 1. This will tell you how both on the hardware development and GUI development side you implement the MCU load.

/Alexandre

Martin KJELDSEN
Principal III
July 17, 2020

Here's a few extra pointers to look for in any of the demos that Alexandre mentioned.

This code is required in FreeRTOSConfig.h

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
#define traceTASK_SWITCHED_OUT() xTaskCallApplicationTaskHook( pxCurrentTCB, (void*)1 )
#define traceTASK_SWITCHED_IN() xTaskCallApplicationTaskHook( pxCurrentTCB, (void*)0 )
/* USER CODE END Defines */

If you're using FreeRTOS - this code is required in your OSWrappers.cpp. We don't have examples for other OS.

// FreeRTOS specific handlers
extern "C"
{
 void vApplicationStackOverflowHook(xTaskHandle xTask,
 signed portCHAR* pcTaskName)
 {
 while (1);
 }
 
 void vApplicationMallocFailedHook(xTaskHandle xTask,
 signed portCHAR* pcTaskName)
 {
 while (1);
 }
 
 void vApplicationIdleHook(void)
 {
 // Set task tag in order to have the "IdleTaskHook" function called when the idle task is
 // switched in/out. Used solely for measuring MCU load, and can be removed if MCU load
 // readout is not needed.
 vTaskSetApplicationTaskTag(NULL, IdleTaskHook);
 }
}

Then some MCU Instrumentation is required in order to get the clocl cycle count for a particular MCU family, in this case F7 - TouchGFX HAL will call these functions if instrumentation is configured.

#include <bsp/STM32F7Instrumentation.hpp>
#include <touchgfx/hal/HAL.hpp>
 
extern "C"
{
#include "stm32756g_eval_sdram.h"
#include "stm32756g_eval_lcd.h"
#include "stm32756g_eval_io.h"
#include "stm32756g_eval_nor.h"
#include "stm32f7xx_hal_dma.h"
#include "stm32f7xx_hal_qspi.h"
#include "stm32f7xx_hal_rcc_ex.h"
#include "stm32f7xx_hal_tim.h"
}
namespace touchgfx
{
TIM_HandleTypeDef tim;
 
void STM32F7Instrumentation::init()
{
 __TIM2_CLK_ENABLE();
 tim.Instance = TIM2;
 tim.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 tim.Init.CounterMode = TIM_COUNTERMODE_UP;
 tim.Init.Period = 0xFFFFFFFF;
 tim.Init.Prescaler = 0;
 tim.Init.RepetitionCounter = 1;
 HAL_TIM_Base_Init(&tim);
 HAL_TIM_Base_Start(&tim);
}
 
//Board specific clockfrequency
unsigned int STM32F7Instrumentation::getElapsedUS(unsigned int start, unsigned int now, unsigned int clockfrequency)
{
 return ((now - start) + (clockfrequency / 2)) / clockfrequency;
}
 
 
unsigned int STM32F7Instrumentation::getCPUCycles()
{
 return __HAL_TIM_GET_COUNTER(&tim);
}
 
void STM32F7Instrumentation::setMCUActive(bool active)
{
 if (active) //idle task sched out
 {
 cc_consumed += getCPUCycles() - cc_in;
 }
 else //idle task sched in
 {
 cc_in = getCPUCycles();
 }
}
}