Skip to content

Conversation

@rob-zeno
Copy link
Contributor

The current stm32 drivers will only enable soft NSS support if the device is using a Zephyr managed GPIO for CS, or if the CONFIG_SPI_STM32_USE_HW_SS flag is set. Neither of these are actually appropriate for a peripheral, which doesn't control CS.

With this change, it is possible for the SPI interface to be configured as a peripheral but still use soft NSS -- otherwise, short of creating a "fake" GPIO configuration, the peripheral will always use hard NSS, and for some boards/configurations, that is unworkable. In the case of a board where the CS is not hooked up, we can use soft NSS to allow the peripheral to assume CS and be driven by the SPI clock signal alone.

Our board has only three signals (clock, COPI, POCI) enabled on one of the SPI interfaces (it is communicating with another MCU on the same board), and works with this change. Without the change, we must enable a "fake" GPIO driver configuration (which is never used for anything, and really makes little sense for a peripheral, but it just happens to force the driver to go down that code path). We cannot disable the CONFIG_SPI_STM32_USE_HW_SS mechanism, as that impacts ALL interfaces, and we have a second interface in controller mode that speaks to flash and requires the NSS_HARD codepath.

@github-actions
Copy link

Hello @rob-zeno, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

type: boolean
description: Swap SPI MOSI and MISO pins

periph-use-soft-nss:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe st,periph-soft-nss

@mathieuchopstm mathieuchopstm added this to the future milestone Oct 29, 2025
The current stm32 drivers will only enable soft NSS support if
the device is using a Zephyr managed GPIO for CS, or if the
CONFIG_SPI_STM32_USE_HW_SS flag is set.  Neither of these are
actually appropriate for a peripheral, which doesn't control CS.

With this change, it is possible for the SPI interface to be
configured as a peripheral but still use soft NSS -- otherwise,
short of creating a "fake" GPIO configuration, the peripheral
will always use hard NSS, and for some boards/configurations,
that is unworkable.  In the case of a board where the CS
is not hooked up, we can use soft NSS to allow the peripheral
to assume CS and be driven by the SPI clock signal alone.

Our board has only three signals (clock, COPI, POCI) enabled
on one of the SPI interfaces (it is communicating with another
MCU on the same board), and works with this change.  Without
the change, we must enable a "fake" GPIO driver configuration
(which is never used for anything, and really makes little
sense for a peripheral, but it just happens to force the
driver to go down that code path).  We cannot disable the
CONFIG_SPI_STM32_USE_HW_SS mechanism, as that impacts ALL
interfaces, and we have a second interface in controller
mode that speaks to flash and requires the NSS_HARD codepath.

Signed-off-by: Rob Newberry <rob@zenomoto.com>
@rob-zeno rob-zeno force-pushed the feature/stm32_spi_softnss_peripheral branch from 700fb95 to 7a31127 Compare October 30, 2025 05:43
@sonarqubecloud
Copy link

Copy link
Contributor

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

otherwise LGTM

(.midi_clocks = DT_INST_PROP(id, midi_clock),)) \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32h7_spi), \
(.mssi_clocks = DT_INST_PROP(id, mssi_clock),)) \
.peripheral_use_soft_nss = DT_INST_PROP(id,periph_use_soft_nss) \
Copy link
Contributor

Choose a reason for hiding this comment

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

As requested by CI + add trailing comma:

Suggested change
.peripheral_use_soft_nss = DT_INST_PROP(id,periph_use_soft_nss) \
.peripheral_use_soft_nss = DT_INST_PROP(id, periph_use_soft_nss), \

@mathieuchopstm mathieuchopstm modified the milestones: future, v4.4.0 Oct 30, 2025
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

LGTM with @mathieuchopstm and CI comment addressed (and with a nitpicking comment).


periph-use-soft-nss:
type: boolean
description: use soft NSS for this interface when in peripheral mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking:

Suggested change
description: use soft NSS for this interface when in peripheral mode
description: Use soft NSS for this interface when in peripheral mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants