Skip to content
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

Full RCC support for STM32F107 #3779

Merged
merged 4 commits into from
Jan 24, 2025
Merged

Conversation

algesten
Copy link
Contributor

@algesten algesten commented Jan 16, 2025

STM32F107 has a two more PLLs than F013, which means using f013.rs config options doesn't let us configure the entire RCC.

My use case is to use STM32F107 for ethernet with an external HSE.

This PR adds a special case for F107 with a fuller RCC config.

@algesten algesten marked this pull request as ready for review January 16, 2025 11:16
@Dirbaio
Copy link
Member

Dirbaio commented Jan 16, 2025

instead of adding a new f107.rs file, could you add support for the PLLs in f013.rs using cfg's like cfg(stm32f107)?

(We used to have code duplication like this in RCC a while ago and it proved to be an unmaintainable mess. Hard to keep them in sync with fixes and features. the file you've added is already out of sync, for example it does .unwrap() instead of unwrap!(..) and is missing the asserts for min/max frequencies)

@algesten
Copy link
Contributor Author

@Dirbaio sure. Is there some thinking of how these are bundled together? Like, why is f107 sorted under f013? Like is there some arch concept that certain groups of STM32 belongs together?

@Dirbaio
Copy link
Member

Dirbaio commented Jan 16, 2025

Yes, they're grouped by "what STM32 families are more similar". ST did some design for the F1, then F107, F3, F0 are incremental improvements on top of that but the "overall structure" stays very similar. OTOH they designed the PLLs very differently for F2, then F4, F7 are incremental improvements on top of that. Etc etc.

(f013 means "STM32F0 + STM32F1 + STM32F3", not "STM32F013")

@algesten
Copy link
Contributor Author

@Dirbaio thanks for explaining.

I have pushed an update where I try to merge the changes into f013.rs. Hopefully it's closer to what you want.

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice! thank you 🚀

@Dirbaio Dirbaio added this pull request to the merge queue Jan 24, 2025
@algesten
Copy link
Contributor Author

@Dirbaio thanks! Just one thing more to fix. There's an exported PreDiv1Src I don't believe I need anymore.

@algesten
Copy link
Contributor Author

Just going to check with my board as well, just to make sure I didn't break anything.

@Dirbaio Dirbaio removed this pull request from the merge queue due to a manual request Jan 24, 2025
@algesten
Copy link
Contributor Author

Yeah. It's not working. Need to figure out why.

@algesten
Copy link
Contributor Author

@Dirbaio found it. The problem was that set_prediv1src must be set after configuring the PLL.

I think we're good to go!

@Dirbaio
Copy link
Member

Dirbaio commented Jan 24, 2025

oh huh. shouldn't it be the other way around? if pll1 is fed from pll2, init order should be prediv2, pll2, prediv1, pll1.

With the previous code it'd fail because you were starting pll1 without starting pll2 first, which would hang because it'd have no clock. Now you're leaving pll1 source as default (so, from HSE), then initialize it (which works because it has a clock), then switch it to pll2 while it's already running. I don't think it's allowed to change a pll source clock while it's running.

@algesten
Copy link
Contributor Author

I don't think it's allowed to change a pll source clock while it's running.

Right. It works, but maybe is dodgy :)

I'll revise the code to ensure the order is correct for: prediv2, pll2, prediv1, pll1

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@Dirbaio Dirbaio added this pull request to the merge queue Jan 24, 2025
Merged via the queue into embassy-rs:main with commit 4e3d066 Jan 24, 2025
7 checks passed
@algesten algesten deleted the fix/f107-rcc branch January 24, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants