Report
1 year, 3 months ago.

How to debug a USB device stack ?

I am designed a IoT prototype with USB device CDC class, Linux (OpenWRT/Raspberry Pi) and VHLL(Python/Lua). Since USB‘s nature, USB CDC/ACM/ECM models are selected as standard interfaces to connectivities, rather than native SPI/I2C/UART on Cortex-A/MIPS SoC.

Currently I am using STM32F103C8/RB and STM32F070/072C8 as perferred micros, but I find USB stacks running on these micros have something wrong in Linux, including Ubunt/Raspbian/OpenWRT and other disto. The stacks comes from STM's HAL, Keil's USB stack, and other sources.

My test code:

But STM32F103C8 in STLINK/V2 and MicroPython in STM32F40X, these CDC firmware works well in Linux, as well as NXP's LPC54114 device driver ROM API.

STM32F103C8/RB with USB CDC stack works well in Windows, from XP to 10. But in Linux, they can be enumerated as /dev/ttyACM0, but no proper characters are printed out, I tried shell programming, Python and Lua. And finally I have tried usbmon tool in Ubuntu. I can narrow down the issue, the USB micro has NO output at all. Here is my usbmon logging.

STM32 USB

f3e3f9c0 1138689644 S Ii:1:004:1 -115:2 16 <
f51fd6c0 1138692116 S Co:1:004:0 s 21 22 0003 0000 0000 0
f51fd6c0 1138703025 C Co:1:004:0 0 0
f3e3fa80 1138703444 S Bi:1:004:2 -115 128 <
f3e3fb40 1138703524 S Bi:1:004:2 -115 128 <
f3e3ff00 1138703570 S Bi:1:004:2 -115 128 <
f3e3fe40 1138703610 S Bi:1:004:2 -115 128 <
f3e3f900 1138703652 S Bi:1:004:2 -115 128 <
f3e3f780 1138703692 S Bi:1:004:2 -115 128 <
f3e3f6c0 1138703817 S Bi:1:004:2 -115 128 <
f3e3f600 1138703865 S Bi:1:004:2 -115 128 <
f3e3fc00 1138703906 S Bi:1:004:2 -115 128 <
f3e3fcc0 1138703947 S Bi:1:004:2 -115 128 <
f3e3f540 1138703987 S Bi:1:004:2 -115 128 <
f3e3f480 1138704026 S Bi:1:004:2 -115 128 <
f3e3f3c0 1138704066 S Bi:1:004:2 -115 128 <
f3e3f300 1138704106 S Bi:1:004:2 -115 128 <
f3e3f240 1138704147 S Bi:1:004:2 -115 128 <
f3e3f180 1138704188 S Bi:1:004:2 -115 128 <
f6c65840 1138704450 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65cc0 1138704878 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65d80 1138704970 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65600 1138705045 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65240 1138705117 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65000 1138705189 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c659c0 1138705261 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65b40 1138705333 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c656c0 1138705459 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65300 1138705515 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65f00 1138705559 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65900 1138705603 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65780 1138705646 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65480 1138705690 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65c00 1138705734 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f5267c00 1138705778 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65840 1138708227 C Bo:1:004:2 0 13 >
f6c65840 1138708367 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65cc0 1138710127 C Bo:1:004:2 0 13 >
f6c65cc0 1138710433 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65d80 1138713557 C Bo:1:004:2 0 13 >
f6c65d80 1138714950 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65600 1138716389 C Bo:1:004:2 0 13 >
f6c65240 1138716408 C Bo:1:004:2 0 13 >
f6c65600 1138716629 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65240 1138716705 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c65000 1138720337 C Bo:1:004:2 0 13 >
f6c65000 1138720673 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a
f6c659c0 1138722247 C Bo:1:004:2 0 13 >
f6c65b40 1138722271 C Bo:1:004:2 0 13 >
f6c659c0 1138722502 S Bo:1:004:2 -115 13 = 48656c6c 6f20776f 726c640d 0a

In above logging, every bulk in is failed, bulk out is fine in LInux, I haven't check its output buffer in micro.

NXP USB

