Determining USB CDC speed

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I try to determine the speed I can reach using USB CDC class using a SAME70.

I wrote a simple test that sends for example 1024 bytes, and compute timing with a TC (configured with MCK/128) and also sysTick to have 2 different measures:

uint32_t free_usb_tx;
uint32_t nb_to_send = 1024;
uint32_t send;
uint8_t tab[512];
for (int i=0; i<512; i++)
	tab[i] = (uint8_t)i;

debug_times[10] = g_ul_tick_count;
debug_times[0] = tc_read_cv(TC3, 0);
while (nb_to_send > 0) {
	free_usb_tx = udi_cdc_get_free_tx_buffer();
	if (free_usb_tx) {
		send = min(free_usb_tx, nb_to_send);
		udi_cdc_write_buf(tab, send);
		nb_to_send -= send;
	}
}
while(udi_cdc_get_free_tx_buffer() < 5*UDI_CDC_DATA_EPS_FS_SIZE);
debug_times[1] = tc_read_cv(TC3, 0);
debug_times[11] = g_ul_tick_count;

Note: I know that at the end of my code, there are still 5 frames to be send (in full speed mode, or 1 fram in high speed mode), so 5ms (or 1ms in high speed).

 

If I configure it as Full Speed, I expect to be able to send 64 bytes every ms, so sending should take 16ms (-5ms because I don't know how to ask µC when all data are really sent)

But I measure something like 1.4ms !! How is that possible?

 

Same problem with High speed: In that case I send more data: 10240 bytes.

I expect to be able to send 512bytes every ms, so it should take 20ms (-1ms).

But I measure 1.5ms! (0x0750-0x0066 = 1770; 1770*128/150e6 = 1.5ms)

 

I'm happy it's faster, but I'd like to understand what happens!