Setup external clock (HSE) at project level
Posted: Thu Apr 01, 2021 1:15 am
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!
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!