Hello all!
I've got a problem trying to program DMA transfer from memory to the USART. When I put DMA in circular mode (DMA_CIRC_MODE) everything works fine, but when I clear this bit and set the DMA_TRNS_CMPLT, it seems that Maple hangs up at first interrupt (I see on the oscilloscope that the 1st transfer is going, and the board LED, that must blink every 0,5s, just turns on). I even tried to remove from the interrupt handler all the operations with DMA controller, it didn't help. What I'm doing wrong? Here's the code:
#include "dma.h"
uint8 buf[512];
int dma_cmplt = 1;
void intDMA(void)
{
dma_cmplt = 1;
}
void setup()
{
pinMode(BOARD_LED_PIN, OUTPUT);
Serial3.begin(9600);
dma_init(DMA1);
dma_setup_transfer(DMA1,
DMA_CH2,
&USART3_BASE->DR,
DMA_SIZE_8BITS,
buf,
DMA_SIZE_8BITS,
(DMA_MINC_MODE | DMA_FROM_MEM | DMA_TRNS_CMPLT));
dma_attach_interrupt(DMA1, DMA_CH2, intDMA);
USART3_BASE->CR3 |= USART_CR3_DMAT;
}
void loop()
{
if (millis() % 500 == 0)
{
digitalWrite(BOARD_LED_PIN, (millis()/500) % 2);
}
if (dma_cmplt)
{
dma_disable(DMA1, DMA_CH2);
dma_set_mem_addr(DMA1, DMA_CH2, buf);
dma_set_num_transfers(DMA1, DMA_CH2, 512);
dma_enable(DMA1, DMA_CH2);
dma_cmplt = 0;
}
}