You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the following F_CPU macro in a library: #define F_CPU SystemCoreClock
This macro is found in stm32_def.h.
The problem is that SystemCoreClock is not resolved to a value at that time and the compiler complains that it is not a compile time constant when I try to use it.
Is there any way I can use it properly in a library? I expect to get the SystemCoreClock value.
I am trying to add support for FastLED using this Arduino STM32 Core.
It defines F_CPU but it seems to be overwritten during compile time by the macro used here, that is why during compilation it complained about not being a compile time constant.
the value of 'SystemCoreClock' is not usable in a constant expression
I already added support for the BluePill (See PR on the FastLED project) but I wanted to add all STM32 boards which this core supports.
It would be easier if I could use some macro that specifies the clock frequency for the board. Because now I had to use some workaround and speciffy the frequency manually.
Well after looking at FastLed, it seems it was mainly oriented to STM32F1xx based board.
I proposed to be able to redefined F_CPU in stm32_def.h.
#ifndefF_CPU#defineF_CPU SystemCoreClock
#endif
But be aware that if a user redefine the SystemClock_Config then this would not be aligned if the F_CPU is fixed in FastLed library.
Else it is possible to define it at build time using build_opt.h or hal_conf_extra.h: https://github.com/stm32duino/wiki/wiki/Custom-definitions
Note that, the best should be to be able to handle F_CPU during execution as the SystemCoreClock
can change during execution (low power mode,...). In fact, this is not a constant value even in the most use case it is.
I would like to lower the clock, to try to reduce the consumption (currently about 27mA and 9mA in sleep mode) found a reference (Table 6*) that may indicate a significant reduction in consumption by reducing the clock.
How can I implement the clock setting during operation?
You can redefine SystemClock_Config at sketch level to change running freq F_CPU do not forgot using extern "C" in front of the definition.
Else try the STM32LowPower library.
Else you can create dedicated function to change it during execution but ensure that all peripherals clock kept the same freq or if you change it ensure to reinit them properly to take in account your changes. Ex if you use Serial and you change its input clock freq then you will hace to reinit it else the baudrate would probably not correct.
Activity
fpistm commentedon Aug 24, 2019
SystemCoreClock is not a constant so you cannot use it at compile time with pre preprocessor test.
GianniDPC commentedon Aug 24, 2019
Is there an alternative I can use depending on the board?
fpistm commentedon Aug 24, 2019
What is your use case? Sketch?
GianniDPC commentedon Aug 24, 2019
I am trying to add support for FastLED using this Arduino STM32 Core.
It defines F_CPU but it seems to be overwritten during compile time by the macro used here, that is why during compilation it complained about not being a compile time constant.
the value of 'SystemCoreClock' is not usable in a constant expressionF_CPU declaration in FastLED
I already added support for the BluePill (See PR on the FastLED project) but I wanted to add all STM32 boards which this core supports.
It would be easier if I could use some macro that specifies the clock frequency for the board. Because now I had to use some workaround and speciffy the frequency manually.
Allow F_CPU redefinition
fpistm commentedon Aug 26, 2019
Well after looking at FastLed, it seems it was mainly oriented to STM32F1xx based board.
I proposed to be able to redefined
F_CPUin stm32_def.h.But be aware that if a user redefine the
SystemClock_Configthen this would not be aligned if theF_CPUis fixed in FastLed library.Else it is possible to define it at build time using
build_opt.horhal_conf_extra.h:https://github.com/stm32duino/wiki/wiki/Custom-definitions
Note that, the best should be to be able to handle
F_CPUduring execution as theSystemCoreClockcan change during execution (low power mode,...). In fact, this is not a constant value even in the most use case it is.
Allow F_CPU redefinition
fpistm commentedon Aug 27, 2019
F_CPU can now be redefined.
rtek1000 commentedon Sep 27, 2019
Hi,
I would like to lower the clock, to try to reduce the consumption (currently about 27mA and 9mA in sleep mode) found a reference (Table 6*) that may indicate a significant reduction in consumption by reducing the clock.
How can I implement the clock setting during operation?
Table 6*:
https://www.st.com/content/ccc/resource/technical/document/application_note/ff/0a/dc/d2/5e/f5/4b/5a/CD00171691.pdf/files/CD00171691.pdf/jcr:content/translations/en.CD00171691.pdf
https://electronics.stackexchange.com/questions/294209/stm32f103-arm-modifying-clock-at-runtime-flash-latency
fpistm commentedon Sep 28, 2019
You can redefine
SystemClock_Configat sketch level to change running freqF_CPUdo not forgot usingextern "C"in front of the definition.Else try the STM32LowPower library.
Else you can create dedicated function to change it during execution but ensure that all peripherals clock kept the same freq or if you change it ensure to reinit them properly to take in account your changes. Ex if you use Serial and you change its input clock freq then you will hace to reinit it else the baudrate would probably not correct.
rtek1000 commentedon Sep 28, 2019
Thank you!