4.2.7 UART Command/Response Integrity Check
The MDFU UART Transport Layer definition uses a one’s compliment 16-bit checksum as a mechanism for detecting corruption in commands and responses. The details of the checksum calculation are provided below.
4.2.7.1 Checksum Computation Details
The following steps are used to calculate the one’s complement checksum over the entire command or response.
- Convert the command or response into a series of
uint16_t values.
- When the command or response contains an odd number of bytes, the upper byte of the last uint16_t value is set to 0x00.
- The added 0x00 is NOT placed into the command or response for transmission. It is only used in the checksum calculation.
- Add the uint16_t values together.
- Truncate the result of the addition to a uint16_t value.
- Calculate the one’s compliment of the truncated result.
4.2.7.2 Examples
The following example shows the checksum calculation for a command with an even number of bytes.
The following example shows the checksum calculation for a command with an odd number of bytes.