UART1 with DMA

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Veronica86
Posts: 1
Joined: Fri Nov 20, 2015 4:19 pm

UART1 with DMA

Post 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);
}
}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART1 with DMA

Post 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
Post Reply