drivers: fix DMA request disable ordering in timer IRQ handlers and stop functions#11589
Open
sensei-hacker wants to merge 1 commit into
Open
Conversation
…top functions STM32 RM (RM0090 §10.3.17) requires disabling the timer DMA request before disabling the DMA stream. The previous code had this backwards in five places across three driver files, creating a race window where the timer could issue a DMA request to an already-disabled stream. The incorrect ordering: DMA_Cmd(stream, DISABLE); // stream disabled first TIM_DMACmd(tim, source, DISABLE); // timer request disabled second Corrected ordering: TIM_DMACmd(tim, source, DISABLE); // timer request disabled first DMA_Cmd(stream, DISABLE); // stream disabled second Affected locations: - timer_impl_stdperiph.c: impl_timerPWMStopDMA, impl_timerPWMPrepareDMA, DMA TC IRQ handler - timer_impl_stdperiph_at32.c: impl_timerPWMStopDMA - timer_impl_hal.c: DMA TC IRQ handler The correct ordering was already used in impl_timerPWMSetDMACircular (both stdperiph files) and impl_timerPWMStopDMA (HAL file), which serve as the reference implementation.
Contributor
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Test firmware build ready — commit Download firmware for PR #11589 237 targets built. Find your board's
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes incorrect DMA stream disable ordering in
timer_impl_stdperiph.c,timer_impl_stdperiph_at32.c, andtimer_impl_hal.c.STM32 Reference Manual (RM0090 §10.3.17) requires disabling the timer DMA request first, then the DMA stream. Five locations had this backwards, creating a race window where the timer peripheral could issue a DMA request to an already-disabled stream via the hardware DMA request line (which bypasses CPU interrupts and operates even inside an ATOMIC_BLOCK).
Changes
timer_impl_stdperiph.c (3 sites):
impl_timerPWMStopDMA— swapped disable orderimpl_timerPWMPrepareDMA— swapped disable order inside ATOMIC_BLOCKtimer_impl_stdperiph_at32.c (1 site):
impl_timerPWMStopDMA— swappeddma_channel_enable/tmr_dma_request_enableordertimer_impl_hal.c (1 site):
LL_DMA_DisableStream/LL_TIM_DisableDMAReq_CCxorderThe correct ordering was already present in
impl_timerPWMSetDMACircular(both stdperiph files, added in #11260) andimpl_timerPWMStopDMA(HAL file), which serve as the reference implementation.Testing
Code Review
Reviewed for ISR safety, ordering correctness against RM0090 §10.3.17, and consistency with reference implementations.