rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.53k stars 1.26k forks source link

Issue with RAWHID and reports doubling #853

Closed Doridian closed 3 years ago

Doridian commented 3 years ago

It seems that incoming reports to my STM32 (STM32F1RET6) are doubling up in a weird way.

Lines with // are comments and not actually sent over USBSerial

// Program sends report ID 0, first byte 0, STM32 prints:
REPORT 0 0 0 0 0 0 0 0 
REPORT 0 0 0 0 0 0 0 0 

// Program sends report ID 0, first byte 1, STM32 prints:
REPORT 0 0 0 0 0 0 0 0 
REPORT 1 0 0 0 0 0 0 0 

// Program sends report ID 0, first byte 2, STM32 prints:
REPORT 1 0 0 0 0 0 0 0 
REPORT 2 0 0 0 0 0 0 0 

As you can see, whenever a new report comes in, it seems it reads the previous report...again somehow?

Output of program ([>] = sent this, [<] = received this)

[>] 00-00-00-00-00-00-00-00-00
[<] 00-00-00-00-00-00-00-00-00
[<] 00-00-00-00-00-00-00-00-00

[>] 00-01-00-00-00-00-00-00-00
[<] 00-00-00-00-00-00-00-00-00
[<] 00-01-00-00-00-00-00-00-00

[>] 00-02-00-00-00-00-00-00-00
[<] 00-01-00-00-00-00-00-00-00
[<] 00-02-00-00-00-00-00-00-00

As expected, the report ID is not part of the data, but why does it seem to repeat the previous report whenever a new one comes in? I have tested my program sending RAW HID reports with an Atmega32U4 and it only gets these once (it is also a very simple program only calling write with an incrementing first byte whenever I press enter)

The sketch I used is a basic echo-back program. I have also tried an example without USBCompositeSerial to see if that is the cause and it still got the reports doubled reading them ( https://github.com/arpruss/USBComposite_stm32f1/blob/master/examples/rawhid/rawhid.ino ).

Below is a gist of my sketch. Am I (and the example I found) using the library wrong maybe? https://gist.github.com/Doridian/d0cef69ecff14b3f3401a30297636e32

//EDIT: In case this is relevant, I am using Windows 10 and tried both node-hid in NodeJS and C#'s HID support, both with the exact same results. I have also tried both flashing the raw FW using an ST-Link (clone) as well as using the stm32duino bootloader. Same results. My board is one of these: https://stm32-base.org/boards/STM32F103RET6-Generic-Board