Leonardo baud rate for USB CDC

That is no surprise is it?

It is still a USB device and that get polled at a maximum of 1KHz, so I guess it is down to how fast the host computer empties the buffer. Allowing more bytes to be transferred.

Grumpy_Mike: That is no surprise is it?

No.

Grumpy_Mike: It is still a USB device and that get polled at a maximum of 1KHz, so I guess it is down to how fast the host computer empties the buffer. Allowing more bytes to be transferred.

Where does the 1kHz come from?

Where does the 1kHz come from?

The polling rate of a USB HID device.

That 1 ms polling rate is true only for HID (the keyboard and mouse) which use the USB interrupt transfer type. CDC (which Leonardo refers to as Serial) uses the USB bulk transfer type which doesn't guarantee timing but does guarantee that it will transfer the data as fast as possible. That "fast as possible" depends on what else is happening on the bus AND on the host computer.

In practice this does lead to different maximum transfer speeds for Serial on different computers (and even on the same computer under different workloads). I don't have a board with me right now but, from memory, you can usually assume at least several tens of kb per second, up to a few hundreds of kbps.

It's not necessary to call Serial.begin() for the Leonardo since the CDC device is initialized elsewhere. The stub was retained for backwards-compatibility.

Serial (which talks CDC over USB to the host) and Serial1 (which talks to pins 0 and 1 via the UART) are both definitely available and usable on the Leonardo.

zeveland, I noticed much of the USB code for Arduino came from you. Can you say how you learned to write "USB code?" I read part of one book on the topic, but the material wasn't well written and as a result difficult to understand.

mkwired, sorry - had overlooked your message. I can't take much credit - most of the implementation was done by a brilliant guy named Peter Barrett.

Almost everything I know about USB has come from working with Dean Camera's LUFA project (http://fourwalledcubicle.com/LUFA.php), reading Jan Axelson's USB Complete book, and reading the specs until my eyes bled.

I found this interesting:

zeveland:
It’s not necessary to call Serial.begin() for the Leonardo since the CDC device is initialized elsewhere. The stub was retained for backwards-compatibility.

… since it seems to say that the serial speed for the USB CDC is independent of whatever code you write. I’m inferring that since you don’t need to open the port with a speed (e.g. Serial.begin(115200))

Does that sound right?

Which leads me to my second question:

Q: Is the serial monitor in the Arduino IDE monitoring the USB CDC serial port or the hardware serial port?

Thanks for any insights!

Daniel

Q: Is the serial monitor in the Arduino IDE monitoring the USB CDC serial port or the hardware serial port?

It's the USB CDC (unless you connected a USB2Serial to the hardware serial port and to the PC too).

.. since it seems to say that the serial speed for the USB CDC is independent of whatever code you write. I'm inferring that since you don't need to open the port with a speed (e.g. Serial.begin(115200))

Does that sound right?

As you can see in the implementation:

void Serial_::begin(uint16_t baud_count)
{
}

... this is correct.

Thanks for the clarification!

The documentation on serial ports fir the Leonardo is a bit lacking.

When you open the serial monitor, and are monitoring the USB(CDC) connection, does the baud rate pulldown have any effect?

D

When you open the serial monitor, and are monitoring the USB(CDC) connection, does the baud rate pulldown have any effect?

Theoretically yes, but it doesn't change any relevant parameter, it just sets some values in the driver on the PC. The counterpart on the Leonardo doesn't react on it.

There is transmit bandwidth benchmark program on the pjrc site: http://www.pjrc.com/teensy/usb_serial.html https://github.com/loganb/teensy-usb-serial/blob/master/tx_benchmark.c It shows darn fast 10Mbit/s max serial speed with teensy halfkay USB-Serial bootloader. Someone can try to adapt and test it on Leonardo.

So if i understand this thread right, Serial.begin(baudrate) does not have any effect for the speed of the USB CDC port?

Also i see in CDC.cpp a baud rate of 57600? Has this something to do with the speed of the port?

I ask, because i want to control a LED strip with 240 RGB LEDs over serial with a minumum of 25 Hz. This would be 240*3*25 = 18000 bytes per second over serial (or minumum 144000 bits per second). At the moment i do not have success. Seems to be too slow.

Maybe i should connect an FTDI breakout to the Serial1 ports on the Leonardo board? Can i set then 500k or 1M bau rate to Serial1?

Best regards TheChief

18000 bytes per second over serial (or minumum 144000 bits per second).

18000 * 10 != 144000

There are 2 extra bits per byte - the start and stop bits that separate the bytes.

OK, then i need a minumum of 180000 bits per second + some protocol bytes. The USB CDC seems to be not really with good performance. Any other ideas?

Well I reported at the start of this old thread that I measured the Leonardo transfer rate at 39258 bytes/second. That is faster than your required 18000 bytes per second. So if there are any performance issues it is not with the Leonardo.

But it is much slower then an FTDI Breakout? There i could set 500k, 1M or 2M on an 16Mhz Arduino.

I also tried the test scipt and cannot get more then 40000 bytes/s.

But it is much slower then an FTDI Breakout? There i could set 500k, 1M or 2M on an 16Mhz Arduino.

Where have you heard that? I doubt it will go that hight. Do you have seen any project receiving 2MB/s on an Arduino? Or even 2Mbit/s using the USART?

I also tried the test scipt and cannot get more then 40000 bytes/s.

So you're getting more than you require? Where's your problem?