Page 1 of 1

UART1 with DMA

Posted: Fri Nov 20, 2015 4:45 pm
by Veronica86
Hi,
I'm using UART1 and DMA with uart.c and uart.h ChibiOS libraries.
I have a problem: the function rxend is executed only at the first reception of a frame. :(
I tried to enable the circular dma mode for rx but it didn't work.
Why? Could someone help me?

In attached there is an abstract of my code.

Thanks for the help,

Veronica

static const uint8_t message[] = "0123456789ABCD\r\n";
static uint8_t buffer[1], appoggio[5];

/*
* This callback is invoked when a receive buffer has been completely written.
*/
static void rxend(UARTDriver *uartp)
{
(void)uartp;

static unsigned char i = 0;

/* When the buffer is full, flush it and restart listening */
appoggio[i]= buffer[0];
i++;
if (i >= 5)
i=0;

uartStopReceive(&UARTD1);
uartStartReceive(&UARTD1, 1, buffer);
}

/*
* UART driver configuration structure.
*/
static UARTConfig uartcfg = {
txend1, /* End of transmission callback */
txend2, /* Physical end of transmission callback */
rxend, /* Receive buffer filled callback */
rxchar, /*UART1RXInterrupt,rxchar, Character received while out */
rxerr, /* Receive error callback */
19200,
USART_CR1_8BIT_WORD | USART_CR1_UE | USART_CR1_TE | USART_CR1_RE, //8bit and no parity check, TX e RX enable
0,
0
};

int main(void)
{
halInit();
chSysInit();

/*Init UART1*/
uartStart(&UARTD1, &uartcfg);

uartStopReceive(&UARTD1);
uartStopSend(&UARTD1);

uartStartSend(&UARTD1, 16, message);
uartStartReceive(&UARTD1, 1, buffer);

chThdSleepMilliseconds(1000);

while (TRUE)
{
//PortC = palReadPort(GPIOC);
SwitchState = palReadPad(GPIOC, GPIOC_SWITCH);
}
}

Re: UART1 with DMA

Posted: Sat Nov 21, 2015 7:57 am
by Giovanni
Hi,

I can see the following errors:
1) You call non I-class functions from the callback. You need to use the "I" version enclosed in chSysLockFromISR/chSysUnlockFromISR.
2) You do not need call uartStopReceive() from the callback, the receive operation is already finished.
3) In the main() you have a loop without a sleep inside, this will prevent the execution of threads at priority less than NORMALPRIO.

In general you need to enable the RT debug options as described here:

http://www.chibios.org/dokuwiki/doku.ph ... ebug_guide

Giovanni