-
Notifications
You must be signed in to change notification settings - Fork 67
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
Cannot calculate PLL for stm32f303xc with 8MHz HSE running at maximum speed (72MHz) #151
Comments
Hey it's me who implemented that logic. Thanks for the report. I implemented the logic while referencing the data sheet As seen in the clock tree, PLLSRC is divided by 2 at least, so with 8 MHz HSE Crystal, 72 MHz are indeed not reachable as you observed. For this case I implemented this check Lines 373 to 378 in 54e8261
As you can see, for devices like the stm32f303xD, these constraints on the Lines 448 to 452 in 54e8261
I hope this logic is correct, but I only referenced the data sheet (which can be wrong sometimes). Maybe STM32CubeIDE is right and this constrain on PLLDIV is really not an In general the greatest-common-divisor function should generate the TBH, I've not tested it on hardware. Is the code, which you are |
I didn't notice the datasheet was only listing
I double checked the MCU I'm using and it's indeed an
Yes. I didn't measure the clock directly, but a few peripherals all worked fine:
|
That is good to here. But I don't really know how to go about this change. In the datasheet, there is no information about PLL_DIV not being able to be set to 1, IIRC (except the clock tree drawing). So I would go and look at stmCubeIDE for most of the chip, which are effected by this (probably) wrong conditional: Lines 373 to 378 in 54e8261
Side-Note: I hope to make this code more ergonomic for the user sometime. Assertion are not really idiomatic in a library, and it is not really obvious for embedded controllers, when assertions are hit, as you have to debug it, to see, if the chip clock is misconfigured. Either the Line 517 in 54e8261
Or include |
Looking at the register descriptions in the RM it looks like the clock tree is simply inaccurate. For the PREDIV field in RCC_CFGR2 (which is the one we are concerned about I believe) the RM says:
(section 9.4.12) Note that setting the value to As an additional datapoint, I was definitely able to achieve 72 MHz on my F3DISCOVERY with the built-in HSE. That was using my own HAL, with this RCC abstraction: https://gitlab.com/ra_kete/stm32f303xc-hal/-/blob/master/src/rcc.rs (which doesn't bother with setting PREDIV at all). |
Hi, I was having trouble setting a 72MHz sysclk with an 8MHz HSE.
Through a little bit of debugging I found out
fn calc_pll
might not be deriving the correct divisor and multiplier for this configuration, causing an assertion to fail.For reference, here's a clock configuration generated by STM32CudeIDE:
Here are some of my guesses, but since I'm new to this project and embedded in general, please take what I say with a grain of salt:
9/1
is perfectly representable yetcalc_pll
rejects it by making it18/2
. The comments say the minimal value for bothPLL_MUL
andPRE_DIV
is 2, but STM32CudeIDE usesRCC_HSE_PREDIV_DIV1
andRCC_PLL_MUL9
in the code it generates and sincePREDIV_A
does have aDIV1
variant, should we try doubling only when the multiplier is 1?calc_pll
represents the ratio as12/2
instead of6/1
.N/M
whereN
andM
are integers such that2 <= N <= 16
and1 <= M <= 16
". Although it's unlikely this alone is sufficient for a valid clock configuration.Anyway, I'd be happy to put up a PR if someone could confirm my guesses or point me in the right direction.
The text was updated successfully, but these errors were encountered: