AnsweredAssumed Answered

USB Device DMA memory corruption

Question asked by Heaffey.Jack on Feb 21, 2017



I am using an STM32F7556NG microcontroller, connecting it to a host PC via USB, with the STM32 acting as a virtual COM port.


I have enabled DMA, an I have noticed very strange behaviour. By supplying a address 0x20024b6C as the DMA  address by writing to the DOEPDMA register, after the USB transaction is completed, I have inspected the memory and it seems that SETUP packet data of the the previous SETUP transaction has been written to the address 0x20024B54, which is 6 words before the given DMA address! After viewing the memory of the chip in a memory browser, the SETUP packet for the last transaction can be found at 0x40060081, which is way beyond the USB FIFO, which is very strange.


Page 1448 of the reference manual does say that:


"The application must always allocate some extra space in the Receive data FIFO, to be
able to receive up to three SETUP packets on a control endpoint.
– The space to be reserved is 10 Words. Three Words are required for the first
SETUP packet, 1 Word is required for the Setup stage done Word and 6 Words
are required to store two extra SETUP packets among all control endpoints.
– 3 Words per SETUP packet are required to store 8 bytes of SETUP data and 4
bytes of SETUP status (Setup packet pattern). The core reserves this space in the
receive data.
– FIFO to write SETUP data only, and never uses this space for data packets."


Does this mean that a buffer used for DMA should be larger than actually expected? Or even that a large buffer should be used and the DMA address given should be 10 words into the buffer?


Kind regards