Page 1 of 1

libmaple F401 pill board gives usb-serial speeds almost 1.2Mbps

Posted: Sat May 30, 2020 5:46 pm
by ag123
i did a little timing measurements using usb serial libmaple core, the board is transferring 1280 bytes of data across each time.
i'm getting numbers like 8 ms - 10 ms to transfer that 1280 bytes across.
hence i tried working the numbers : 1280 bytes / 8 ms ~ 160 bytes / ms ~ 160 KBps ~ 1.28 Mbps
while this may be less than the 12 Mbps deemed possible on usb-full speed, it is still well faster than 115200 bps commonly specified for serial comm ports.

Re: libmaple F401 pill board gives usb-serial speeds almost 1.2Mbps

Posted: Wed Jun 03, 2020 1:45 pm
by fpiSTM
How did you measure the time?
And how did you transferring the 1280 bytes? (sketch?)

Re: libmaple F401 pill board gives usb-serial speeds almost 1.2Mbps

Posted: Wed Jun 03, 2020 3:13 pm
by ag123
the codes is something like

Code: Select all

#define BUF_SIZE 1280
uint8_t buf[1280];

void setup() {
	//populate some data
	for(int i=0; i<BUF_SIZE;i++) {
		buf[i] = i & 0xffU;
	}
}

void loop() {
	if(Serial.available()) {
		//read and discard the char
		uint8_t c = Serial.read();
		//then send our buffer
		for(int i=0; i<BUF_SIZE;i++) {
			Serial.write(buf[i]);
	}
	delay(1);
}
on the host side i've an app that basically 'send a character' to start the transfer. so that between the 'start transfer' and after i've received that 1280 chars i can do some timing measurements. repeated over many cycles, and averaged, that's how i measured the transfer rates.

the host side app written in java is something like

Code: Select all

port = getPort(portName);
port.openPort();
port.setComPortTimeouts(SerialPort.TIMEOUT_NONBLOCKING, 0, 0);
//this actually has no effect on usb-serial, i think the parameters are passed and ignored, which is what i want ;)
port.setComPortParameters(portRate, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY); 

inputStream = port.getInputStream();
outputStream = port.getOutputStream();

int len = 1280; //read 1280 bytes
ByteBuffer buf = ByteBuffer.allocate(len);
long toldur = 0
int loops = 1000;
for(int i = 0; i< loops; i++) {
	long begin =  System.System.nanoTime();
	outputStream.write('#"); //send a char to start the transfer	

	buf.rewind();
	while (buf.position() < len) {
		if (inputStream.available() > 0) {
			v = inputStream.read();
			if (v < 0)
				break;
			buf.put((byte) v);
		} else
			Thread.sleep(1);
		if (Thread.interrupted())
			throw new InterruptedException("sleep interrupted");	
	}
	toldur += System.System.nanoTime() - start;
}
int dur = toldur / loops;
System.out.println("duration of transfer (ns):" + Integer.toString(dur));
i used jSerialComm on the host side for receiving the data
https://fazecast.github.io/jSerialComm/
the java code above isn't complete, and java tends to be rather verbose with all that class declaration etc
i'd need to hack together this into a little app if anyone is really interested in it

in my actual app itself, the adc fills the buffer via dma, the transmit part Serial.write(...) is the same.

Re: libmaple F401 pill board gives usb-serial speeds almost 1.2Mbps

Posted: Sun Jul 19, 2020 10:48 am
by GonzoG
I get speed up to 5-6 Mbps on F103 blue pill and 1.7Mbps on Arduino Nano (serial speed set to 2Mbps) so 1.2 Mbps for F401 isn't even fast.

There is no baud rate for USB. You can put "Serial.begin(1);" in code and it still will work as fast as possible.