My MCU has 6 DMA channels but i need 7 so eventually i have to reconfigure one of the DMA channels.
First, all of my DMA channels are configured for UART on all three SERCOM RT/TX triggers but later in the code i need to reconfigure one of the DMA channels to trigger off TCC0 overflow.
So far i've been unsuccessful in doing so. I'm using start.atmel to setup my DMA channels at first, and later reconfigure (or at least try to) the DMA channels by writing to the registers.
void config_dma_channel_4(void)
{
struct _dma_resource *dma_res;
_dma_set_source_address(4, (void *)LED_TX_buf);
_dma_set_destination_address(4, (void *)&(TCC0->CCB[2].reg));
_dma_set_data_amount(4, (uint32_t)450);
_dma_get_channel_resource(&dma_res, 4);
/* Set application callback to handle the DMA CH-4 transfer done */
dma_res->dma_cb.transfer_done = dmac_channel_4_callback;
_dma_set_irq_state(4, DMA_TRANSFER_COMPLETE_CB, true);
// redefine
DMAC->CHID.reg = 4;
DMAC->CHCTRLB.reg |= DMAC_CHCTRLB_TRIGSRC(TCC0_DMAC_ID_OVF);
//DMAC->CHCTRLB.bit.TRIGSRC = 0b111;
} // end of config_dma_channel_4
The above code is just a test i whipped up when i noticed that reconfiguring the DMA wasn't working on my main code. So i made a new, cleaner project to experiment.
DMA is originally set up to trigger on SERCOM TX and the goal is to change it to TCC0 overflow.
I do it in the same DMA initialization function because this code here is only for test purposes.
First i select the channel:
DMAC->CHID.reg = 4;
Then i write to the trigger source register:
DMAC->CHCTRLB.reg |= DMAC_CHCTRLB_TRIGSRC(TCC0_DMAC_ID_OVF);
By OR-ing i mask the bits that were previously there, TCC0 is 0b111 and all SERCOM triggers are less than that so OR-ing should work.
But it doesn't work.
Another option that i have not yet tried is writing to the bit:
DMAC->CHCTRLB.bit.TRIGSRC = 0b111;
Commented out because i used atmel studio to autocomplete for this post.
Also i assume 0b111 can also be replaced with the TCC0_DMAC_ID_OVF macro.
Am i missing something ? Would be great to know because i'm running out of time and this has been driving me up the wall.