dmitrystu / libusb_stm32

Lightweight USB device Stack for STM32 microcontrollers
Apache License 2.0
707 stars 160 forks source link

Not sending data back with certain characters #81

Closed Electro707 closed 2 years ago

Electro707 commented 3 years ago

First of all thanks for this lightweight library. ST's USB HAL was way too bloated (used up more than the flash memory availale for my application). Unfortunately I have ran into a potential issue: Using the example loopback program under an STML052 (USB CDC), if I send certain hex values (like 0xFF, 0xFE, 0xEF, etc) the device will not loopback the given characters. I am not sure if there are against the CDC spec, the library's fault, or Linux's fault (although I did try it under Windows with the same outcome). I actually noticed this when programming my ST to reply back read EEPROM, in which they were all 0xFF's (due to the lack of programming the EEPROM).

Setup Info:

OS: Arch Linux (Kernel v5.11)
LibUSB: Latest 
MCU: STM32L052
Electro707 commented 3 years ago

I just loaded a standalone program for USB using ST's HAL library, and all characters gets sent over (a basic program where it loops sending back every possible characters). Going thru ST's code for differences, while it might not be related to this issue, they call the following function after writing to the pma: PCD_SET_EP_TX_CNT(USBx, ep->num, len); which sets counter for the tx/rx buffer. (their code comment). I am not sure if that is important or not, but tomorrow (or whenever I get to it) I'll hack this in this library and see if it does anything.

EDIT: Nevermind, this library also adjusts the tx counter with tx->cnt = blen;

Electro707 commented 2 years ago

The issue actually turned out to be a bug in STMCube's LowLevel library code for the RCC. When I switched that over to HAL, USB started working.