Fix SPI45 2MHz clock source#659
Merged
Merged
Conversation
Contributor
ST-LIB Release Plan
Pending changes
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make SPI4/SPI5 clocking deterministic for a 2 MHz baud request (notably for HVBMS) by sourcing SPI45 from the 64 MHz HSI clock rather than the APB clock path, and by ensuring HSI remains enabled during system clock setup.
Changes:
- Enable/configure HSI in
HALconfig::system_clock()so SPI45 can reliably use HSI. - Switch SPI4 and SPI5 peripheral clock selection to
RCC_SPI45CLKSOURCE_HSIduring SPI domain initialization. - Add a patch changeset documenting the SPI45 clock-source change.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Src/HALAL/Models/HALconfig/Halconfig.cpp | Updates oscillator configuration to include HSI so it can be used as a peripheral clock source. |
| Inc/HALAL/Models/SPI/SPI2.hpp | Routes SPI4/SPI5 peripheral clocks to HSI when initializing SPI instances. |
| .changesets/spi45-hsi-clock-source.md | Adds release note entry describing the SPI45 clock-source change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b8c2c4d to
f037ad0
Compare
FoniksFox
previously approved these changes
Jun 2, 2026
f037ad0 to
f588e1b
Compare
f588e1b to
b1df651
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
The current code drives SPI4/SPI5 from PCLK2. With the board clock tree, that source is not an exact power-of-two multiple of 2 MHz, so the SPI prescaler calculation cannot land exactly on the requested BMS SPI rate.
HSI provides a 64 MHz source. With the existing 2 MHz max baud request, ST-LIB selects the /32 SPI prescaler, producing a deterministic 2 MHz SPI4 SCK.
Important
This is need for the HVBMS to work properly
Warning
This may affect other boards that use SPI4 with a different baudrate, if the requested one cannot be properly determined prescaling 64MHz