Showing results for 
Search instead for 
Did you mean: 

Hello Team, I would like to modify the clock of STm32h7b3-dk kit and make sure I get different frequency to run different tasks in FreeRTOS,

Associate II

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 */


 /* 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.




 /* 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.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;



 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.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.


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?

If you feel a post has answered your question, please click "Accept as Solution".
Associate II

Hello Team

Associate II

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.

Associate II

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.

Associate II

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.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Associate III

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.