2024-10-10 02:32 AM - edited 2024-11-15 10:09 PM
2024-10-10 02:35 AM
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...
2024-10-10 02:38 AM
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
2024-10-10 04:37 AM
@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?
2024-10-10 05:13 AM
@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 - AN4657, STM32 in-application programming (IAP) using the USART:
2024-10-10 05:58 AM
>>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.
2024-10-11 12:11 AM
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
2024-10-11 01:00 AM
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