Awesome, got serial I/O working nicely. With the particular FTDI chip I'm using, I've got RTS and CTS flow control pins; I just ignored them so far, but turns out I was lucky.. output (TX from mcu, to input on PC) has been working great for debug logging. Absolutely essential .. I'll be adding ftdi's to every pcb from now on
But trying to read from the PC, didn' get anywhere with first 10 minutes blush, so I left it. (I added a basic 'echo mode' to my test code, so anything comes in, it'd send back.) Hit the scope on the pin, just to make sure something is coming in from PC.. nothing. *mrf* Check /dev/ttyUSB0 permissions and such, all looks good on the PC side.
Look up how flow control works .. okay, so if CTS is not set right, the sender may be waiting for CTS (clear to send); likewise is RTS (ready to send). Tie CTS to ground (logic 0) and it means 'we're clear, send away', and poof, PC is sending no problem now; I expect I'm suppose to handle CTS and toggle it as needed but screw it for now .. tied to ground, and Echo Mode works fine.
I've not yet thought about how I'd like to receive data from the PC; assuming (say) a 9600 baud connection, is my mcu running fast enough to burn and pull from serial? Well, the bigger question is .. I'm rather figuring to receive a page at a time (say 256b or something), and then burn, and repeat as needed. I could use CTS/RTS flow control to notify the PC-side 'wait up', or maybe we can pull the full 256 in real time, then burn it. I'm rather expecting the protocol I write to be 'heres a page of 256', then say 'burn last page to address X', and wait for OK from the burner, and repeat as needed; so at a page level, flow control is done in the protocol. So for CTS/RTS its just a quesiton of what we can receive without errors.
I guess the protocol should really have to be ..
(from PC perspective, since the python or whatever code will be the driver's seat)
Connect to /dev/ttyUSB0
Send 'You there?' and wait for some OK ACK
(on error, notify user and bail out of course; assume that always.)
Send 'Receive data name 1, size 256'
Wait for OK Data Receive ACK sort of thing
Transmit the block
Wait for OK Block Received, CRC32 checksum is <big number> ACK
Compare received checksum to locally calculated checksum
If checksum good, send 'Burn data named 1, to address A'
Wait for OK
.... repeat as needed
Send Done and hang up
This should be pretty safe more or less, and allow for re-burning same page data without transmitting or something. Features I'll never use
Given this, it should be easy to run say 1000 burn operations and see if I get any errors or not; if so, maybe need to implement CTS/RTS. Probably should.
On the mcu side, I may just busy loop to receive data, or maybe I shoudl turn on an interupt and do it that way; either way, CTS could be easy..
Wait on char present in UART (theres a bit on the UART to check this fact; or an interupt.)
When char received, drop CTS (rather, raise it high, since high is block)
Pull character
Reset CTS low (clear for more)
That is a pretty dumb strategy, but shoudl work well enough.
I'll worry about it tomorrow.. time to watch Agents of Shield!
jeff