Setup external clock (HSE) at project level

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
tyllurius
Posts: 4
Joined: Wed Jan 06, 2021 6:56 pm

Setup external clock (HSE) at project level

Post by tyllurius »

Hey there,

in my project I have an external 16 MHz crystal connected to my STM32F103CB. So I need to reconfigure my clock, by maintaining 72 MHz SYSCLK and 48 MHz for USB. I know that two things need to be done, change the HSE predivider, and adjust the value of HSE. In my case HSE/2, and HSE = 16000000.

I already changed the HSE predivider by redefining the WEAK SystemClock_Config(void) in my sketch (Sloeber Eclipse project) with RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV2.
I saw that adjusting HSE can be done in stm32f1xx_hal_conf_default.h: #define HSE_VALUE 8000000U, but apart that it's inconvenient to change this value all the time (because only this project uses 16 MHz, other projects use 8 MHz from eval boards) I also guess that changing a value in a default file is not a proper way to do it.

For this project I also have two hardware configs, one eval board (8 MHz) and the final board (16 MHz), and I select the proper board per #define. But this #define isn't recognized in stm32f1xx_hal_conf_default.h. So each time I want to compile for my eval board of the final board, I have to change the HSE value.

I found out that copying the stm32f1xx_hal_conf_default.h into the project directory works, so at least this would be a solution to not change the default file, but I guess that's not proper, too. Also, the mentioned #define selection is not working either.

So, is there a way to change the HSE properly outside of the mentioned file?

Thanks and regards!
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Setup external clock (HSE) at project level

Post by fpiSTM »

With Arduino IDE you can define the HSE_VALUE using build_opt.h because value is under !#ifndef in the configuration default but this is not properly managed by Sloeber.
I guess you could add the define in your project configuration.
mwon
Posts: 6
Joined: Fri May 21, 2021 12:25 pm

Re: Setup external clock (HSE) at project level

Post by mwon »

Hi,
I'm having the same problem. Did you figure it how to do it, tyllurius?
tyllurius
Posts: 4
Joined: Wed Jan 06, 2021 6:56 pm

Re: Setup external clock (HSE) at project level

Post by tyllurius »

Hi mwon,

sorry, saw your post only now...

No, I haven't figured it out, because as I read "...but this is not properly managed by Sloeber" I deferred from it, because it took me weeks to get Sloeber running properly with STM32 and I wanted to proceed with my project. But it's still on my list and I will reply as soon as I figure it out.
Have you figured it out?
Post Reply

Return to “General discussion”