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
difference between UART and Serial driver
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: difference between UART and Serial driver
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
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
Re: difference between UART and Serial driver
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?
Delphi
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
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: difference between UART and Serial driver
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
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
Re: difference between UART and Serial driver
Thanks again, seems I have to take some time to understand the channel concept of chibios.
Delphi
Delphi
Re: difference between UART and Serial driver
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?
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?
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: difference between UART and Serial driver
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
Giovanni
Re: difference between UART and Serial driver
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?
#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?
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: difference between UART and Serial driver
Hi,
Please enable debug options in chconf.h, it is possible something will be detected.
Giovanni
Please enable debug options in chconf.h, it is possible something will be detected.
Giovanni
Who is online
Users browsing this forum: No registered users and 24 guests