2022-05-26 06:43 AM
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
Current clock configuration that is uploaded to the microcontroller, but DIVN2 and DIVP2 will needed to be changed.
Solved! Go to Solution.
2022-05-26 08:23 AM
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
2022-05-26 07:58 AM
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.
2022-05-26 08:10 AM
Hi Jiangfan,
Where do I find stm32h7b3i_disco_audio.c? I can't seem to find it on the Cube IDE examples.
2022-05-26 08:23 AM
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
2022-05-26 08:53 AM
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.
2022-05-26 09:19 AM
Need better Windows tools, and File Manager
STM32Cube_FW_H7_V1.8.0\Drivers\BSP\STM32H7B3I-DK\stm32h7b3i_discovery_audio.c
2022-05-26 02:06 PM
Did you include the file stm32h7xx_ll_rcc.h.
Did you add the stm32h7xx_ll_rcc.c file to your project?
2022-05-26 06:17 PM
from https://github.com/STMicroelectronics/
https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Drivers/BSP/STM32H7B3I-DK
you may see stm32h7b3i_disco_audio.c
2022-05-26 06:20 PM
from https://github.com/STMicroelectronics/
https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Drivers/STM32H7xx_HAL_Driver/Inc
you may see stm32h7xx_ll_rcc.h, and other HAL and LL(Low Level) header files.
2022-05-27 07:31 AM
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!