cancel
Showing results for 
Search instead for 
Did you mean: 

Transmit multiple data using UART & FREE RTOS

SMour.2
Associate III

Hi,

Iam using STM32 NUCLEO F401RE BOARD to send multiple data to PC using UART Printf.

I have created different tasks(4 tasks) for different computations and finally one dedicated task to send all the data computed to be sent via UART using Printf.

for example one task is running PWM & ADC, other task is using I2C, third task is using UART1.

The issue is that sending multiple data causes tasks to misbehave and not do the computations properly.

In all I have 8 integer values, 1 floating value. for example, when I try to send all this data using multiple printf commands , The task with ADC gives incorrect ADC sampled values.

When Iam not using printf command the tasks work properly , but I need to send all the data to PC via UART.

To use Printf , Iam using below code

#ifdef __GNUC__

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

#else

#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

#endif /* __GNUC__ */

PUTCHAR_PROTOTYPE

{

HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);

return ch;

}

1 ACCEPTED SOLUTION

Accepted Solutions
Maybe the UART connection is the bottleneck. How much data are you transferring vs the maximum bandwidth available?
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

8 REPLIES 8
TDK
Guru

In what way are the values incorrect? Are you calling printf from a single task only?

If you feel a post has answered your question, please click "Accept as Solution".
hs2
Senior

Do you provide sufficient stack size (especially) to the printf task ? printf family functions are known being stack hungry and you might have stack overflows issues.

SMour.2
Associate III

Hi TDK,

Values are incorrect because the original signal is not reconstructed according to ADC samples when I'am using Printf. I have a peak detection algorithm in my code and without using printf the peaks are detected accurately .But When I use it, The no. of peaks detected are less in the same signal.

Yes Iam calling printf from single task only. One more thing I tried is that When I send only One integer ,Then the values are correct and tasks are performing correctly. If I try sending more than one values, then there is a problem.

I've kept the stack size of the task which is using printf as 4096. I dont know , but this Printf thing is really affecting the tasks.

SMour.2
Associate III

The stack size is 4096

I can offer my own version of printo ("text", double / float / uint (8-16-32-64) _t / int (8-16-32-64) _t)

It weighs 20 less than a standard printf, runs 6 times faster, and does not require a brain.

https://github.com/AVI-crak/Rtos_cortex/blob/master/sPrint.h

However, any printing medium is intended for a person - to look at numbers. And it is not designed for high speed data transfer. For high speed, you need to transfer raw data packed into a fixed-length packet structure. In this case, the parsing of the data is performed by the receiving side.

Maybe the UART connection is the bottleneck. How much data are you transferring vs the maximum bandwidth available?
If you feel a post has answered your question, please click "Accept as Solution".
SMour.2
Associate III

Ok, I solved the issue by going back to the basics, i.e. I break my data into bytes on the transmitting side and then rejoin the bytes on receiving end to get actual data. I used Hal_UART_Transmit_IT to send data bytes. I think sending Bytes is much faster than using Printf as Iam getting real time data by sending Bytes. I am working on a portable pocket size patient monitoring system with all the vital parameters shown along with graph on the display. Currently I used STM32F7 Discovery board , but have my custom PCB ready to get it going. Thanks all for your replies.

image attached

0693W00000AO6ZUQA1.jpg

Thanks for your suggestion. I really chose to transfer data byte wise for real time speed.