Skip to content

Fix SPI45 2MHz clock source#659

Merged
jorgesg82 merged 1 commit into
developmentfrom
codex/spi45-hsi-2mhz
Jun 2, 2026
Merged

Fix SPI45 2MHz clock source#659
jorgesg82 merged 1 commit into
developmentfrom
codex/spi45-hsi-2mhz

Conversation

@jorgesg82
Copy link
Copy Markdown
Contributor

@jorgesg82 jorgesg82 commented Jun 2, 2026

Summary

  • Route SPI4/SPI5 peripheral clocks from HSI instead of PCLK2 during SPI domain initialization.
  • Explicitly keep HSI enabled at divide-by-1 in the system clock setup.

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

ST-LIB Release Plan

  • Current version: 6.1.2
  • Pending changesets: 1
  • Highest requested bump: patch
  • Next version if merged now: 6.1.3

Pending changes

  • patch Drive SPI4 and SPI5 from HSI for stable 2 MHz BMS transfers (.changesets/spi45-hsi-clock-source.md)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_HSI during 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.

Comment thread Src/HALAL/Models/HALconfig/Halconfig.cpp
Comment thread .changesets/spi45-hsi-clock-source.md Outdated
@jorgesg82 jorgesg82 force-pushed the codex/spi45-hsi-2mhz branch from b8c2c4d to f037ad0 Compare June 2, 2026 18:57
FoniksFox
FoniksFox previously approved these changes Jun 2, 2026
@jorgesg82 jorgesg82 force-pushed the codex/spi45-hsi-2mhz branch from f588e1b to b1df651 Compare June 2, 2026 19:08
@jorgesg82 jorgesg82 merged commit 43cbb1c into development Jun 2, 2026
24 checks passed
@jorgesg82 jorgesg82 deleted the codex/spi45-hsi-2mhz branch June 2, 2026 19:11
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.

3 participants