The fdcanusb provides a USB 2.0 full speed interface to an FDCAN bus. It presents a serial-like interface over the USB port using the CDC ACM class, i.e. a virtual COM port.
The designs and firmware are licensed under the Apache 2.0 License.
Pre-assembled hardware can be purchased at https://mjbots.com/products/fdcanusb
To build on an Ubuntu 22.04 or newer system.
sudo apt install curl openocd
./tools/bazel build //fw:fdcanusb.bin
To flash:
./flash.sh
Each command or response is a single newline terminated line, composed
of 7-bit ASCII encoded characters. Every command sent from the client
to the device has a response which consists of an optional command
specific response followed by a final line consisting solely of OK
or
ERR <details>
.
The device can be in one of two states.
-
Bus Off: This is the initial state of the device. In this state, no frames may be sent or received, but the device may be configured.
-
Bus On: In this state frames may be sent and received, but configuration is locked out.
Sample commands are prefixed with >
to show the data sent from the
client to the device and <
to show the values sent from the device
to the client. Those characters are for illustrative purposes only,
and are not present in actual communications.
The "conf" command is used to read and set configuration values. It has several subcommands.
This emits all current configuration values one after another.
This queries the value of one specific configuration item.
>conf get sample.value
<31235
<OK
This sets the value of one specific configuration itme.
>conf set sample.value 1234
<OK
This loads all persistent configuration from the persistent storage.
>conf load
<OK
This stores all configuration values to persistent storage. They will then be the default when the device is powered on the in the future.
>conf write
<OK
Reset all configuration values to their "default" state.
>conf default
<OK
Enter the "Bus On" state. All configurable values are validated and put into place. This results in an error if the device is already in the "Bus On" state.
Enter the "Bus Off" state. Transmission and reception of CAN messages is halted, and configurable values may be changed.
Send a standard CAN frame. The following format is used.
can std <HEXID> <HEXDATA> <options>
options
may be zero or more of the following optionally separated by
spaces.
- B/b require/disable bitrate switching
- F/f require/disable FDCAN format
- R/r require/disable remote frame
Send an extended CAN frame. The following format is used.
can ext <HEXID> <HEXDATA> <options>
The allowable options are the same as for can std
.
Just like std
or ext
, but auto-detect the ID type.
Report the current mode and status of various flags.
>can status
<mode:BUSON
<OK
When in the "Bus On" state, the device may spontaneously emit the following lines upon receipt of valid CAN frames or other errors.
A CAN frame has been received.
<rcv <HEXID> <HEXDATA> <flags>
flags
may be zero of more of the following separated by spaces:
- E/e frame was received with extended/classic ID
- B/b frame was received with/without bitrate switching
- F/f frame was received in fdcan/classic mode
- R/r frame was remote/data frame
- tNNNNN timestamp of receipt measured in microseconds
- fNN integer ID of which filter matched this frame
The following items may be configured.
-
can.bitrate - The bitrate used for the CAN frame (or header only if bitrate switching is used.
-
can.fd_bitrate - The bitrate used for the data and CRC field when bitrate switching is used.
-
can.automatic_retransmission - When true/non-zero, frames will be retried until acknowledged.
-
can.fdcan_frame - By default, send frames in FDCAN mode
-
can.bitrate_switch - By default, switch to the
can.fd_bitrate
for the data and CRC fields. -
can.restricted_mode - Only transmit acknowledgements.
-
can.bus_monitor - Transmit nothing.
-
can.termination - Enable the onboard terminator
-
can.autostart - Enter BusOn immediately at power-on
-
can.global.std_action
-
can.global.ext_action
-
can.global.remote_std_action
-
can.global.remote_ext_action
- 0/1 - accept
- 2 - reject
-
can.filter.N.id1 - first ID
-
can.filter.N.id2 - second ID or bitmask
-
can.filter.N.mode
- 0 - range
- 1 - exact match
- 2 - bitmask
-
can.filter.N.type
- 0 - standard
- 1 - extended
-
can.filter.N.action
- 0 - disable
- 1 - accept
- 2 - reject