cancel
Showing results for 
Search instead for 
Did you mean: 

UART Rx Interrupt Routine for Variable-Length Data on STM32F072RBT6

shyamparmar
Associate III

 

 

 

7 REPLIES 7

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

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 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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


@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

 

>>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?

You'd have to impart the size in header information, or embedded in the image itself.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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?


Well it depends on how much ram you have, but you'll probably want to receive data in chunks and save to flash memory. Then request for another chunk and so on. 

See this pdf to get a general idea

https://www.st.com/resource/en/application_note/an3155-usart-protocol-used-in-the-stm32-bootloader-stmicroelectronics.pdf

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
zhaowhong
Associate III

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