difference between UART and Serial driver

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
delphi
Posts: 16
Joined: Sat Jul 27, 2013 8:56 am
Location: Hong Kong

difference between UART and Serial driver

Postby delphi » Sat Jul 27, 2013 9:09 am

Hello every body,
I am new to RTOS and just tried to embed a chibios 2.6 in to my STM32F4 Discovery Board. I've done my first experiment to make the LEDs blink in difference speed with difference threads and it's running cool!!
I would like to try to send and receive characters by UART in the same environment but i found something confuse that there are UART driver and Serial driver in the HAL of chibios. Can anyone helps to tell me what is the difference between UART and serial driver?
Thanks a lot.

Delphi

User avatar
Giovanni
Site Admin
Posts: 13086
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 759 times
Been thanked: 638 times
Contact:

Re: difference between UART and Serial driver

Postby Giovanni » Sat Jul 27, 2013 9:18 am

Hi,

The two drivers use the same peripherals but the API is very different. The serial driver is an interrupt-driven driver implementing circular buffers for input and output, the access is through classic read/write/get/put functions.
The UART driver is meant for packet-based data exchange at high speed (it uses the DMA) and is unbuffered.

For most application the serial driver is perfectly adequate and it is much easier to use.

Giovanni

delphi
Posts: 16
Joined: Sat Jul 27, 2013 8:56 am
Location: Hong Kong

Re: difference between UART and Serial driver

Postby delphi » Sat Jul 27, 2013 12:02 pm

Thanks Giovanni, your information is helpful. Just done my UART experiment with sdAsynchronousRead() and sdWrite() from Serial API and it works well. However,I got a concern about the documentation state :This function bypasses the indirect access to the channel and reads directly from the input queue. This is faster but cannot be used to read from different channels implementations.
I have not idea what is the meaning of "different channels". It sounds like sdAsynchronousRead() is a function for advance use only and there are some normal API sets for normal use. Am i right?

The following is the code i used to test the UART2. It just send out the data it got. Can you tell me is it a proper way to use the uart?

Code: Select all

static WORKING_AREA(waTH12,128);

static msg_t thFunc_UART2(void *arg)
{
   uint8_t sbuf2[100];
   uint8_t len;
  SerialConfig sConfig2;
   sConfig2.speed=9600;
   sConfig2.cr1 = 0;
   sConfig2.cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN;
   sConfig2.cr3 = 0;
   
  palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
   
   sdStart(&SD2, &sConfig2);
   
   while(true)
   {
      len=sdAsynchronousRead(&SD2,sbuf2,10);
      if(len>=1)
         sdWrite(&SD2, sbuf2, len);
   }
}



Delphi

User avatar
Giovanni
Site Admin
Posts: 13086
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 759 times
Been thanked: 638 times
Contact:

Re: difference between UART and Serial driver

Postby Giovanni » Sat Jul 27, 2013 12:17 pm

Not exactly.

The serial driver can be used using two sets of functions:

The first set, with names prefixed by "sd" access directly the serial driver and is generally faster.

The second set access the serial driver through an interface called BaseAsynchronousChannel and the methods of this interface are prefixed by "chn", see the module io_channel.h. Several devices implement that interface, so it is possible to write code that can write to different peripherals.

See chprintf() for an example, it can write to a serial driver but also other objects implementing a channel interface.

Giovanni

delphi
Posts: 16
Joined: Sat Jul 27, 2013 8:56 am
Location: Hong Kong

Re: difference between UART and Serial driver

Postby delphi » Sat Jul 27, 2013 12:28 pm

Thanks again, seems I have to take some time to understand the channel concept of chibios.

Delphi

bezmic
Posts: 9
Joined: Fri Feb 28, 2014 9:07 pm

Re: difference between UART and Serial driver

Postby bezmic » Thu Apr 17, 2014 4:19 pm

Hello,
For STM32F407:
I have problem with using two or more UART's drivers at the same time. When i write "uartStart(UARTDriverN, &(UARTConfigN))" once its working. But when i repeat uartStart for second UART, first don't work. What is my problem?

User avatar
Giovanni
Site Admin
Posts: 13086
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 759 times
Been thanked: 638 times
Contact:

Re: difference between UART and Serial driver

Postby Giovanni » Thu Apr 17, 2014 6:38 pm

Probably conflicting DMA channels, in mcuconf.h you can see the current assignment, you can change them but not to any channel, see the reference manual for alternate channels.

Giovanni

bezmic
Posts: 9
Joined: Fri Feb 28, 2014 9:07 pm

Re: difference between UART and Serial driver

Postby bezmic » Thu Apr 17, 2014 7:54 pm

Thanks, i'l see DMA settings.

bezmic
Posts: 9
Joined: Fri Feb 28, 2014 9:07 pm

Re: difference between UART and Serial driver

Postby bezmic » Thu May 01, 2014 11:58 pm

DMA dont't cross:

#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)

What else could be the reason?

User avatar
Giovanni
Site Admin
Posts: 13086
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 759 times
Been thanked: 638 times
Contact:

Re: difference between UART and Serial driver

Postby Giovanni » Fri May 02, 2014 6:27 am

Hi,

Please enable debug options in chconf.h, it is possible something will be detected.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 0 guests