2025-03-29 7:37 PM - edited 2025-03-29 7:45 PM
I'm on STM32F103CBT6.
I have a TI DAC8564 on SPI2. It has a 24-bit input register, requiring me to TX a pair of 16-bit values (extra 8 low bits are ignored) while SYNC is low. After sending, I have to toggle SYNC high and then low to begin a new write cycle.
I want to perform this write sequence (TX 16-bit value, TX 16-bit value, SYNC high, SYNC low) using DMA, ideally all synchronized by a single timer (currently TIM2). The timer will run at 160kHz and send a DAC buffer consisting of 64 samples of 40kHz audio for each of 4 channels, each sample being a 16-bit pair.
I've had success using DMA to send the SYNC high/low to GPIO at defined phases of the timer cycle. I'm now looking at using DMA to write the pair of 16-bit values at two other phases of TIM2. RM0008 lists TIM2_CH2 and TIM2_CH4 as available requests for DMA1_Channel7. Can a single DMA channel receive requests from two different channels of the same timer, or are these mutually exclusive?
I found this line from the docs a little hard to interpret:
The 7 requests from the peripherals (TIMx[1,2,3,4], ADC1, SPI1, SPI/I2S2, I2Cx[1,2] and
USARTx[1,2,3]) are simply logically ORed before entering the DMA1, this means that only
one request must be enabled at a time.
I also see this in the libs:
/**
* @brief Enables or disables the TIMx�s DMA Requests.
* TIMx: where x can be 1 to 8 to select the TIM peripheral.
* TIM_DMASource: specifies the DMA Request sources.
* This parameter can be any combination of the following values:
* @arg TIM_DMA_Update: TIM update Interrupt source
* @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
* @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
* @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
* @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
* @arg TIM_DMA_COM: TIM Commutation DMA source
* @arg TIM_DMA_Trigger: TIM Trigger DMA source
* NewState: new state of the DMA Request sources.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void TIM_DMACmd(TIM_TypeDef* TIMx, uint16_t TIM_DMASource, FunctionalState NewState)
But I'm unsure whether "any combination" is just to allow the timer's channels to request multiple DMA channels, not for the timer's channels to independently request the same DMA channel.
Thanks!