Skip to content

STM32H7a3ZI-q SPI bus speed is half of what is set #81520

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

Closed
CodingGhost opened this issue Nov 18, 2024 · 3 comments
Closed

STM32H7a3ZI-q SPI bus speed is half of what is set #81520

CodingGhost opened this issue Nov 18, 2024 · 3 comments
Assignees
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug Stale Waiting for response Waiting for author's response

Comments

@CodingGhost
Copy link
Contributor

CodingGhost commented Nov 18, 2024

when using SPI (Im using SPI4) on the stm32H7a3ZI-q, the actual SCK Frequency is half of what is set in the configuration.
Im testing this on current master, this is my configuration:

static struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_MASTER | SPI_LINES_SINGLE |  SPI_HOLD_ON_CS,
	.frequency = 8000000,
	.slave = 0,
	.cs = 0,
};

&spi4 {
	status = "okay";
	label="ARDUCAM_MEGA";
	pinctrl-0 = <&spi4_sck_pe12 &spi4_miso_pe13 &spi4_mosi_pe14>;
	pinctrl-names = "default";
	cs-gpios = <&gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
	clock-frequency=<8000000>;
	
	arducam_mega: arducam_mega@0 {
		compatible = "masjao,arducam_mega";
		reg = <0>;
		spi-max-frequency=<8000000>;
	};
	
};

Expected behavior
I Expect the Bus to operate at the frequency that I have configured.

Impact
It seems like just configuring the Bus to 16MHZ when I actually need 8MHZ works as a workaround. But this was very confusing and costs some time to figure out as I didnt know why I had massive performance problems.

Logs and console output
SPI debug logging is too much for the uart to handle, but the messages that I do see on init are no problem.

@CodingGhost CodingGhost added the bug The issue is a bug, or the PR is fixing a bug label Nov 18, 2024
@JarmouniA JarmouniA added area: SPI SPI bus platform: STM32 ST Micro STM32 labels Nov 18, 2024
@erwango erwango added the priority: low Low impact/importance bug label Nov 19, 2024
@djiatsaf-st
Copy link
Collaborator

After testing on my side, I was able to observe the same behavior that you pointed out on an oscilloscope. After investigation, it is not surprising that we need to modify the clock to achieve the desired frequency of the SCK.

You must first understand that there are three frequencies involved here:

  • The frequency of the system clock source that supplies the SPI bus
  • The frequency of the SPI bus (FreqSPI)
  • The baud rate or the SCK frequency (Fsck).

When you configure:
clock-frequency=<8000000>; and .frequency = 8000000,

in reality, you are configuring the frequency of the SPI bus and not the baud rate as mentionned here https://docs.zephyrproject.org/apidoc/latest/structspi__config.html#aa1ec6933fe66f91653c5be488e4c9b2a and here https://docs.zephyrproject.org/latest/build/dts/api/bindings/spi/st%2Cstm32-spi.html#dtbinding-st-stm32-spi .

The baud rate = FreqSPI * prescaler (½ by default). We have a finite range of prescalers (½, ¼, …, 1/256) already defined in STM32 SPI driver.

So, if you configure an SPI bus frequency of 8 MHz with the prescaler of ½ by default, you get a baud rate or Fsck of 4 MHz. To achieve 8 MHz, you must double the frequency of the SPI bus.

I think the SPI driver will approximate the baud rate based on the frequency of the SPI bus and the prescalers to have a value that is as close as possible to the desired baud rate. Therefore, it may sometimes be necessary to change the clock source of the SPI bus to have a frequency that allows us to obtain the desired baud rate.

Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Feb 16, 2025
@erwango erwango added the Waiting for response Waiting for author's response label Feb 18, 2025
@github-actions github-actions bot removed the Stale label Feb 19, 2025
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Apr 20, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus bug The issue is a bug, or the PR is fixing a bug platform: STM32 ST Micro STM32 priority: low Low impact/importance bug Stale Waiting for response Waiting for author's response
Projects
None yet
Development

No branches or pull requests

4 participants