f6e45180 2640787952 C Bi:1:006:5 0 2 = 0d0a
f6e45180 2640787990 S Bi:1:006:5 -115 32 <
f6e45300 2640788823 C Bi:1:006:5 0 3 = 726573
f6e45300 2640788841 S Bi:1:006:5 -115 32 <
f6e45f00 2640789745 C Bi:1:006:5 0 4 = 65742034
f6e45f00 2640789763 S Bi:1:006:5 -115 32 <
f6e45e40 2640790812 C Bi:1:006:5 0 4 = 33332e33
f6e45e40 2640790838 S Bi:1:006:5 -115 32 <
f6e45d80 2640795349 C Bi:1:006:5 0 4 = 32303030
f6e45d80 2640795382 S Bi:1:006:5 -115 32 <
f6e45cc0 2640798478 C Bi:1:006:5 0 3 = 370d0a
f6e45cc0 2640798501 S Bi:1:006:5 -115 32 <
f6e45c00 2640853515 C Bi:1:006:5 0 1 = 34
f6e45c00 2640853542 S Bi:1:006:5 -115 32 <
f6e45b40 2640854401 C Bi:1:006:5 0 4 = 33342e30
f6e45b40 2640854419 S Bi:1:006:5 -115 32 <
f6e45780 2640856682 C Bi:1:006:5 0 4 = 30303030
f6e45780 2640856703 S Bi:1:006:5 -115 32 <
f522b240 2640858403 C Bi:1:006:5 0 4 = 304d487a
f522b240 2640858429 S Bi:1:006:5 -115 32 <
f522b180 2640862356 C Bi:1:006:5 0 3 = 0d0a75
f522b180 2640862383 S Bi:1:006:5 -115 32 <
f522b0c0 2640864166 C Bi:1:006:5 0 8 = 73696e67 20736637
f522b0c0 2640864192 S Bi:1:006:5 -115 32 <
f522b000 2640864291 C Bi:1:006:5 0 2 = 0d0a
f522b000 2640864296 S Bi:1:006:5 -115 32 <
f6e45900 2641504293 C Bi:1:006:5 0 4 = 6368303a
f6e45900 2641504417 S Bi:1:006:5 -115 32 <
f6e45000 2641505511 C Bi:1:006:5 0 4 = 202d3132
f6e45000 2641505536 S Bi:1:006:5 -115 32 <
f6e450c0 2641505560 C Bi:1:006:5 0 4 = 332e3337
f6e450c0 2641505562 S Bi:1:006:5 -115 32 <
f6e45180 2641506461 C Bi:1:006:5 0 4 = 35303030
f6e45180 2641506480 S Bi:1:006:5 -115 32 <
f6e45300 2641507381 C Bi:1:006:5 0 2 = 0d0a
f6e45300 2641507396 S Bi:1:006:5 -115 32 <
f6e45f00 2642151605 C Bi:1:006:5 0 4 = 6368313a
f6e45f00 2642151642 S Bi:1:006:5 -115 32 <
f6e45e40 2642152172 C Bi:1:006:5 0 3 = 202d31
f6e45e40 2642152179 S Bi:1:006:5 -115 32 <
f6e45d80 2642152179 C Bi:1:006:5 0 4 = 32322e37
f6e45d80 2642152182 S Bi:1:006:5 -115 32 <
f6e45cc0 2642153309 C Bi:1:006:5 0 4 = 39363837
f6e45cc0 2642153324 S Bi:1:006:5 -115 32 <
f6e45c00 2642154062 C Bi:1:006:5 0 3 = 350d0a
f6e45c00 2642154084 S Bi:1:006:5 -115 32 <
f6e45b40 2642797520 C Bi:1:006:5 0 3 = 636832
f6e45b40 2642797550 S Bi:1:006:5 -115 32 <
f6e45780 2642798408 C Bi:1:006:5 0 4 = 3a202d31
f6e45780 2642798428 S Bi:1:006:5 -115 32 <
f522b240 2642799435 C Bi:1:006:5 0 4 = 32322e37
f522b240 2642799456 S Bi:1:006:5 -115 32 <
f522b180 2642800357 C Bi:1:006:5 0 4 = 30333132
f522b180 2642800373 S Bi:1:006:5 -115 32 <
f522b0c0 2642802580 C Bi:1:006:5 0 3 = 350d0a
f522b0c0 2642802587 S Bi:1:006:5 -115 32 <
f522b000 2643446519 C Bi:1:006:5 0 3 = 636833
f522b000 2643446554 S Bi:1:006:5 -115 32 <
f6e45900 2643447358 C Bi:1:006:5 0 3 = 3a202d
f6e45900 2643447375 S Bi:1:006:5 -115 32 <
f6e45000 2643447389 C Bi:1:006:5 0 4 = 3132332e
f6e45000 2643447391 S Bi:1:006:5 -115 32 <
f6e450c0 2643447401 C Bi:1:006:5 0 4 = 30343638
f6e450c0 2643447402 S Bi:1:006:5 -115 32 <
f6e45180 2643448419 C Bi:1:006:5 0 4 = 37350d0a
f6e45180 2643448434 S Bi:1:006:5 -115 32 <
f6e45300 2644091509 C Bi:1:006:5 0 2 = 6368
f6e45300 2644091545 S Bi:1:006:5 -115 32 <
f6e45f00 2644095359 C Bi:1:006:5 0 4 = 343a202d
f6e45f00 2644095394 S Bi:1:006:5 -115 32 <
f6e45e40 2644095643 C Bi:1:006:5 0 4 = 3132322e
f6e45e40 2644095647 S Bi:1:006:5 -115 32 <
f6e45d80 2644095664 C Bi:1:006:5 0 4 = 37333433
f6e45d80 2644095666 S Bi:1:006:5 -115 32 <
f6e45cc0 2644100140 C Bi:1:006:5 0 3 = 37350d
f6e45cc0 2644100234 S Bi:1:006:5 -115 32 <
f6e45c00 2644102025 C Bi:1:006:5 0 1 = 0a
f6e45c00 2644102052 S Bi:1:006:5 -115 32 <
f6e45b40 2644738614 C Bi:1:006:5 0 2 = 6368
f6e45b40 2644738651 S Bi:1:006:5 -115 32 <
f6e45780 2644741501 C Bi:1:006:5 0 3 = 353a20
f6e45780 2644741511 S Bi:1:006:5 -115 32 <
f522b240 2644742421 C Bi:1:006:5 0 4 = 2d313232
f522b240 2644742446 S Bi:1:006:5 -115 32 <
f522b180 2644742468 C Bi:1:006:5 0 4 = 2e393231
f522b180 2644742470 S Bi:1:006:5 -115 32 <
f522b0c0 2644742484 C Bi:1:006:5 0 4 = 3837350d
f522b0c0 2644742486 S Bi:1:006:5 -115 32 <
f522b000 2644743408 C Bi:1:006:5 0 1 = 0a
f522b000 2644743428 S Bi:1:006:5 -115 32 <
f6e45900 2645385615 C Bi:1:006:5 0 1 = 63
f6e45900 2645385653 S Bi:1:006:5 -115 32 <
f6e45000 2645386407 C Bi:1:006:5 0 4 = 68363a20
f6e45000 2645386546 S Bi:1:006:5 -115 32 <
f6e450c0 2645387428 C Bi:1:006:5 0 4 = 2d313232
f6e450c0 2645387448 S Bi:1:006:5 -115 32 <
f6e45180 2645390425 C Bi:1:006:5 0 4 = 2e393834
f6e45180 2645390554 S Bi:1:006:5 -115 32 <
f6e45300 2645391424 C Bi:1:006:5 0 3 = 333735
f6e45300 2645391439 S Bi:1:006:5 -115 32 <
f6e45f00 2645391454 C Bi:1:006:5 0 4 = 0d0a7573
f6e45f00 2645391456 S Bi:1:006:5 -115 32 <
f6e45e40 2645391466 C Bi:1:006:5 0 4 = 696e6720
f6e45e40 2645391467 S Bi:1:006:5 -115 32 <
f6e45d80 2645392544 C Bi:1:006:5 0 4 = 6368302c
f6e45d80 2645392564 S Bi:1:006:5 -115 32 <
f6e45cc0 2645396242 C Bi:1:006:5 0 4 = 20343333
f6e45cc0 2645396278 S Bi:1:006:5 -115 32 <
f6e45c00 2645398078 C Bi:1:006:5 0 4 = 33323030
f6e45c00 2645398103 S Bi:1:006:5 -115 32 <
f6e45b40 2645398125 C Bi:1:006:5 0 4 = 3030687a
f6e45b40 2645398127 S Bi:1:006:5 -115 32 <
f6e45780 2645398143 C Bi:1:006:5 0 2 = 0d0a
f6e45780 2645398145 S Bi:1:006:5 -115 32 <
f522b240 2645400353 C Bi:1:006:5 0 4 = 70726573
f522b240 2645400360 S Bi:1:006:5 -115 32 <
f522b180 2645401933 C Bi:1:006:5 0 8 = 3a313430 3632352c
f522b180 2645401954 S Bi:1:006:5 -115 32 <
f522b0c0 2645406827 C Bi:1:006:5 0 8 = 20636f72 65636c6f
f522b0c0 2645406842 S Bi:1:006:5 -115 32 <
f522b000 2645408221 C Bi:1:006:5 0 7 = 636b3a37 323030
f522b000 2645408242 S Bi:1:006:5 -115 32 <
f6e45900 2645408259 C Bi:1:006:5 0 8 = 30303030 0d0a746f
f6e45900 2645408260 S Bi:1:006:5 -115 32 <
f6e45000 2645410642 C Bi:1:006:5 0 3 = 6f2073
f6e45000 2645410654 S Bi:1:006:5 -115 32 <
f6e450c0 2645412008 C Bi:1:006:5 0 8 = 6d616c6c 20312c20
f6e450c0 2645412026 S Bi:1:006:5 -115 32 <
f6e45180 2645417355 C Bi:1:006:5 0 5 = 736e723a 2d
f6e45180 2645417514 S Bi:1:006:5 -115 32 <
f6e45300 2645417865 C Bi:1:006:5 0 10 = 372e3520 2d313337 6442
f6e45300 2645417896 S Bi:1:006:5 -115 32 <
f6e45f00 2645417937 C Bi:1:006:5 0 3 = 6d0d0a
f6e45f00 2645417960 S Bi:1:006:5 -115 32 <
f6e45e40 2651898506 C Bi:1:006:5 0 3 = 0d0a72
f6e45e40 2651898545 S Bi:1:006:5 -115 32 <
f6e45d80 2651899376 C Bi:1:006:5 0 4 = 65736574
f6e45d80 2651899397 S Bi:1:006:5 -115 32 <
f6e45cc0 2651902573 C Bi:1:006:5 0 3 = 203433
f6e45cc0 2651902583 S Bi:1:006:5 -115 32 <
f6e45c00 2651903444 C Bi:1:006:5 0 4 = 332e3332
f6e45c00 2651903469 S Bi:1:006:5 -115 32 <
f6e45b40 2651903490 C Bi:1:006:5 0 4 = 30303037
f6e45b40 2651903493 S Bi:1:006:5 -115 32 <
f6e45780 2651903508 C Bi:1:006:5 0 2 = 0d0a
f6e45780 2651903510 S Bi:1:006:5 -115 32 <
f522b240 2651963474 C Bi:1:006:5 0 2 = 3433
f522b240 2651963510 S Bi:1:006:5 -115 32 <
f522b180 2651964309 C Bi:1:006:5 0 4 = 342e3030
f522b180 2651964318 S Bi:1:006:5 -115 32 <
f522b0c0 2651972333 C Bi:1:006:5 0 4 = 30303030
f522b0c0 2651972383 S Bi:1:006:5 -115 32 <
f522b000 2651973089 C Bi:1:006:5 0 4 = 4d487a0d
f522b000 2651973103 S Bi:1:006:5 -115 32 <
f6e45900 2651973127 C Bi:1:006:5 0 3 = 0a7573
f6e45900 2651973130 S Bi:1:006:5 -115 32 <
f6e45000 2651973144 C Bi:1:006:5 0 8 = 696e6720 7366370d
f6e45000 2651973146 S Bi:1:006:5 -115 32 <
f6e450c0 2651974766 C Bi:1:006:5 0 1 = 0a
f6e450c0 2651974789 S Bi:1:006:5 -115 32 <
f6e45180 2652611933 C Bi:1:006:5 0 1 = 63
f6e45180 2652611972 S Bi:1:006:5 -115 32 <
f6e45300 2652612808 C Bi:1:006:5 0 4 = 68303a20
f6e45300 2652612822 S Bi:1:006:5 -115 32 <
f6e45f00 2652613843 C Bi:1:006:5 0 4 = 2d313233
f6e45f00 2652613873 S Bi:1:006:5 -115 32 <
f6e45e40 2652614792 C Bi:1:006:5 0 4 = 2e343638
f6e45e40 2652614807 S Bi:1:006:5 -115 32 <
f6e45d80 2652618021 C Bi:1:006:5 0 4 = 3735300d
f6e45d80 2652618028 S Bi:1:006:5 -115 32 <
f6e45cc0 2652622868 C Bi:1:006:5 0 1 = 0a
f6e45cc0 2652622904 S Bi:1:006:5 -115 32 <
f6e45c00 2653259868 C Bi:1:006:5 0 1 = 63
f6e45c00 2653259907 S Bi:1:006:5 -115 32 <
f6e45b40 2653260457 C Bi:1:006:5 0 4 = 68313a20
f6e45b40 2653260471 S Bi:1:006:5 -115 32 <
f6e45780 2653261430 C Bi:1:006:5 0 4 = 2d313232
f6e45780 2653261448 S Bi:1:006:5 -115 32 <
f522b240 2653265514 C Bi:1:006:5 0 3 = 2e3932
f522b240 2653265545 S Bi:1:006:5 -115 32 <
f522b180 2653267261 C Bi:1:006:5 0 4 = 31383735
f522b180 2653267283 S Bi:1:006:5 -115 32 <
f522b0c0 2653267304 C Bi:1:006:5 0 2 = 0d0a
f522b0c0 2653267306 S Bi:1:006:5 -115 32 <
f522b000 2653909274 C Bi:1:006:5 0 4 = 6368323a
f522b000 2653909315 S Bi:1:006:5 -115 32 <
f6e45900 2653909798 C Bi:1:006:5 0 4 = 202d3132
f6e45900 2653909807 S Bi:1:006:5 -115 32 <
f6e45000 2653909827 C Bi:1:006:5 0 4 = 322e3738
f6e45000 2653909830 S Bi:1:006:5 -115 32 <
f6e450c0 2653912444 C Bi:1:006:5 0 4 = 31323530
f6e450c0 2653912473 S Bi:1:006:5 -115 32 <
f6e45180 2653915717 C Bi:1:006:5 0 2 = 0d0a
f6e45180 2653915748 S Bi:1:006:5 -115 32 <
f6e45300 2654554525 C Bi:1:006:5 0 4 = 6368333a
f6e45300 2654554564 S Bi:1:006:5 -115 32 <
f6e45f00 2654555397 C Bi:1:006:5 0 4 = 202d3132
f6e45f00 2654555485 S Bi:1:006:5 -115 32 <
f6e45e40 2654556555 C Bi:1:006:5 0 3 = 322e38
f6e45e40 2654556583 S Bi:1:006:5 -115 32 <
f6e45d80 2654559771 C Bi:1:006:5 0 4 = 39303632
f6e45d80 2654559806 S Bi:1:006:5 -115 32 <
f6e45cc0 2654561258 C Bi:1:006:5 0 3 = 350d0a
f6e45cc0 2654561282 S Bi:1:006:5 -115 32 <
f6e45c00 2655201464 C Bi:1:006:5 0 3 = 636834
f6e45c00 2655201501 S Bi:1:006:5 -115 32 <
f6e45b40 2655202469 C Bi:1:006:5 0 4 = 3a202d31
f6e45b40 2655202484 S Bi:1:006:5 -115 32 <
f6e45780 2655203466 C Bi:1:006:5 0 4 = 32322e38
f6e45780 2655203488 S Bi:1:006:5 -115 32 <
f522b240 2655206914 C Bi:1:006:5 0 4 = 32383132
f522b240 2655206942 S Bi:1:006:5 -115 32 <
f522b180 2655207803 C Bi:1:006:5 0 3 = 350d0a
f522b180 2655207826 S Bi:1:006:5 -115 32 <
f522b0c0 2655847989 C Bi:1:006:5 0 3 = 636835
f522b0c0 2655848026 S Bi:1:006:5 -115 32 <
f522b000 2655848903 C Bi:1:006:5 0 4 = 3a202d31
f522b000 2655848926 S Bi:1:006:5 -115 32 <
f6e45900 2655851289 C Bi:1:006:5 0 3 = 32322e
f6e45900 2655851296 S Bi:1:006:5 -115 32 <
f6e45000 2655852619 C Bi:1:006:5 0 4 = 37303331
f6e45000 2655852643 S Bi:1:006:5 -115 32 <
f6e450c0 2655856560 C Bi:1:006:5 0 4 = 32350d0a
f6e450c0 2655856589 S Bi:1:006:5 -115 32 <
f6e45180 2656495516 C Bi:1:006:5 0 2 = 6368
f6e45180 2656495545 S Bi:1:006:5 -115 32 <
f6e45300 2656496403 C Bi:1:006:5 0 4 = 363a202d

In a normal USB device, both bulk in and bulk out is working well.

Since USB firmware debugging is quite complex, does anyone who has experiences on this issue?

Comment on this question
Be the first to answer this question.

To post an answer, please log in.