Hi Mark. Am I correct that you have this: host <----wifi----> T4(1) <----UART----> T4(2) ?
Yes, you're picture is my thousand words.
Are you sending the actual hex file produced by the IDE from the host to T4(1)? How are you sending it? I don't understand why there is an issue related to LF versus CR/LF. The hex file has only LF, right?
Yes. I am sending the .hex file generated by the IDE, slightly modified to have the file size and CRC32 value at the beginning of the file. I'm using linux, so I don't entirely understand why the .hex file has CRLF instead of just CR, but I can verify that it does. I'm sending the contents of the file using the netcat command.
Here is a script I use to prepend the size and CRC32 values and then send the file via netcat.
And just to be clear, the current code in FlasherX handles CR vs CRLF just fine. It just ignores any CR or LF that it finds at the beginning of a line until it reaches a non-CR or LF character. My
earlier issue was that the final LF was never read. And this would throw off any CRC32 check I wanted to include. So I had modified the original read_ascii_line to ensure that it read all of the stream contents (including the final LF).
But that is not the issue I was encountering now. I was encountering times when read_ascii_line would return an empty line, and looking at the current code it seems that the only time that could really happen is when the stream->available() returns false each time it was called. That is why I added the check for a timeout threshold, giving the system a chance to wait for more data to arrive before returning a partial or empty line. Between the need to read all CRs and LFs and to wait for a timeout, it was easier to rewrite the method, and I was just offering it back since I like FlasherX and have been using it.
Regarding the issue I had, I don't understand USB well enough to be sure, but the print/flush seemed to be necessary to slow things down. That's probably not entirely correct, and possibly completely wrong, but it works.
I have packaged the FlasherX code (with my changes) with the size and CRC32 check, and my support code to process updates via USB, UART, or TCP into
a FlasherXUpdater library. That way I can reuse more code across my projects. It's not 'pure' in the sense that it has no other dependencies, it is dependent on some of my other libraries I use, but it works for my situation.
I've tested it across USB, UART, and TCP with Teensy 4.0s on my linux system, and it seems to be working very well. I removed the print/flush code for Serial, and at 115200 baud it doesn't seem to drop any bytes. I do have to create a larger read/write buffer though. You can see the
examples that I included. And I also made the timeout threshold configurable because with TCP I still get the occasional bad hex line. But I have read_ascii_line instrumented to print when it encounters a boundary error (max bytes or timeout), so hopefully I can have a better idea of what is going on when it happens next.
Anyways, please feel free to pull out anything you find useful back into FlasherX. Like I said, just trying to give back.
thanks,
-Mark