nuttx-apps
nuttx-apps copied to clipboard
Byte Order, Single Thread - Pi Pico: USB Serial
Writing from a single character array in the USB serial example in a single thread causes the bytes to write out of order. Ex, define the string as:
static const char out_string[] = {0xAA, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x88, 0x89};
Then call the write for a single byte, the next nineteen bytes, and then the last two bytes:
write(outfd, out_string, 1);
write(outfd, out_string[1], 19);
write(outfd, out_string[20], 2);
The output across the USB channel using:
cat /dev/ttyACM0 | hexdump -e '22/1 "%02X ""\n"" "'
will be similar to:
AA 1F 04 20 EF 00 00 00 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03
*
AA 01 02 5F 03 AA 00 00 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03
AA 00 31 00 00 00 4D 75 01 02 5F 03 AA 02 5F 03 AA 1F 04 20 EF 00
00 00 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03 AA 1F 04 20 EF 00
*
00 00 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03 AA 00 00 31 00 00
00 4D 75 01 02 5F 03 AA 1F 04 20 EF 00 00 00 35 00 00 00 31 00 00
*
00 4D 75 01 02 5F 03 AA 4D 75 01 02 5F 03 AA 00 00 4D 75 01 02 5F
03 AA 01 02 5F 03 AA 1F 04 20 EF 00 00 00 35 00 00 00 31 00 00 00
4D 75 01 02 5F 03 AA 1F 04 20 EF 00 00 00 35 00 00 00 31 00 00 00
*
4D 75 01 02 5F 03 AA 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03 AA
1F 04 20 EF 00 00 00 35 00 00 00 31 00 00 00 4D 75 01 02 5F 03 AA
75 01 02 5F 03 AA 1F 04 20 EF 00 00 00 35 00 00 00 31 00 00 00 4D
*
Whereas, a single write such as:
write(outfd, out_string, 22);
will produce the following using the same hexdump command as above:
AA 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 88 89
*