2019-07-10 05:36 AM
Hello
I want to know the MCU Load, so I found this function
McuLoad = touchgfx::HAL::getInstance()->getMCULoadPct();
I call it in
void Model::tick()
But I always get 0, whatever I do it alwsys returns zero, so I don't think it's working well,
so, how could I resolve the problem? maybe I should call it from another place?
Thank you
Anton
2019-07-11 03:29 AM
@Martin KJELDSEN I think the problem is in TIM1, i checked TIM1->CNT value and it's always = 0, looks like it's not working,
but I don't know why
2019-07-11 03:43 AM
@Martin KJELDSEN
void STM32F4Instrumentation::init()
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
uint32_t pFLatency;
__TIM1_CLK_ENABLE();
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler( );
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
{
Error_Handler( );
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler( );
}
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* TIM2 is on APB1 bus */
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
uwTimclock = HAL_RCC_GetPCLK1Freq();
else
uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
m_sysclkRatio = HAL_RCC_GetHCLKFreq() / uwTimclock;
HAL_TIM_Base_Start(&htim1);
}
This is my timer init code, I change
htim1.Init.Prescaler = 0;
and
htim1.Init.Period = 0;
so, finally getMCULoadPct() returns numbers except 0.
Could you advise how to configure the timer better?
2019-07-11 06:46 AM
Here's the configuration we use for TIM2 for STM32F7.
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);
}
2019-07-14 10:29 PM
Thank you for your time, now it's working
but CPU Load value only has two states 1% and 100%, maybe it's ok
2019-07-22 07:03 AM
Hi @qqAnton and @Martin KJELDSEN ,
I think the problem is in the initialization of the timer.
I selected the TIM1 in Cube, but the initialization (generated) is incorrect (it seems to refer to TIM2).
This is my initialization
static TIM_HandleTypeDef htim1;
void STM32F7Instrumentation::init()
{
#if 1
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
uint32_t pFLatency;
__TIM1_CLK_ENABLE(); //__TIM2_CLK_ENABLE();
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0xFFFFFFFF;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
{
Error_Handler( );
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
{
Error_Handler( );
}
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0xFFFFFFFF;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
{
Error_Handler( );
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
{
Error_Handler( );
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler( );
}
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
sBreakDeadTimeConfig.DeadTime = 0;
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
sBreakDeadTimeConfig.BreakFilter = 0;
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
sBreakDeadTimeConfig.Break2Filter = 0;
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
{
Error_Handler( );
}
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* TIM1 is on APB1 bus */
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
uwTimclock = HAL_RCC_GetPCLK1Freq();
else
uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
m_sysclkRatio = HAL_RCC_GetHCLKFreq() / uwTimclock;
HAL_TIM_Base_Start(&htim1);
#else
__TIM1_CLK_ENABLE();
htim1.Instance = TIM1;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0xFFFFFFFF;
htim1.Init.Prescaler = 0;
htim1.Init.RepetitionCounter = 1;
HAL_TIM_Base_Init(&htim1);
HAL_TIM_Base_Start(&htim1);
#endif
}
2019-08-05 05:05 AM
Hi, i'm back from vacation.
Hmm, that's strange - At which points in time is it going to 100% ? This should only happen if you're e.g. busy-looping somewhere or do not have DMA2D enabled (Using CPU to render everything)
/Martin
2019-08-15 12:03 AM
@qqAnton,
Any updates on your end?
2019-08-15 12:53 AM
@Martin KJELDSEN ,
I think the problem is that I use handleTickEvent() on every screen, where I poll hardware buttons state,
or refresh text on the screen, so CPU is always busy.
2019-09-19 07:34 AM
The Tim1 is 16-bit, The Tim2 is 32-bit.
So Timer selection Tim2.
In file STM32F4Instrumentation.cpp:
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_tim.h"
#include <touchgfx/hal/HAL.hpp>
#include <STM32F4Instrumentation.hpp>
/* USER CODE BEGIN user includes */
/* USER CODE END user includes */
namespace touchgfx
{
static TIM_HandleTypeDef htim2;
void STM32F4Instrumentation::init()
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
uint32_t pFLatency;
__TIM2_CLK_ENABLE();
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim2.Instance = TIM2;
htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 0xffffffff;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler( );
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler( );
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler( );
}
/* Get clock configuration */
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
/* TIM2 is on APB1 bus */
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
uwTimclock = HAL_RCC_GetPCLK1Freq();
else
uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
m_sysclkRatio = HAL_RCC_GetHCLKFreq() / uwTimclock;
HAL_TIM_Base_Start(&htim2);
}
//Board specific clockfrequency
unsigned int STM32F4Instrumentation::getElapsedUS(unsigned int start, unsigned int now, unsigned int clockfrequency)
{
return ((now - start) + (clockfrequency / 2)) / clockfrequency;
}
unsigned int STM32F4Instrumentation::getCPUCycles()
{
return __HAL_TIM_GET_COUNTER(&htim2) * m_sysclkRatio;
}
void STM32F4Instrumentation::setMCUActive(bool active)
{
if (active) //idle task sched out
{
cc_consumed += getCPUCycles() - cc_in;
}
else //idle task sched in
{
cc_in = getCPUCycles();
}
}
}
2019-09-19 07:42 AM
STM32CubeMX :