0
\$\begingroup\$

I have a question about protocols used over UART. Trying to either create or use an already defined protocol that will allow for transferring a large amount of data as quick as possible over UART. I would like to use the DMAC as much as possible on the receiving end which will be some type of MCU. With that said I'd like to be able to interpret commands as well (which may be in conflict with using the DMAC).

A few thinkgs I seem to get stuck on are:

  1. What happens if the transmission is terminated early form the transmitting end?
  2. Am I wasting my time trying to use the DMAC?

I'm sure there's information I've left out of this question or something I need to do to narrow it down, so I will try to do that with future edits. For now the main question is (although a bit more generic than I want), is there already accepted practices to sending big chunks of data over UART/RS232?

\$\endgroup\$
3
  • \$\begingroup\$ I remember programming a simple protocol in a similar situation, with messages like [marker]+[data_lenght]+[data]+[crc]. I'm interested to see a better solution though. \$\endgroup\$ Mar 17, 2016 at 16:37
  • \$\begingroup\$ Hey @DmitryGrigoryev, thought I'd let you in on what I did and clarify a bit (in this short space). I needed a protocol that required as little MCU overhead as possible so I could transfer as fast as possible (current max link speed is 870K baud, but that is more because of my output). I didn't need any CRC or security, though. I'll post what I did in the next comment. \$\endgroup\$
    – Hexum064
    Mar 29, 2016 at 15:47
  • \$\begingroup\$ My config is basically, an ISR for the UART Rx. It receives a command which lets the MCU know to expect a few data bytes (length based on the command, a one-byte value), or a command that sets up the MCU for accepting streaming data, with no length min or max. During data and streaming, a short timer is turned on which acts as a watchdog for incoming data and resets the connection back to command mode if it times out. For streaming, the UART Rx ISR is disabled until a timeout is reached. I also did a single-shot streaming mode which is length based. \$\endgroup\$
    – Hexum064
    Mar 29, 2016 at 15:51

1 Answer 1

2
\$\begingroup\$

I assume DMAC means DMA controller? I hope you dont assume DMA is free, sometimes it costs less than not using it sometimes it costs more. Know your system.

RS232 is a voltage level thing not a protocol, defines what a 1 and a 0 is not what the stream of them means.

There are many solutions you can do a ppp or slip thing, or just do your own. You can do xmodem, y or z or kermit, etc. Depends on if you want data going both ways.

As Dmitry commented, a typical approach is marker, length, payload and some sort of mathematical check on the packet. And there are many ways to do the sync pattern and the math. ppp uses a specific character but if that character shows up elsewhere in the packet then they do this two character thing, just makes for more processing.

So if bidirectional, then use some sort of sync pattern, length, payload, crc scheme which you can invent. The DMA controller can be used if desired as you could prep the data in ram first then just shoot it over.

If just point to point no need to overcomplicate with ppp/slip or something like that.

You can get rid of length if you want to make everything the same length. You can arguably get rid of the sync pattern too, but the crc or checksum or other is important IMO. The sync pattern even if a single byte makes re-syncing much faster, less processing.

The combination of header, length, payload, and checksum allows for you to cover short or modified packets, not perfect of course, no system is, but it covers the common problems of corrupt data and if you need to stop short mid packet. Whether or not you can detect a fractional packet and re-sync on the next packet (wanted AAAABBBBCCCC got AABBBBCCCC did I resync on BBBB or have to go out of sync and lose BBBB and resync on CCCC) depends on the software design.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks for the great response. Just to clarify, I am referring to the DMA controller when I say DMAC. Anyways, I was talking to some people in chat and one of the things Asmyldof helped me realize was that a timeout on a packet was somewhat common, which is where I thought I was going to far and missing something simpler. But you named off a few protocols which is what I was looking for since i wanted to review what others had done. Just wasn't searching with the right terms I guess. Thanks again! \$\endgroup\$
    – Hexum064
    Mar 18, 2016 at 15:22
  • \$\begingroup\$ There is a difference between securing stuff from hackers and just dealing with corruption or data loss on a connection. The simple header, length, payload, checksum, will help with data loss and corruption, certainly it is not perfect, garbage data may get lucky, but as far as syncing up with the data mid stream or if you get lost, you have a chance, where assuming perfection and no lost data and counting bytes from the beginning of time, that only works until there is corruption or data loss, then you can never re-sync... \$\endgroup\$
    – old_timer
    Mar 18, 2016 at 23:27
  • \$\begingroup\$ If you look at low level ethernet for example there is a sync pattern and a checksum and I think a gap to separate one packet from another (so you dont need a length at that point, and the layers of payloads inside the mac layer packet contains that stuff anyway). Any kind of serial link has some scheme, just look around. \$\endgroup\$
    – old_timer
    Mar 18, 2016 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.