2024-03-18 03:39 AM
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
Solved! Go to Solution.
2024-03-20 05:29 AM
Does ST have any reference documents or examples of TouchGFX with UART (or other protocols)?
2024-03-21 02:45 AM
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
2024-03-21 06:06 PM - edited 2024-03-21 07:30 PM
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).
(main.c)
(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.
2024-03-22 01:46 AM - edited 2024-03-22 01:52 AM
Please use this button to properly post source code - not as an image:
@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:
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 ?
2024-03-24 11:47 PM
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.
2024-03-25 01:45 AM - edited 2024-03-25 01:54 AM
@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:
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
2024-03-25 01:47 AM
@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?
2024-03-25 07:39 PM
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.
2024-03-25 07:47 PM
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! :folded_hands:
Here is my test code for anyone using the STM32U5A9J-DK development board for UART communication, hope it helps!
2024-03-26 03:03 AM
@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.