Go Down

Topic: DMA UART (Serial)? (Read 1 time) previous topic - next topic

williamkalfelz

Has anyone created a simple lib to use the DMA on UART (Serial) Output?

Thanks

williamkalfelz

Found this so far:

https://github.com/rblilja/DmaSerial

https://github.com/adafruit/Adafruit_ZeroDMA

williamkalfelz

Ok, I'm having actual fun with this, as I read the PDF of the SAM IC :-)

http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf

Under the DMA section you can find all details, just replace PERIPH with UART

void ConfigureUart( void )
{
  PIOA->PIO_IDR = PIO_PA8A_URXD | PIO_PA9A_UTXD;
  PIOA->PIO_PDR = PIO_PA8A_URXD | PIO_PA9A_UTXD;
  PIOA->PIO_ABSR &= ~(PIO_PA8A_URXD | PIO_PA9A_UTXD);
  PIOA->PIO_PUER = PIO_PA8A_URXD | PIO_PA9A_UTXD;
  PMC->PMC_PCER0 = 1 << ID_UART;
  UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS |UART_CR_TXDIS;

  // Set the baudrate to 115200
  UART->UART_BRGR = 45 ; // 84000000 / 16 * x = BaudRate (write x into UART_BRGR)

  // No Parity
  UART->UART_MR = UART_MR_PAR_NO;
  //UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
  UART->UART_IDR = 0xFFFFFFFF ;

  NVIC_EnableIRQ((IRQn_Type)ID_UART);
  UART->UART_IER =  UART_IER_ENDTX; //<--makierte Zeile

  UART->UART_CR |=  UART_CR_TXEN;

}

void UartSend(uint8_t* value,uint16_t size)
{
  UART->UART_TPR = (uint32_t)value;
  UART->UART_TCR = (uint32_t)size;

  UART->UART_PTCR |= UART_PTCR_TXTEN;
}

dberezin

Did you have any success using rblilja's DmaSerial library?

I couldn't make it work commenting the lines it said to comment and everything, but I don't have much experience using 3rd party libraries.


I'm trying to use it as I had a code writing to DAC and reading from ADC at a reasonable speed but if I try to send the data (both the written and read) through serial using Serial.println() it slows down a lot the code. Is DMA the solution to this? And if so, how do you send and read data? I don't get why your UartSend function needs two arguments.

Go Up