Skip to content

drivers: spi: atmel spi_sam0: Reset peripheral on init #90921

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

Merged

Conversation

pdietl
Copy link
Contributor

@pdietl pdietl commented Jun 1, 2025

I ran into a problem where a vendor-provided bootloader also configured the same SPI peripheral before booting my Zephyr application. The bootloader configured the ENABLE32B option to make writes to the DATA register be 32 bits and not 8 bits -- this broke the Zephyr driver. Since the configuration of the SPI peripheral may be arbitrarily configured before the Zephyr driver attempts to initialize it and because the Zephyr SPI driver assumes that the peripheral is in its default state, it makes sense to use the SWRST bit to ensure that the peripheral is indeed in its default state.

@github-actions github-actions bot added platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) area: SPI SPI bus labels Jun 1, 2025
Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Overall LGTM, just small things and CI must be green : )

BTW, you need to follow the commit message guidelines.

I'm looking forward to accept you PR.

@pdietl
Copy link
Contributor Author

pdietl commented Jun 1, 2025

Sweet. Could you let me know what should be improved in the commit message?

@pdietl pdietl force-pushed the pdietl/reset_sercom_periph_during_init branch 2 times, most recently from 6aa7608 to c95b27e Compare June 1, 2025 21:18
@pdietl
Copy link
Contributor Author

pdietl commented Jun 2, 2025

@nandojve I rebased, split the changes into two commits, added conditional compilation for the CTRLC register, and reworded the commit messages. Please let me know if you find this satisfactory or if you desire additional changes :)

pdietl added 2 commits June 6, 2025 18:10
The sam0 SPI driver does not ensure that it clears the 32-bit extension
option during init. The 32-bit extension option, which comprises of a field
in the CTRLC register and the LENGTH register enables better bus
utilization by allowing 32-bit writes to the SPI DATA register
(as opposed to the usual 8-bit writes). The driver breaks down if this
option is enabled by causing each intended byte of output to become
four bytes. We fix this by explicitly disabling the 32-bit extension
option in init.

Signed-off-by: Pete Dietl <[email protected]>
Reset the SPI peripheral to its default state
and register values on init by setting its SWRST bit.
This is important since the driver assumes that certain
registers are at their default values.

Signed-off-by: Pete Dietl <[email protected]>
@pdietl pdietl force-pushed the pdietl/reset_sercom_periph_during_init branch from c95b27e to 1720bcb Compare June 7, 2025 01:13
Copy link

sonarqubecloud bot commented Jun 7, 2025

@pdietl
Copy link
Contributor Author

pdietl commented Jun 9, 2025

@pdgendt I think you need to resolve some requested changes.

@pdgendt
Copy link
Collaborator

pdgendt commented Jun 9, 2025

@pdgendt I think you need to resolve some requested changes.

How so? All mine are resolved, also note that unresolved comments do not block PRs.

@pdietl
Copy link
Contributor Author

pdietl commented Jun 11, 2025

@pdgendt ah ok. I just see this
image

I guess we need someone with write access to approve?

@kartben kartben merged commit c9e48c8 into zephyrproject-rtos:main Jun 11, 2025
26 checks passed
@pdietl
Copy link
Contributor Author

pdietl commented Jun 11, 2025

@pdgendt Thanks again for your time with this review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: SPI SPI bus platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants