Skip to content

Conversation

@jerome-pouiller
Copy link
Contributor

tests/drivers/spi/spi_loopback reported Rx errors on the last bit when requested frequency was > 40MHz. This was mainly caused by misuse of GSPI_DATA_SAMPLE_EDGE.

This PR take advantage of this change to slightly clean up the SPI driver.

I have successfully tested with code at 40Mhz and 80Mhz.

The bit_rate variable does not bring any benefit.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
In functions requiring to lock/release resources, it is less error prone to
have only one exit point and user goto to manage errors.

The behavior of the new code is exactly identical to the initial one.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Until now, GSPI_DATA_SAMPLE_EDGE was enabled as soon as the user requested
> 40Mhz (even if the actual frequency was in fact 40Mhz). However, at 40MHz
and at 80MHz, use of GSPI_DATA_SAMPLE_EDGE generated read errors on the
last bit of the transaction:

    Buffer contents are different:
     [...],0xaa,0xaa,0xaa,0xaa,
    vs:
     [...],0xaa,0xaa,0xaa,0xab,

I have not found any case where GSPI_DATA_SAMPLE_EDGE is useful, so this
patch just remove this parameter.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
In gspi_siwx91x_config(), clk_div_factor can't be < 1. Therefore, we can
remove the dead code.

This code has been tested with tests/drivers/spi/spi_loopback, with a PLL
clock configured to 160MHz and a bus clock to 80MHz with success. I have
not found the case where change in GSPI_CLK_CONFIG are required.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Since actual_hz is no more needed, we can simplify
gspi_siwx91x_pick_lower_freq().

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Currently, clk_div_factor is force to 1 if user request more than 110MHz.
However, in this case, gspi_siwx91x_get_divider() will never return 2 or
more, unless the input clock is >= 220MHz. The si91x is not designed for
such high clock frequency. So, this case has never been tested.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
@sonarqubecloud
Copy link

asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
The bit_rate variable does not bring any benefit.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
In functions requiring to lock/release resources, it is less error prone to
have only one exit point and user goto to manage errors.

The behavior of the new code is exactly identical to the initial one.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
Until now, GSPI_DATA_SAMPLE_EDGE was enabled as soon as the user requested
> 40Mhz (even if the actual frequency was in fact 40Mhz). However, at 40MHz
and at 80MHz, use of GSPI_DATA_SAMPLE_EDGE generated read errors on the
last bit of the transaction:

    Buffer contents are different:
     [...],0xaa,0xaa,0xaa,0xaa,
    vs:
     [...],0xaa,0xaa,0xaa,0xab,

I have not found any case where GSPI_DATA_SAMPLE_EDGE is useful, so this
patch just remove this parameter.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
In gspi_siwx91x_config(), clk_div_factor can't be < 1. Therefore, we can
remove the dead code.

This code has been tested with tests/drivers/spi/spi_loopback, with a PLL
clock configured to 160MHz and a bus clock to 80MHz with success. I have
not found the case where change in GSPI_CLK_CONFIG are required.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
Since actual_hz is no more needed, we can simplify
gspi_siwx91x_pick_lower_freq().

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
asmellby pushed a commit to asmellby/zephyr that referenced this pull request Dec 10, 2025
Currently, clk_div_factor is force to 1 if user request more than 110MHz.
However, in this case, gspi_siwx91x_get_divider() will never return 2 or
more, unless the input clock is >= 220MHz. The si91x is not designed for
such high clock frequency. So, this case has never been tested.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Upstream-status: pr <zephyrproject-rtos#100762>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: SPI SPI bus platform: Silabs Silicon Labs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants