2020-06-17 09:36 AM
I would like to modify the clock of STm32h7b3-dk kit and make sure I get different frequency to run different tasks in FreeRTOS, I have checked SystemClock_Config() in main file and stm32h7xx_hal_rcc_ex.c and stm32h7xx_hal_rcc.c file . I would like to set to HSI,CSI,HSE,PLL-I clock sources and make sure the system runs on any of the clock sources, And I would like to run a Task with that particular frequency.
Can we achieve it by modifying the definition of SystemClock_Config()
static void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
HAL_StatusTypeDef ret = HAL_OK;
/*!< Supply configuration update enable */
HAL_PWREx_ConfigSupply(PWR_DIRECT_SMPS_SUPPLY);
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet.
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/* Enable HSE Oscillator and activate PLL with HSE as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 12;
RCC_OscInitStruct.PLL.PLLN = 280;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLR = 2;
RCC_OscInitStruct.PLL.PLLQ = 2;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1;
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
if(ret != HAL_OK)
{
while(1) {};
}
/* Select PLL as system clock source and configure bus clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | \
RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_D3PCLK1);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
if(ret != HAL_OK)
{
while(1) {};
}
}
}
Please do let me know how this can be achieved.
Thanks and Regards
Abhijith N.M.
2020-06-17 05:00 PM
There isn't really a way to do this. The RTOS switches between tasks as needed, and there isn't a way to inject a clock change between tasks. Why would you want different clocks for each task?
2020-06-17 05:15 PM
Hello Team
2020-06-17 05:32 PM
Hello Team,
We have different clock sources in the source code. We Can set the HSI,CSI,HSE,PLL-I clock source only during clock initialization ? There is separate clock for peripherals being connected, how can we switch to the separate clock source when we are using the peripherals ??
We can have a different clock frequency for the tasks being run in the board and different frequency For the peripheral operation at the same time ?
Clock source is set only during clock initialization ?? we cannot modify the clock when the board is up and running ?
How do we change the clock source during runtime for any operation ?
In Linux we can achieve different clock frequency for the the different tasks being run I am trying to achieve the same using FreeRTOS,
Hence I came up with the above question.
2020-06-17 05:35 PM
Hello Team,
I need to change the clock source from HSE to CSI , if I just make changes in the structure containing the member “Oscillator type�? in the source code that would be sufficient or I need to change at few other places ? Please do let me know Where all to change to achieve different clock frequency.
please do the needful.
Thanks and Regards
Abhijith N.M.
2020-06-17 05:39 PM
Hello Team,
There are four different modes as per datasheet of stm32h7b3.
Ultra low power Mode.
Medium Low driving
Medium High Driving
High driving.
Please do let me know who’s to switch to these different modes ?
If I cannot run tasks with different frequency atleast I would try to run Tasks in different modes since different modes have different operating voltages.
Thanks and Regards
Abhijith N.M.
2020-06-17 06:34 PM
Peripherals mainly function with there own clocks internally, and interact with you at the bus clock.
Tasks tend to get paced by Timers.
It would help significantly if you read and understood the content of the Reference Manual. At the very least to the point you grasp the interactions, which you have to share, and which impact performance or are critical to desired operation.
You can't change the PLL settings while it is running, you can change the CPU/Bus clocks, but there might be ramifications for baud rates, pixel clocks, etc.
Where possible find a combination of clocks that work with everything you have running, and sleep the idle processor to save power.
2020-06-17 11:25 PM
Create your different tasks and then set vTaskDelay(delayPeriod) for each task in the for loop. In this case taskFreq = 1/delayPeriod, and you have what you asked for.