Skip to content

feat(PeriphDrivers): Add new MXC_SPI_GetAndClearFlags API#1541

Merged
ttmut merged 1 commit into
analogdevicesinc:mainfrom
petejohanson-adi:mxc-spi-get-and-clear-flags-api
Apr 16, 2026
Merged

feat(PeriphDrivers): Add new MXC_SPI_GetAndClearFlags API#1541
ttmut merged 1 commit into
analogdevicesinc:mainfrom
petejohanson-adi:mxc-spi-get-and-clear-flags-api

Conversation

@petejohanson-adi

Copy link
Copy Markdown
Collaborator

Description

Add new MXC_SPI_GetAndClearFlags to simultaneously retrieve the current interrupt flags, and clear only the returned flags. This avoids accidentally clearing flags that have been set since a call to get the current flags using the existing MXC_SPI_ClearFlags API.

This is needed to fix a race condition discovered in the Zephyr MAX32 SPI driver. In particular, the ISR there is fetching the flags, then clearing the flags (via MXC_SPI_ClearFlags), which can lead to missed flags if a flag is set between the call to get the flags, and clear them: https://github.com/zephyrproject-rtos/zephyr/blob/acc53653b4707aa40c22aec8c33f1d733e5e670f/drivers/spi/spi_max32.c#L1064

Testing here on MAX32666 (where flake was most prevalent due to this race condition) confirms that moving to the new API eliminates all flake.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

@github-actions github-actions Bot added MAX32520 Related to the MAX32520 (ES17) MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX32655 Related to the MAX32655 (ME17) MAX32660 Related to the MAX32660 (ME11) MAX32665 Related to the MAX32665 (ME14) MAX32670 Related to the MAX32670 (ME15) MAX32672 Related to the MAX32672 (ME21) MAX32675 Related to the MAX32675 (ME16) MAX32680 Related to the MAX32680 (ME20) MAX32690 Related to the MAX32690 (ME18) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) MAX32662 Related to the MAX32662 (ME12) MAX32572 Related to the MAX32572 (ME55) MAX32657 Related to the MAX32655 (ME30) labels Apr 15, 2026
@petejohanson-adi petejohanson-adi force-pushed the mxc-spi-get-and-clear-flags-api branch from bd3c4e5 to 50d63a1 Compare April 15, 2026 21:59
Add new MXC_SPI_GetAndClearFlags to simultaneously retrieve the current
interrupt flags, and clear only the returned flags. This avoids
accidentally clearing flags that have been set since a call to get the
current flags using the existing MXC_SPI_ClearFlags API.

Signed-off-by: Pete Johanson <pete.johanson@analog.com>
@petejohanson-adi petejohanson-adi force-pushed the mxc-spi-get-and-clear-flags-api branch from 50d63a1 to 4e21e1a Compare April 15, 2026 22:05
@ttmut ttmut merged commit cf876ac into analogdevicesinc:main Apr 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MAX32520 Related to the MAX32520 (ES17) MAX32570 Related to the MAX32570 (ME13) MAX32572 Related to the MAX32572 (ME55) MAX32650 Related to the MAX32650 (ME10) MAX32655 Related to the MAX32655 (ME17) MAX32657 Related to the MAX32655 (ME30) MAX32660 Related to the MAX32660 (ME11) MAX32662 Related to the MAX32662 (ME12) MAX32665 Related to the MAX32665 (ME14) MAX32670 Related to the MAX32670 (ME15) MAX32672 Related to the MAX32672 (ME21) MAX32675 Related to the MAX32675 (ME16) MAX32680 Related to the MAX32680 (ME20) MAX32690 Related to the MAX32690 (ME18) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants