cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5xxx UART communication problems

jessie_chiu
Associate III

I am using the STM32U5A9J-DK for a UART communication test, and I expect to display the content sent from the computer's Serial port on the screen (textArea).
I'm using UART1, 115200 Baud rate, 8 data bits, 1 stop bits, and I've turned on the UART interrupt, but for some reason the text on the screen doesn't change.
There are not many examples that I can find, so I hope someone can help me to clear this up!

Here is my code

20 REPLIES 20

Does ST have any reference documents or examples of TouchGFX with UART (or other protocols)?

Hello @jessie_chiu , 

I think you are missing some steps when generating you project you need to configure the UART with CUBEMX and then continue the configuration with TouchGFX this is explained in details  in this thread.

Hope this resolves your request .

BR

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello, @STea and @SofLit .Thank you for your reply!


To update the current status of this issue: 
1. For the project using freeRTOS, I've successfully completed sending messages to the MCU in Serial Motior (using Idle Interrupt).
2. when I call HAL_UARTEx_RxEventCallback(), I can use HAL_UART_Transmit() to send back UART data (line 110).

jessie_chiu_0-1711069227511.png  

(main.c)

jessie_chiu_2-1711069327628.png

(main.h)

BUT when I run strncpy and update struct (line 114, 115), I can't receive the response (line 116)
If I only run osMessageQueuePut(), I can receive the RxData content.

It looks like I can't access the struct content.

 

I am confused about this situation.

All my code is referenced from this video.

Please use this button to properly post source code - not as an image:

AndrewNeil_0-1711096974442.png

 


@jessie_chiu wrote:

when I run strncpy and update struct (line 114, 115), I can't receive the response (line 116)


You define a buffer of length Size, but you tell strncpy() to copy a length of Size+1:

AndrewNeil_1-1711097145988.png

Correction:

The buffer length is 257, but you are still copying more data than has actually been received

Also, uartData_q is just a pointer - have you actually created any storage for it to point to ?

 

 

Hi, thanks for the correction, I will avoid using screenshots of the program code in the future.
In lines 114 and 116 of the screenshot is where I have called the uartData_q storage.


@jessie_chiu wrote:

In lines 114 and 116 of the screenshot is where I have called the uartData_q storage.


You don't "call" a data structure?

Actually, line 116 is commented-out - so it does nothing.

In line 114, you dereference the pointer:

AndrewNeil_0-1711356129780.png

That is, you try to access the memory that the pointer is pointing to.

But you haven't shown where that pointer gets set to point to any actual memory.

That was my question.

If the pointer uartData_q hasn't been set to point to any actual memory, then line 114 is, at best, going to be a NULL pointer reference ...

Somewhere, you need to create an actual uartData_t structure, and then you need to set the uartData_q pointer to point to it; eg, 

uartData_t uartData_struct;     // Create the structure

uartData_q = &uartData_struct;  // Set the pointer to point to the structure

 


@jessie_chiu wrote:

Hi, thanks for the correction, I will avoid using screenshots of the program code in the future.


Perhaps you could contribute to this thread:

https://community.st.com/t5/feedback-forum/formatting-code-should-be-easier/td-p/631565

How could the forum have better signposted you to the way to post source code?

Hi, I have the implementation of the uartData_t structure in line 103 of the drawing, with uartData_q pointing to memory.

uartData_t *uartData_q;

As for the problem in line 116, when I access the Data data of uartData_q, the PC will not receive the message.That's why I comment it out.

jessie_chiu
Associate III

Update the status of this issue:
I have now resolved the issue with the UART communication problem, and I will move the rest of the questions to a new thread.

Thanks again to everyone who replied to this thread! 🙏

 

Here is my test code for anyone using the STM32U5A9J-DK development board for UART communication, hope it helps!


@jessie_chiu wrote:

I have now resolved the issue with the UART communication problem,


For the benefit of future readers with similar problems who may find this, please describe what was the actual problem, and how did you solve it.