cpu/stm32f[2|4|7]: unify stmclk and improve PLL configuration#7477
cpu/stm32f[2|4|7]: unify stmclk and improve PLL configuration#7477kaspar030 merged 4 commits intoRIOT-OS:masterfrom
Conversation
|
side questions: as both files look (very) similar can (or should) this go into |
|
@MichelRottleuthner might be interesting for you, too? |
|
@smlng I unified stm32f2,4,7 stmclk files in stm32_common. It might be adapted to other stm32... Changed PR title accordingly |
|
nice work! Hope, it doesn't break existing stuff 🤞 We only have very few STM nucleos available for testing, |
|
I think it would need some more documentation on how to configure everything, does someone have an idea where is the best place to write that? |
|
though this needs some squashing, still Murdock can have a first look on this. |
how about |
|
Added coreclock max value check and documentation (doc.txt in cpu/stm32_common) |
|
Removed coreclock check as RCC_MAX_FREQUENCY seems to be defined only for f4. |
|
I split the configuration in one header per PLL. Now, main PLL, PLLI2S and PLLSAI can be configured. |
aabadie
left a comment
There was a problem hiding this comment.
A few comments and question. Otherwise this is very good job. I'll be able to test that on hardware next week.
cpu/stm32_common/clk/pll.h
Outdated
| #define _PLL_N_FINISHED 1 | ||
| #endif | ||
| #if !_PLL_N_FINISHED | ||
| #undef P |
There was a problem hiding this comment.
Are those lines needed, since the macro are redefined just below ?
There was a problem hiding this comment.
yes because P could be already defined above, which would cause a preprocessor error on the (re)define below.
cpu/stm32_common/clk/plli2s.h
Outdated
| #define PLLI2S_SRC RCC_PLLI2SCFGR_PLLI2SSRC | ||
| #else | ||
| #define PLLI2S_IN PLL_IN | ||
| #define PLLI2S_SRC 0 |
cpu/stm32_common/doc.txt
Outdated
| /** | ||
| * @ingroup cpu | ||
| * @defgroup cpu_stm32_common STM32 common | ||
| * @{ |
There was a problem hiding this comment.
I don't think this block @{ is required.
There was a problem hiding this comment.
yep, I think the block is not needed, too - though it doesn't hurt either. Still I would re-order that to:
/**
* @defgroup cpu_stm32_common STM32 common
* @ingroup cpu
* @brief STM32 common configurations
[ * @{ ] <- optional
*
the @brief should be above @{ (if still used)
does it simplify [edit] things/configuration [/edit], because looks like you introduced lots of duplicate code/macros and more LOCs now than with the single header before, |
There is more features now. A lot can be calculated automatically. And the problems with macro are:
|
|
Refactored some macros |
84ca10b to
c6db16f
Compare
|
a big +1 for the changes in general. However, the macro-code is very hard to read and will be extremely hard to maintain in the future! Without having tried this: but couldn't we solve a lot of this functionality using inline functions? As all parameters are constants, the compiler should actually be able reduce those inline functions to constant expressions, right? Especially when building with |
I can only agree with that ;) even if I tried my best to have something easy to read.
I don't know if it's really possible. I can give a try. But I would like to avoid any runtime computation, as the clock init is called when waking up where saving time is important. |
|
Another idea would be to write that in an external tool (in python for instance) and generate the right constants.
|
I think I would like that. How about something simple in C like I did for the computation of SPI clock frequencies -> |
I know, when I wrote smaller, I meant, less line duplication (same init value -> line duplication) ;) I think I found a way. I'll try to push something this afternoon. |
|
nice! |
|
Refactored |
|
nice, I like it! |
|
Fixed some wrong APB values, fixed spaces, updated boards. Should be OK now! |
|
Removed stm32f0 code from clk_conf (will be added in #7500) |
haukepetersen
left a comment
There was a problem hiding this comment.
Just some minor remarks left, otherwise I think this PR is good to go.
| puts(""); | ||
|
|
||
| printf("/**\n" | ||
| " * @name Clock settings\n" |
There was a problem hiding this comment.
indention slipped off, should be tab aligned -> @name Clock settings
There was a problem hiding this comment.
Sorry, I don't understand
There was a problem hiding this comment.
all the comments in the perihp_conf.h have the equivalent spaces to a tab character after the @brief/@name -> leading to 3 spaces after a @brief and 4 spaces after a @name. So this should be also outputted by the clk_conf tool so that the comment style is consistent in the periph_conf.h files.
There was a problem hiding this comment.
Ok, I didn't know that. Will fix.
| printf("/**\n" | ||
| " * @name Clock settings\n" | ||
| " *\n" | ||
| " * @note This is auto-generated from\n" |
| "#define CLOCK_HSE (%uU)\n", pll_src ? pll_in : 0); | ||
| printf("/* 0: no external low speed crystal available,\n" | ||
| " * 1: external crystal available (always 32.768kHz) */\n" | ||
| "#define CLOCK_LSE (%d)\n", is_lse); |
There was a problem hiding this comment.
how about (%dU) to make it consistent with CLOCK_HSE?
|
one more thing I just noticed: could you add Thanks! |
|
|
||
| /* Print constants */ | ||
| puts("=============================================================="); | ||
| puts("Please copy the following code into your board's periph_conf.h"); |
There was a problem hiding this comment.
please make it somehow possible to do this automatically. Either by using stderr for all other output, or by (maybe optionally) writing the actual code into a file.
There was a problem hiding this comment.
(we can do that as followup. @haukepetersen feel free to dismiss my review if you're happy.)
There was a problem hiding this comment.
Used stderr for evrything but code. Is it OK?
| puts(""); | ||
|
|
||
| printf("/**\n" | ||
| " * @name Clock settings\n" |
There was a problem hiding this comment.
sorry, still one space missing.
There was a problem hiding this comment.
crap, I can't count up to 4! :D
Should be OK now
haukepetersen
left a comment
There was a problem hiding this comment.
Looking good -> ACK from my side
fd96c36 to
674fd1e
Compare
|
Oops, maybe I squashed a bit quickly. @kaspar030 any objections? |
674fd1e to
63704bc
Compare
63704bc to
fc9fc57
Compare
|
@kaspar030, your comment has been addressed. Are you fine with the change ? |
|
&go! |
When initializing PLL, input frequency was hard-coded to 2Mhz, leading to invalid output frequency when the crystal is not an even frequency (25MHz for instance).
Now, PLL input frequency can be configured (
PLL_IN_FREQ) and PLL M and N factors are checked.