Author Topic: SAMD10: changing DMA trigger souce in code.  (Read 857 times)

0 Members and 1 Guest are viewing this topic.

Offline RefrigeratorTopic starter

  • Super Contributor
  • ***
  • Posts: 1542
  • Country: lt
SAMD10: changing DMA trigger souce in code.
« on: December 11, 2020, 04:10:54 pm »
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.
Code: [Select]
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:
Code: [Select]
DMAC->CHID.reg = 4;
Then i write to the trigger source register:
Code: [Select]
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:
Code: [Select]
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.

I have a blog at http://brimmingideas.blogspot.com/ . Now less empty than ever before !
An expert of making MOSFETs explode.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: SAMD10: changing DMA trigger souce in code.
« Reply #1 on: December 11, 2020, 05:20:58 pm »
Either
Code: [Select]
DMAC->CHCTRLB.bit.TRIGSRC = TCC0_DMAC_ID_OVF;
or
Code: [Select]
DMAC->CHCTRLB.reg &= ~DMAC_CHCTRLB_TRIGSRC_Msk; // Lookup in the header file how exactly it is called
DMAC->CHCTRLB.reg |= DMAC_CHCTRLB_TRIGSRC(TCC0_DMAC_ID_OVF);
Alex
 
The following users thanked this post: Refrigerator

Offline RefrigeratorTopic starter

  • Super Contributor
  • ***
  • Posts: 1542
  • Country: lt
Re: SAMD10: changing DMA trigger souce in code.
« Reply #2 on: December 12, 2020, 01:48:15 am »
Finally got my project to work, too bad i ran out of time to expand to full functionality.
For now it will work for demo purposes and i have just finished the full code but unfortunately don't have time to test/debug it.
Anyways i'm happy it works at all, i was preparing for the worst case scenario.
I have a blog at http://brimmingideas.blogspot.com/ . Now less empty than ever before !
An expert of making MOSFETs explode.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf