Advice on STM32U5 multiple timer configuration
I'm struggling with how to use the timers to achieve certain behavior and am looking for some advice. First I'll describe the purpose, then how I tried to approach it, and then why I'm stuck.
I need a 32-bit timebase that counts up at exactly 48kHz and always runs, rolling over from 0xffffffff back to 0. This timebase is used to precisely "schedule" the start of DAC and/or ADC conversions at some future counter value. For example, if the current counter value is 12345, I might want to start DAC conversion at counter value 20000. Optionally, I might also want to start ADC conversion at counter value 20100. The DAC and ADC are scheduled independently but may overlap. Once triggered, the DAC/ADC channels should continue running until disabled by software. It's important that the timebase, DAC sampling, and ADC sampling are all synchronized at 48kHz such that they maintain a consistent relative phase offset, even across conversion windows. Since my application would be very sensitive to relative timing jitter, I am trying to do as much as possible via hardware events. In a nutshell, I want to use one always-running timer to precisely time-gate the start of continuous ADC and DAC windows.
My first thought was to configure TIM2.PSC for a 48kHz counter rate and set TIM2.ARR to 0xFFFFFFFF, so TIM2 is the 32-bit timebase. Then I'd use its CH1 and CH2 in output compare mode to trigger the start of two other timers (TIM4 and TIM5) that would clock the DAC and ADC, respectively. For example, TIM2.CCR1 is the future counter value to start the DAC conversion. TIM4 and TIM5 would be configured as slaves to TIM2 and would be triggered to start via TIM2's CH1 and CH2 events. Then to stop the DAC/ADC, software would later disable TIM4/TIM5.
The problem here is that TIM2 only has one trigger output (trgo), so I don't see a way that TIM2 can use OC1 as a trigger to TIM4 while simultaneously using OC2 as a trigger to start TIM5. Or, maybe I'm misunderstanding the signals. For now I'm going to just start it from an ISR, but any thoughts on how to accomplish this would be much appreciated - happy to discuss as raw registers or as CubeMX HAL nomenclature.
