cpu: stm32: convert preprocessor if to compiler if statement#7502
cpu: stm32: convert preprocessor if to compiler if statement#7502jnohlgard merged 1 commit intoRIOT-OS:masterfrom
Conversation
doesn't work 😉 increases binary size by 8B compared to master, tested with However, this approach also opens a more general discussion on how to handle that in RIOT overall: macros vs. real code. |
| #if CLOCK_HSE | ||
| if ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI) { | ||
| RCC->CR &= ~(RCC_CR_HSION); | ||
| if (CLOCK_HSE) { |
There was a problem hiding this comment.
IIRC some compilers, e.g. clang, may complain about tautological compare if CLOCK_HSE is 0 rendering this if always false and hence obsolete.
There was a problem hiding this comment.
though I know, we don't use clang for ARM (currently/yet) but newer GCC might also be not happy?
There was a problem hiding this comment.
You can try it with
make TOOLCHAIN=llvm
4370e36 to
ead7ae1
Compare
Same size here, with arch linux |
Doesn't complain! |
|
(I messed up the latest rebase) |
fixed |
fcd8130 to
1f1fd71
Compare
cpu/stm32_common/stmclk_common.c
Outdated
| RCC->REG_LSE |= BIT_LSEON; | ||
| while (!(RCC->REG_LSE & BIT_LSERDY)) {} | ||
| stmclk_dbp_lock(); | ||
| } else { |
There was a problem hiding this comment.
Make this two lines:
}
else {
cpu/stm32_common/stmclk_common.c
Outdated
| RCC->REG_LSE &= ~(BIT_LSEON); | ||
| while (!(RCC->REG_LSE & BIT_LSERDY)) {} | ||
| stmclk_dbp_lock(); | ||
| } else { |
|
Looks fine to me, apart from the minor nit on the else statements. Feel free to squash immediately. |
Fixed & squashed. |
1f1fd71 to
6d18a51
Compare
jnohlgard
left a comment
There was a problem hiding this comment.
tested on samr21-xpro, no changes in build size. ACK
As
CLOCK_HS[EI]are always defined as either 0 or 1, we can use conventional compiler if instead of preprocessor#if, and rely on the optimizer to drop the dead code.