Skip to main content
Graduate II
March 18, 2024
Solved

STM32U5xxx UART communication problems

  • March 18, 2024
  • 4 replies
  • 6298 views

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

    This topic has been closed for replies.
    Best answer by jessie_chiu

    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!

    4 replies

    ST Employee
    March 18, 2024

    Hello @jessie_chiu ,

    you are sharing the IOC file and it seems like you are not using the correct pins for UART communication . the UART instance connected to VCP (virtual com port)of STlink is UART1 on pins PA8 and PA9. check you configuration to make sure you are using the correct pins and if you are using printf to display the text make sure you are correctly surcharging it .

    BR

    Graduate II
    March 19, 2024

    Thank you for your reply. I didn't notice the pin problem!!
    But after I fixed the pin define, I still don't get the message.
    Do you have any other suggestions?

     

    jessie_chiu_1-1710810160258.png

     

    ST Employee
    March 19, 2024

    Hello @jessie_chiu ,

    after making sure that you pinout configuration is good you should verify the baudrate and UART related configuration from the PC terminal side is matching .

    if you are using Pritnf to output messages here is what you need to add to you main file 

    1. #include "stdio.h"
    2. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
    3. PUTCHAR_PROTOTYPE
      {
        /* Place your implementation of fputc here */
        /* e.g. write a character to the UART2 and Loop until the end of transmission */
        HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
       
        return ch;
      }
       
    you can get more information about this in this article  .
    you should also make sure that you solder bridge configuration is the correct one for redirecting UART communications via VCP (your stock board if not modified should have the correct configuration of solder bridges ).
     
    if you are still having some issues with outputting messages try adding fflush(0); after printf (redirected) or UART_Trassmit() to flush the internal buffer and make sure that your message is flushed to the VCP.
     
    BR 
     
     
    Super User
    March 18, 2024

    @jessie_chiu wrote:

     for some reason the text on the screen doesn't change.


    So have you checked that any data is being received?

     

    Technical Moderator
    March 18, 2024

    Hello,

    As stated by @STea you're not assigning the correct IOs for UART1 to connect it to VCP:

    SofLit_0-1710777099982.png

    So replace PB6 by PA9 and PB7 by PA10 in CubeMx.

    jessie_chiuAuthorAnswer
    Graduate II
    March 26, 2024

    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!

    Super User
    March 26, 2024

    @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.