Skip to main content
ClaudiaP
Associate
April 24, 2021
Solved

STM32CubeMX, STM32F34R8 autogenerated project for TrueStudio. Prescaler for APB2 is setting the prescaler for APB1

  • April 24, 2021
  • 4 replies
  • 1309 views

Hello All,

I tried to generate a test project with STM32CubeMX version 6.1.2 for micro STM32F334R8. I setup my project to generate mostly LL libraries, when setting the clock configuration, HSI (8MHz RC) is enabled, AHB prescaler is /8, then APB2 prescaler is set to /2. My intention is to have Pclk2 set to 500KHz here.

When I generate the code from STM32CubeMX with these settings, the below SystemClock_Config function is generated. Line 32 is setting again APB1 prescaler, instead of APB2.

Is it a known bug? I have no problem in updating the generated code, but everytime I regenerate the code, I would have to update this line of code. It would be nice also that other people do not have to spend some time trying to debug this.

Is there a more recent version or should I do something different with my STM32CubeMX?

Thanks,

void SystemClock_Config(void)
{
 LL_FLASH_SetLatency(LL_FLASH_LATENCY_0);
 while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_0)
 {
 }
 LL_RCC_HSI_Enable();
 
 /* Wait till HSI is ready */
 while(LL_RCC_HSI_IsReady() != 1)
 {
 
 }
 LL_RCC_HSI_SetCalibTrimming(16);
 LL_RCC_LSI_Enable();
 
 /* Wait till LSI is ready */
 while(LL_RCC_LSI_IsReady() != 1)
 {
 
 }
 LL_PWR_EnableBkUpAccess();
 if(LL_RCC_GetRTCClockSource() != LL_RCC_RTC_CLKSOURCE_LSI)
 {
 LL_RCC_ForceBackupDomainReset();
 LL_RCC_ReleaseBackupDomainReset();
 LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSI);
 }
 LL_RCC_EnableRTC();
 LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_8);
 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
 LL_RCC_SetAPB2Prescaler(LL_RCC_APB1_DIV_2);
 LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSI);
 
 /* Wait till System clock is ready */
 while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
 {
 
 }
 LL_Init1msTick(1000000);
 LL_SetSystemCoreClock(1000000);
}

This topic has been closed for replies.
Best answer by Khouloud OTHMAN

Hi @ClaudiaP​ ,

Good news :smiling_face_with_smiling_eyes: I am pleased to inform you that this issue is fixed in the latest STM32CubeMX version 6.3.0.

Now, LL_RCC_SetAPB2Prescaler is taking correctly LL_RCC_APB2_DIV_2.

Thanks for your contribution.

Khouloud.

4 replies

ClaudiaP
ClaudiaPAuthor
Associate
April 24, 2021

Found out that there is a newer version for STM32CubeMX> 6.2.1. The issue is still there.

Khouloud OTHMAN
Associate
April 26, 2021

Hello @ClaudiaP​ ,

First let me welcome you to the STM32 Community :smiling_face_with_smiling_eyes:

Thanks for your feedback and for raising this issue. You're right LL_RCC_SetAPB2Prescaler should take LL_RCC_APB2_DIV_2 prescaler instead of LL_RCC_APB1_DIV_2.

This will be reported internally to be reviewed and fixed. I'll surely keep you posted with updates.

Sorry for any inconvenience that this may cause.

Thanks a lot for you contribution.

Khouloud.

ClaudiaP
ClaudiaPAuthor
Associate
April 26, 2021

Thanks for your prompt reply, Khouloud!

Khouloud OTHMAN
Khouloud OTHMANBest answer
Associate
August 4, 2021

Hi @ClaudiaP​ ,

Good news :smiling_face_with_smiling_eyes: I am pleased to inform you that this issue is fixed in the latest STM32CubeMX version 6.3.0.

Now, LL_RCC_SetAPB2Prescaler is taking correctly LL_RCC_APB2_DIV_2.

Thanks for your contribution.

Khouloud.