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

Post Reply
ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

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

Post 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.

User avatar
fpiSTM
Posts: 661
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 25
Location: Le Mans
Contact:

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

Post by fpiSTM »

How did you measure the time?
And how did you transferring the 1280 bytes? (sketch?)

ag123
Posts: 467
Joined: Thu Dec 19, 2019 5:30 am
Answers: 1

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

Post 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.

GonzoG
Posts: 27
Joined: Wed Jan 15, 2020 11:30 am
Answers: 2

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

Post 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.

Post Reply

Return to “STM32F4 based boards”