satoshinm / pill_duck

Scriptable USB HID device for STM32F103 blue pill (inspired by USB Rubber Ducky) ⛺
GNU General Public License v3.0
63 stars 17 forks source link

Fix USB packet sending speed synchronization overwriting, necessitating 100 ms systick #3

Closed satoshinm closed 6 years ago

satoshinm commented 6 years ago

Calling usbd_ep_write_packet() too quickly overwrites the send buffer, so I slowed down the system tick to 100 ms allowing time to send. This should be properly fixed and the systick timer sped up, investigate how USB stalls work and what is needed to wait for the USB host to process a packet before sending another one.

satoshinm commented 6 years ago

https://sourceforge.net/p/libopencm3/mailman/libopencm3-devel/?page=27

You only need to call usbd_ep_write_packet to send, but you should check its return value. It returns the number of bytes written. If zero you should retry. The callback is only needed if you want your sending to be interrupt/callback driven.

satoshinm commented 6 years ago

If I change to systick_set_reload(89999); // 10 ms, and test with d00ff00ff00ff00eb0b0208000f000f00120036002c001a00120015000f000700 (Hello, world), then it sends too fast and misses some keystrokes:

HworldHlo, worHelo,HrldH, worldHelo, wHelHworldHlo, worHeloHrldH, worldHelo, wHeldHworldHlo, worHeloHrldH, worldHelo, HeldHworldHlo, worHelorldHo, worldHelo, HeldHworldHlo, woHelorldHo, worldHelo, HedH worldHlo, woHelorldHo, worlHelo, HedH worldHlo, woHeloorldHo, worlHelo, HedH worldHelo, woHellll