Skip to main content
Explorer
October 10, 2024
Question

UART Rx Interrupt Routine for Variable-Length Data on STM32F072RBT6

  • October 10, 2024
  • 3 replies
  • 1270 views

 

 

 

    This topic has been closed for replies.

    3 replies

    Super User
    October 10, 2024

    Set the receive size to 1 - receive 1 byte at a time.

    Doing it with HAL_UART_Receive_IT is quite an overhead, but it can work - depends on how fast you want/need it to be...

    Explorer
    October 10, 2024

    @Andrew Neil  Thank you for the suggestion to receive 1 byte at a time using HAL_UART_Receive_IT. I understand that this approach can add overhead, but it might work for my use case. However, I’m still unclear about how to determine the end of the file.

    Since I will be receiving the file byte-by-byte, how can I know when I have received the complete binary file so I can proceed with writing the data to flash and jumping to the application?

    Super User
    October 10, 2024

    @shyamparmar wrote:

    I’m still unclear about how to determine the end of the file.


    well, that's an entirely different question - nothing to do with the UART handling of the bytes!

    As @Tesla DeLorean suggested, you will need some sort of protocol to handle that - X/Y/Z-modem are specifically designed for this very application, and are widely supported by terminal software.

    https://web.cecs.pdx.edu/~rootd/catdoc/guide/TheGuide_226.html

    https://en.wikipedia.org/wiki/XMODEM

    https://en.wikipedia.org/wiki/YMODEM

    https://cambium.inria.fr/~doligez/zmodem/ymodem.txt 

    ST Use Y-modem in their IAP Application Note - AN4657STM32 in-application programming (IAP) using the USART:

    https://www.st.com/resource/en/application_note/an4657-stm32-inapplication-programming-iap-using-the-usart-stmicroelectronics.pdf

     

    Graduate II
    October 10, 2024

    You'll need to manage as bytes or blocks, or create circular/ring buffers where you consume the data elsewhere. 

    For files, where size is imparted, look at Y-MODEM 

    Explorer II
    October 11, 2024

    I just wrote this program a few days ago. You should use DMA to receive data.Regularly query data and receive data for splicing。And my bin file transfer added crc check