cancel
Showing results for 
Search instead for 
Did you mean: 

uart + xmodem1k. Get incorrect char in the beginning of data

carlogulliani
Associate III
Posted on December 07, 2015 at 18:07

The original post was too long to process during our migration. Please click on the attachment to read the original post.
12 REPLIES 12
Posted on December 09, 2015 at 01:06

It's not an endian issue, both are little endian.

Normally the way you handle this is to take the bytes stream and manage them with a state machine. One that initially concentrates on waiting for the start character, and then the record number, and its complement, and then receiving the data. Doing the CRC as each byte arrives will reduce the latency in responding with an ACK if they match at the end.

You can't treat this as a homogeneous lump of 1029 characters, succeed or fail. May be you can search for classic C implementations of the algorithm. Perhaps look at ST's IAP examples.

After you get the CRC pass or fail, you should wait for the start character again

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
carlogulliani
Associate III
Posted on December 09, 2015 at 16:03

Thanks for your reply, I fixed my code and everything works fine. Could you tell me, maybe you know any other protocols which I can use to transfer file? Or how can I increase the speed of transferring? I know I can increase baud of my uart (now I use 9600), so what else I can do to make it faster? For example 256 Kb was sending almost 16 minutes

And great thanks again, you really helped me to solve the issue which took too many days 

Posted on December 09, 2015 at 17:20

The baud rate is the primary driver of speed here. X-MODEM-1K is easily viable at 460800 and 921600 baud and it's intrinsically self pacing, ie doesn't need any addition HW/SW flow control. Most USB and RS232 level drivers can function to just below 1Mbps.

The latency in responding with ACK/NAK can be reduced by doing the CRC for each byte as it arrives. Other algorithms basically slip-stream the data and keep pushing data, and then resending failing packets. You could look at Z-Modem, and it's windowing technique, but it's rather complex and large. The beauty of X-MODEM is that it is effective and compact, and can be implemented in a few KB of ROM, which is why it's so prevalent in SoC boot loaders. These have very small loaders, typically enough to initialize RAM, SDRAM, etc, and allow you to download a more powerful loader, switch up speeds, and download larger firmware images.

If you have a solid connection your could send larger blocks, but the counter-play there is you'll waste more time if there are a lot of errors. At this point you're off in more custom protocols.

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