CRC error in QM31120WDK2 TLV API

I’m using the LEAPS UWBS firmware on the QM31120WDK2.

API command UWBS gateway
leaps_usr_data_read Yes No
leaps_usr_data_write Yes No

I want to record information about each device in the NVM. According to the table above, each API should work on UWBS.

Below is the test code. When I run the code, I get a CRC error, which is different from the expected response.

import serial
import time

def build_usr_data_read_tlv():
    Type = 0x19         # leaps_usr_data_read
    Length = 0x01       # 1 byte value
    Value = 0x02  # type=2 (NVM)

    tlv = bytes([Type, Length]) + bytes([Value])

    return tlv

def build_usr_data_write_tlv():
    Type = 0x1A         # leaps_usr_data_write
    Length = 0x05       # 5 byte value
    Value = 0x02        # type=2 (NVM)
    Data = bytes([0xAA, 0xBB, 0xCC, 0xDD])  # Data to write

    tlv = bytes([Type, Length]) + bytes([Value]) + Data

    return tlv


def send_and_receive(port="/dev/ttyUSB0", baud=115200):

    tlv = build_usr_data_read_tlv()

    print("TX TLV:", tlv.hex(" "))

    ser = serial.Serial(port, baudrate=baud, timeout=0.01)

    ser.write(tlv)
    ser.flush()

    time.sleep(0.1)

    rx = ser.read(256)

    print("RX RAW:", rx.hex(" "))

    ser.close()


if __name__ == "__main__":
    send_and_receive("COM27", 115200)

The result of the operation is: ‘6’ (checksum error).

(READ)
TX TLV: 19 01 02
RX RAW: 40 01 06 a0

(WRITE)
TX TLV: 1a 05 02 aa bb cc dd
RX RAW: 40 01 06 a0

What could be causing this error? I remember the DWM1001 had a shell mode command to write and read from nvm, but it seems to be missing on this model.

@leapslabs Do you know what is causing this problem or how to fix it?

I’m not familiar with the leaps firmware.
Maybe try to compute the CRC checksum of your TLV frame and append. There is example code here:

Hi,

  • It looks like the CRC is missing in your command. Value 6 is checksum error as you have indicated
  • The CRC calculation is shown on this link: TLV API — LEAPS
  • You can also use the shell command ‘tlv’ to get the CRC calculated, e.g.
leaps> tlv 0x19 0x01 0x02
CRC: 0x26
OUTPUT(hex): 
40 01 00 06 58 00 d0 
leaps>

Cheers,
TDK

@Matthias , @leapslabs

Thank you both.

I made a mistake. However, I believe the guide was written in a confusing way.
The code below shows what I tried (above) and what @leapslabs suggested (below).

leaps> tlv 19 01 02
CRC: 0xf8
OUTPUT(hex):
40 01 03 55

leaps> tlv 0x19 0x01 0x02
CRC: 0x26
OUTPUT(hex):
40 01 00 06 58 00 d0

According to the guide, it appears users don’t need to enter the 0xXX format. However, the correct command is executed only when the format is followed. This can be confusing and should be corrected.

Actually, I tried attaching a CRC before posting the question.

However, what was confusing was that when I tested it in Python, I followed the CRC example exactly, but the calculated CRC was a decimal value. I unknowingly used that value as the CRC, and the system seemed to report an invalid CRC.

If possible, could you please correct the last part of the code? I think you might make the same mistake I did. Maybe not. :sweat_smile:

print((crc_8(data))  ->  print(hex(crc_8(data)))
TX TLV: 19 01 02 26
RX RAW: 40 01 00 06 58 00 d0

I’ve verified that I can send commands in binary and receive responses, so I’ll close this question. Thank you.

Hi,

Great to hear you have been able to resolve the issue.

Thanks your feedback. We will review and fix that in case needed.

Cheers,
TDK