2022-06-13 09:18 AM
Dear to All,
I have a boar with STM32G030J6 and I want use the TIM3 as PWM output (on PB0->TIM3_CH3) using DMA1 channel 3 to transfer data from RAM memory to TIM3_CCR3 register. The problem is that DMA never trigger the interrupt!
Here the code:
// Setup Pin PB0 in PWM (TIM3_CH3)
RCC->IOPENR = 0x0000002F;
GPIOB->MODER |= 0x00000003;
GPIOB->OSPEEDR |= 0x00000003;
GPIOB->AFR[0] &= ~0x0000000F; // Reset Alternate Function AF1
GPIOB->AFR[0] |= 0x00000001; // Alternate Function AF1
// Setup TIM3 per PWM su pi PB0 con DMA
RCC->APBENR1 |= 0x00000002;
TIM3->CR1 = 0x00000000;
TIM3->CR2 = 0;
TIM3->ARR = 0x0000003D;
TIM3->DIER = 0x00000900;
TIM3->EGR = 0;
TIM3->PSC = 0x00000005;
TIM3->SR = 0;
TIM3->CCR3 = 0x0015;
TIM3->CCMR2 = 0x0060;
TIM3->CCER = 0x00000300;
TIM3->CR1 |= 0x00000001;
//DMA
RCC->AHBENR |= 0x00000003;
DMA1_Channel3->CNDTR = 10;
DMA1_Channel3->CPAR = 0x4000043C;
DMA1_Channel3->CMAR = (uint32_t) &ledValues;
DMA1_Channel3->CCR = 0x00003292;
DMA1_Channel3->CCR |= 0x00000001;
NVIC->ISER[0] = 0x00000400; // int 10
The interrupt on "void DMA1_Channel2_3_IRQHandler(void) " never trigger!
Why? Whats wrong?
Thank you in advance,
Davide
Solved! Go to Solution.
2022-06-14 02:41 PM
DMAMUX channel 0 generates trigger for DMA1_Channel1 (the numbering is mismatched). For DMA1_Channel3 you want to set DMAMUX_C2CR.
Also, keep all fields except DMAREQ_ID in DMAMUX_CxCR zero, unless you know exactly what are you doing.
Also note that DMAMUX clock enable in RCC is identical to DMA clock enable, so you have to set it before you change DMAMUX registers.
JW
2022-06-13 12:46 PM
STM32G0xx contain DMAMUX which determines the triggers routing from peripherals to DMA, you have to set it up.
JW
2022-06-14 01:52 PM
Thank you JW,
I set up the DMAMUX_C0CR register with 0x00080222 value, but nothing new happen!
Davide
2022-06-14 02:41 PM
DMAMUX channel 0 generates trigger for DMA1_Channel1 (the numbering is mismatched). For DMA1_Channel3 you want to set DMAMUX_C2CR.
Also, keep all fields except DMAREQ_ID in DMAMUX_CxCR zero, unless you know exactly what are you doing.
Also note that DMAMUX clock enable in RCC is identical to DMA clock enable, so you have to set it before you change DMAMUX registers.
JW
2022-06-14 09:46 PM
Thank you again JW,
the issue is solved, I set up DMAMUX_C2CR.
Now works fine.
Best regards,
Davide