STM32F777: DMA race condition between TIM8 CH1 and TIM8_UP triggering SPI
Hello community,
I am currently working on an STM32F777 project where I encounter a race condition between two DMA-triggered SPI transfers originating from the same timer (TIM8).
Setup:
-
MCU: STM32F777
-
Mechanism 1 (Input Capture): TIM8 CH1 is configured for Input Capture. Upon an active edge, a DMA request transfers a 14-bit data packet to
SPI->DR. -
Mechanism 2 (Periodic Update): TIM8_UP (Update Event) triggers a chained DMA transfer that writes 2 consecutive packets to
SPI->DR.
The Problem:
When both events (TIM8 CH1 Input Capture and TIM8_UP) trigger simultaneously, a collision occurs on the SPI bus:
-
Only 2 packets appear on the SPI MOSI line instead of the expected sequence.
-
The transmitted sequence consists of the packet from the CH1 Capture event followed directly by the second packet of the TIM8_UP chained DMA transfer.
-
The first packet of the TIM8_UP DMA transfer is lost/overwritten.
-
Following this race condition, the entire transfer mechanism halts, and no further packets are transmitted.
Question / Expected Hardware Behavior:
Is there a hardware-level way (e.g., via DMA stream priority, timer gating, request masking, or trigger configuration) to give TIM8_UP strict priority over TIM8 CH1, so that a periodic TIM8_UP event completely overrides/suppresses the CH1 capture transfer if both occur at the same time?
Handling this in software via an ISR is too slow for my timing constraints, so I require a pure hardware or register-level solution.
Update:
I managed to catch the error in the IRQ. After restarting the timer, the packets are triggering on the periodic TIM event again. However, the two packets are now swapped – the first one is sent last, and the last one comes first.
Does anyone know why this might be happening and how I can fix it?
Thanks in advance for your insights!
