Hi team.
A number of my projects leverage the convenience of the USB serial component where supported by the micro.
I'm now developing a few projects requiring that a large amount of data (e.g. 10-50kB) is copied to PuTTY terminal, received by the uC, and stored to EEPROM. However, flow control doesn't expressly feature in the USB Serial component, and EEPROM write cycles are relatively slow, so I've used proprietary FTDI devices with 4-wire interface to the PIC for embedded flow control to avoid concerns regarding buffer overflows and missed data.
Not immediately aware of what's going in with USB Serial low-level comms, would it be appropriate to request flow control for the USB Serial component to avoid additional hardware as the workaround?
Many thanks,
Brendan
USB Serial Flow Control
Moderator: Benj
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: USB Serial Flow Control
I used a similar approach for my lightboard display project a while ago... I needed to write 'graphic' files to an i2c eeprom attached to an Arduino.
I used a very simple Python script - which copied a given file across to the Arduino - after each block it waited for a response from the Arduino - before sending the next. (Alternatively you could just wait before sending again)
I also wrote a new i2c eeprom component - the FC standard one is very slow (there is a pause after each byte written - whereas the eeprom I was using could handle blocks of data being written - this meant that I could also buffer a large number of bytes and then just write using a single 'write' command.. If you are using an i2c eeprom - I'd recommend this too...
I've had to migrate to a new computer - but I'll see if I can find the code to send the file.....
Martin
I used a very simple Python script - which copied a given file across to the Arduino - after each block it waited for a response from the Arduino - before sending the next. (Alternatively you could just wait before sending again)
I also wrote a new i2c eeprom component - the FC standard one is very slow (there is a pause after each byte written - whereas the eeprom I was using could handle blocks of data being written - this meant that I could also buffer a large number of bytes and then just write using a single 'write' command.. If you are using an i2c eeprom - I'd recommend this too...
I've had to migrate to a new computer - but I'll see if I can find the code to send the file.....
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: USB Serial Flow Control
Hello,
It's been a while since I last looked at these but I'll see if adding flow control as an option would be an easy addition to the code. It might be very simple and then again it might not
It's been a while since I last looked at these but I'll see if adding flow control as an option would be an easy addition to the code. It might be very simple and then again it might not
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: USB Serial Flow Control
If it helps - and yes flow control would be better..
I used something like:
This sends data to the MCU in 128 byte blocks - shown here with a delay for waiting for eeprom write...
The Arduino code is simple (circular buffer - with interrupt to read UART data) - depends which MCU you are using here?
Slight bug in circular buffer - defined size as 128 bytes but only holds 127 bytes - so get size returns a max of 127...
Martin
I used something like:
Code: Select all
#usage python serial_port file
#python serial_test com4 fred.dat
import serial
import time
import sys
com_port = sys.argv[1] # Serial port eg com4 or /dev/tty0 (Linux) etc
fname = sys.argv[2] # filename to transfer
f = open(fname ,"rb")
ser = serial.Serial(com_port, 9600, timeout = 1) # Change baud if appropriate
time.sleep(5) # Opening com port resets arduino - pause to allow reboot
write_pos = 0
while(f):
data = bytearray(f.read(128))
if not data: break
ser.write(data)
time.sleep(5) # Wait while eeprom write finishes... Set time as needed
f.close() # close the file
ser.close() # close the serial port
print("Success")
The Arduino code is simple (circular buffer - with interrupt to read UART data) - depends which MCU you are using here?
Slight bug in circular buffer - defined size as 128 bytes but only holds 127 bytes - so get size returns a max of 127...
Martin
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: USB Serial Flow Control
I found this in the PIC library so it certainly looks possible. For this family anyway.
I'll try and have a good run at it ASAP and let you know.
Code: Select all
#if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL)
mInitRTSPin();
mInitCTSPin();
#endif
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 243
- Joined: Tue Nov 27, 2012 12:53 pm
- Location: Cambridge, UK
- Has thanked: 140 times
- Been thanked: 118 times
- Contact:
Re: USB Serial Flow Control
Thank you so much guys !!!
The approach uses PuTTY or terminal variants to facilitate easier off-site updates with generic terminal tools (etc), allowing changes to the system-stored test sequence updated from text file via Vcom.
Exemplary professional support as always, and can't thank you enough!
ADDENDUM: I confirm that I am using the PIC.
Stay safe and well everyone.
Sincere best wishes,
Brendan
The approach uses PuTTY or terminal variants to facilitate easier off-site updates with generic terminal tools (etc), allowing changes to the system-stored test sequence updated from text file via Vcom.
Exemplary professional support as always, and can't thank you enough!
ADDENDUM: I confirm that I am using the PIC.
Stay safe and well everyone.
Sincere best wishes,
Brendan
LinkedIn Profile...
http://www.linkedin.com/in/brendantownsend
http://www.linkedin.com/in/brendantownsend