-
Notifications
You must be signed in to change notification settings - Fork 1k
[Question] when is F_CPU macro set? #612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
SystemCoreClock is not a constant so you cannot use it at compile time with pre preprocessor test. |
Is there an alternative I can use depending on the board? |
What is your use case? Sketch? |
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.
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. |
To avoid any issue with `F_CPU` value, it is defined by default to `SystemCoreClock` value which is updated automatically after each clock configuration update. Some libraries use `F_CPU` at build time for conditional purpose (ex to stm32duino#612). This commit allow to redefine it at build time using `build_opt.h` or `hal_conf_extra.h`: https://github.com/stm32duino/wiki/wiki/Custom-definitions then it will be possible to define it as a constant. Important note: **User have to ensure to set it to the proper value.** Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Well after looking at FastLed, it seems it was mainly oriented to STM32F1xx based board. I proposed to be able to redefined #ifndef F_CPU
#define F_CPU SystemCoreClock
#endif But be aware that if a user redefine the Note that, the best should be to be able to handle |
To avoid any issue with `F_CPU` value, it is defined by default to `SystemCoreClock` value which is updated automatically after each clock configuration update. Some libraries use `F_CPU` at build time for conditional purpose (ex to #612). This commit allow to redefine it at build time using `build_opt.h` or `hal_conf_extra.h`: https://github.com/stm32duino/wiki/wiki/Custom-definitions then it will be possible to define it as a constant. Important note: **User have to ensure to set it to the proper value.** Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
F_CPU can now be redefined. |
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? |
You can redefine |
Thank you! |
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.
The text was updated successfully, but these errors were encountered: