cancel
Showing results for 
Search instead for 
Did you mean: 

How to set DIVN2 and DIVP2 of PLL2 in code

KSOdin2
Associate III

I have set the clock for the ADC to 51.2MHz by PLL2P with the DIV set as seen below. Without reprogramming the STM32H7A3 I would like to change DIVN2 to x16 and DIVP2 to /32 to give me 4MHz clock to the ADC, but I can not seem to find where these are set in the code.

I Have checked the auto-generated code within main.c and there are no options for x32 and /5. Are DIVN2 and DIVP2 set outside of main.c, and if so where?

Also is there anything else I need to know/do when changing the clock division via the code?

Thank you for any help

0693W00000NqiT8QAJ.pngCurrent clock configuration that is uploaded to the microcontroller, but DIVN2 and DIVP2 will needed to be changed.

1 ACCEPTED SOLUTION

Accepted Solutions
Nikita91
Lead II

You can use:

LL_RCC_PLL2_Disable();

LL_RCC_PLL2_SetN(N) ;

LL_RCC_PLL2_SetP(P) ;

LL_RCC_PLL2_Enable();

// Wait till PLL is ready

while(LL_RCC_PLL2_IsReady() != 1)

{

}

in stm32h7xx_ll_rcc.h

View solution in original post

11 REPLIES 11
jiangfan
ST Employee

Yes. it is possible to set DIVN2 and DIVP2 of PLL2 in code.

by calling HAL_RCCEx_PeriphCLKConfig(), which is defined in stm32h7xx_hal_rcc_ex.c.

refer to one example: function AUDIO_SAIx_Init() in stm32h7b3i_disco_audio.c.

Hi Jiangfan,

Where do I find stm32h7b3i_disco_audio.c? I can't seem to find it on the Cube IDE examples.

Nikita91
Lead II

You can use:

LL_RCC_PLL2_Disable();

LL_RCC_PLL2_SetN(N) ;

LL_RCC_PLL2_SetP(P) ;

LL_RCC_PLL2_Enable();

// Wait till PLL is ready

while(LL_RCC_PLL2_IsReady() != 1)

{

}

in stm32h7xx_ll_rcc.h

How would I do this in main.c. I have a function that has your code in it but the error is "

undefined reference to `LL_RCC_PLL2_Disable' " How would I solve this error?

Also, should I be de initialising the clock like I do with the ADC parameters?

Have you done something like this before out of curiosity?

Edit: Also where did you find stm32h7xx_ll_rcc.h, I can't seem to find it

Edit2: It seems stm32h7xx_ll_rcc.h is in the main repository for H7 on Github and the repository folder of the STM32CubeIDE. But when a new project is created stm32h7xx_ll_rcc.h is not included

//Set timer for the DAC
htim2.Init.Period = 1400-1;
 
if (HAL_TIM_Base_Init(&htim2) != HAL_OK){ Error_Handler();}
 
//De intilise the ADC and re initliase
if (HAL_ADC_DeInit(&hadc1) != HAL_OK) {Error_Handler();	   }
MX_ADC1_Init();
 
LL_RCC_PLL2_Disable();
LL_RCC_PLL2_SetN(16) ;
LL_RCC_PLL2_SetP(32) ;
LL_RCC_PLL2_Enable();
 
// Wait till PLL is ready
 
while(LL_RCC_PLL2_IsReady() != 1)
{
int a;
}
 

Example of my code which is in a function that is called.

Need better Windows tools, and File Manager

STM32Cube_FW_H7_V1.8.0\Drivers\BSP\STM32H7B3I-DK\stm32h7b3i_discovery_audio.c

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

Did you include the file stm32h7xx_ll_rcc.h.

Did you add the stm32h7xx_ll_rcc.c file to your project?

Hi, I did add these files and It works. These files are not generated by default by STM32CUBEIDE by default. They do get deleted if you regenerate the code.

Using your example allowed me to change the clock thank you! Just have to ensure it is done after ADCInit() otherwise ADCinit() will overwrite any changes I make.

Thanks again Nikita!