Issues with Odrive native interface over USB (C++)


I am trying to get Odrive working with C++ over USB.
I am using libusb to facilitate the communication between my machine and Odrive.

I am first trying to retrieve the JSON endpoints definition from within the USB itself.
Per the documentation I am creating my request like so and sending it to endpoint 0:

81 0 0 80 40 0 0 0 0 0 1 0

I can then get a response from the Odrive and then try to retrieve the rest of the JSON. So I will send another request like so:

82 0 0 80 40 0 0 0 0 0 1 0

I am getting a response from the Odrive but it is always the exact same and so I am not sure what is going wrong here. The response I am getting is (minus the first 2 bytes):

5b 7b 22 6e 61 6d 65 22 3a 22 22 2c 22 69 64 22 3a 30 2c 22 74 79 70 65 22 3a 22 6a 73 6f 6e 22 2c 22 61 63 63 65 73 73 22 3a 22 72 22 7d 2c 7b 22 6e 61 6d 65 22 3a 22 65 72 72 6f 72

Which decodes to:


But I am not sure what I am doing wrong here. Any help would be appreciated!

The payload of your request needs to contain the number of bytes you already received. If you always set it to 0, you always get the beginning of the json :wink:

Something like this:

	do {
		serialize(send_payload, (int)received_json.size());
		endpoint_request(0, receive_payload, send_payload, true, 64, false);
		for (u8 byte : receive_payload) {
			//printf("%c", byte);
	} while (receive_payload.size());

BTW It’s strange that you receive anything at all. Usually the last two bytes should contain the firmware crc.

Awesome that was the missing piece of the puzzle thanks for your help!
The CRC for endpoint 0 is the protocol version but for all other endpoints it’s the CRC of the JSON.
Do you know how large the JSON is currently? I am trying to ensure I did everything properly.

No, but you can keep requesting data until nothing comes back. See my code above

Ok so everything is working now thanks a lot for your help.
I’ve moved on to trying to use other endpoints. I started off with endpoint 5 to try to retrieve the SN.
The issue is I am not 100% sure if my JSON CRC is correct.

In the documentation it takes you to a sample calculator that you can use to calculate the CRC16.

I am not clear if the initial value should be 0x0001 or 0x1337 but neither of the CRCs generated from the retrieved JSON seem to work (0x23F7 or 0xD67B).

I am querying endpoint 5 like so but keep receiving a timeout response:

70 3 5 80 8 0 0 0 0 0 f7 23 

Any advice would be great :slight_smile:

Ok I learned from another forum that the CRC should be 0xD271 but I am not sure what the difference is in the calculation since I used the same algo from the documentation.

You can send a request with endpoint 0 and 0xffffffff in the payload. You then receive a 32-bit number with the crc being the upper 16 bits. Don’t know if this is official behavior, but it works :wink: