AnsweredAssumed Answered

STM32L073 USB PMA issue - HAL lib misinterpreting SETUP packets

Question asked by Stephen Whittle on Aug 30, 2017

So I'm currently working on a custom HID with STM32L073CZ using code generated by the latest version of Cube and CubeMX, and I'm running into an issue with intermittent enumeration being caused by SETUP packets not always being recognised properly. Enumeration begins without issues (you can see here the on-device log, showing the PMA contents, on the left matching up with my protocol analyzer output on the right):

First part of enumeration - working correctly

 

However, at some point during the enumeration process (not always on the same request), the device receives a SETUP packet, that it wrongly interprets as being of length 0 (xfer_count is 0 after the following line executes):




ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);

This means that when PCD_ReadPMA is called with wNBytes == 0, that nothing is copied from the PMA into hpcd->Setup. All fine and dandy, but hpcd->Setup still contains the SETUP information from the previous packet.

This is a problem, because HAL_PCD_SetupStageCallback is called regardless, meaning that the previous SETUP packet is handled again with the stale hpcd->Setup contents, leading to the following problem:

The protocol analyzer clearly shows SETUP packets with their contents changing, but the device believes the setup packet to be empty, and further logging of the PMA contents directly inside ReadPMA shows that the PMA contents don't change either.




680 200 0 FF
PMA read
Setup request parsed as: bmReq 80 - bReq 6 - wVal 200 - wIndex 0 - wLen FF
fsconfig
680 200 0 FF
PMA read
Setup request parsed as: bmReq 80 - bReq 6 - wVal 200 - wIndex 0 - wLen FF
fsconfig
680 200 0 FF
PMA read
Setup request parsed as: bmReq 80 - bReq 6 - wVal 200 - wIndex 0 - wLen FF
fsconfig
680 200 0 FF
PMA read
Setup request parsed as: bmReq 80 - bReq 6 - wVal 200 - wIndex 0 - wLen FF
fsconfig
680 200 0 FF
PMA read
Setup request parsed as: bmReq 80 - bReq 6 - wVal 200 - wIndex 0 - wLen FF
fsconfig
 

 

This issue is still present in the current version of Cube I am using,  HAL_PCD_EP_GetRxCount returning wrong value ? , but applying the fixes from that thread don't do anything to fix this issue as that is related to data rather than setup packets. 

 

I've attached my current elf file to this thread. Has anybody encountered anything like this before? 

Attachments

Outcomes