cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072 CAN to USB HID Converter

engineerhan
Associate

Hi all!

I am planning to make a USB to CAN converter or can sniffer and want to do it in most efficient way. First step can be just sniffer. So I want send all received packages from CAN(at max speed (500kbps %80 or %100 bus traffic) and send them via USB like real time. I want to do it without any latency nor data lost. Is it possible to do it? I saw in the datasheet (page 30) that there is a shared memory with CAN and USB.

How it works actually?

Can CAN write the received packages to this memory and can USB send the packages to the PC with HID interface when there is a new package?

Can I make the process automatically? Is there any app note or example about that?

Thanks in advance.

cheers,

0693W00000SwFUtQAN.png 

1 REPLY 1
JPeac.1
Senior

For a USB 2.0 Device you can use the CDC class for no-loss communications at the rate of one SOF (start of USB frame) every millisecond, or 64,000 bytes (64 data per SOF) per second. However, USB is half duplex, with an ACK needed from the host, so the theoretical max to transmit is about half (32,000 bytes/sec). In practice you won't see rates that high due to latency on device and host ends.

Regular CAN has a total packet size of roughly 8 to 16 bytes (8 to 72 for FD-CAN), if you include the header and timestamp (that's important for a sniffer). Average case your thruput would be around 2,000 CAN packets/second delivered through USB. In practice some packets will be only 8 bytes, with no data field, so it might be a little better. So the question is, how many packets/sec can your CAN network support? Collisions increase with active node count and the CAN protocol used, so the more nodes running, the lower the theoretical maximum per second. You can calculate the absolute worst case with only two nodes present, and only one sending as fast as possible. That will tell you if you can sustain a CAN rate of 500Kbaud.

Alternatively, you can go with a controller that supports USB 480M/bit HS mode. Plenty of USB bandwidth then, but an order more complex for software.

I would not recommend HID mode unless you intend to interpret the CAN messages into something meaningful for an HID device. Converting manifold pressure transducer measurements from CAN to a mouse operation results in the cursor bouncing all over the display.

Jack Peacock