How to trigger a dma transfer with a timer.

octavio
Wed May 31, 2017 12:06 pm
Actually i have this code that does not compile because “timer->dev” is private, what is the correct way to do it?
timer_dma_enable_trg_req(timer->dev);

stevestrong
Wed May 31, 2017 2:03 pm
“timer->dev” should be TIMERx which you declared to be the “timer”.

octavio
Wed May 31, 2017 3:10 pm
Well,it compiles ,but do not works ,what do i missed?

#include <libmaple/dma.h>
#define dma_bufer_size 48
long dma_bufer[dma_bufer_size];
//dmx driver
//d- PA2
//d+ PA3

#define dmx0 0x80004;
#define dmx1 0x40008;
HardwareTimer timer(2);

dma_tube_config tube_config;

void setup() {
//fill dma bufer
int fps=0;
do{
dma_bufer[fps++]=dmx0;
dma_bufer[fps++]=dmx1;
}while(fps<dma_bufer_size);

pinMode(PA2,OUTPUT);
pinMode(PA3,OUTPUT);
//DMA setup
tube_config.tube_src = dma_bufer;
tube_config.tube_src_size = DMA_SIZE_32BITS;
tube_config.tube_dst = &GPIOA->regs->BSRR; // Load pointer to porta clear/set
tube_config.tube_dst_size = DMA_SIZE_32BITS;
tube_config.tube_nr_xfers = dma_bufer_size;
tube_config.tube_flags = DMA_CFG_SRC_INC | DMA_CFG_CIRC; // Source pointer increment,circular mode
tube_config.target_data = 0;
dma_init(DMA1);
tube_config.tube_req_src = DMA_REQ_SRC_TIM2_CH3; // DMA request source.
dma_set_priority(DMA1, DMA_CH1,DMA_PRIORITY_VERY_HIGH);
dma_tube_cfg(DMA1, DMA_CH1, &tube_config); // Attach the tube to channel 1 (timer2 ch3)
dma_enable(DMA1, DMA_CH1);

//TIMER setup
timer.pause();
timer.setPeriod(2000000);//2 seconds
timer.setChannel3Mode(TIMER_OUTPUT_COMPARE);
timer.setCompare(TIMER_CH3, 1);
timer_dma_enable_trg_req(TIMER2);
timer.resume();

}

void loop() {
while(1){

//commented code is what dma is supposed to do.(blink a led connected to PA2-PA3)
/*
GPIOA->regs->BSRR=dmx0;
delay(2000);
GPIOA->regs->BSRR=dmx1;
delay(2000);*/
};

}


Rick Kimball
Wed May 31, 2017 3:43 pm
Where does the dma_tube_config come from? This doesn’t compile for me.

octavio
Wed May 31, 2017 3:47 pm
I’m using arduino 1.8.2 and libraries for stm32f1 (from Roger Clark repository i think.)
https://github.com/rogerclarkmelbourne/ … nfig&type=

Rick Kimball
Wed May 31, 2017 3:50 pm
I’m using the latest stuff from github. Searching there I see no where it is defined.

https://github.com/rogerclarkmelbourne/ … nfig&type=

Just comments


octavio
Wed May 31, 2017 3:53 pm
defined in line 137
https://github.com/rogerclarkmelbourne/ … aple/dma.h

Rick Kimball
Wed May 31, 2017 3:54 pm
https://github.com/rogerclarkmelbourne/ … ries/dma.h … it is here ..
However, it is not finding SdFat.h or this file for me.

octavio
Wed May 31, 2017 3:59 pm
It works with this too:
#include <libmaple/dma.h>

stevestrong
Wed May 31, 2017 5:11 pm
Try:

tube source = &dma_buffer; // note the “&”

tube dest = &GPIOA->regs->ODR; // only the lowest 16 bits are used, so you could use 16 bit transfer, increasing the number of samples to store in buffer

I am not sure that you selected the correct source for DMA trigger. Shouldn’t be the CC output of TIM2 CH3?

Extract from RM0008:
"In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an UEV update event but without setting the UIF flag (thus no interrupt or
DMA request is sent)."


octavio
Wed May 31, 2017 9:46 pm
Now ,for debug,i did a mem to mem dma transfer,transfer is done inmediately ignoring the timer trigger (timer is not enabled).

octavio
Thu Jun 01, 2017 4:10 pm
Problem solved,i changed “timer_dma_enable_trg_req(TIMER2);” by “TIMER2_BASE->DIER=TIMER_DIER_CC3DE;” and it works now.

Leave a Reply

Your email address will not be published. Required fields are marked *