2025-10-03 9:46 AM
Currently, in the HAL USB driver, the PCD_HandleTypeDef structure embeds the setup packet buffer directly:
uint32_t Setup[12]; /*!< Setup packet buffer */
This design tightly couples the control structure (state, locks, callbacks) with a DMA-dependent buffer. As a result:
When USB OTG FS/HS DMA is enabled, the entire PCD_HandleTypeDef must be located in a DMA-accessible SRAM region.
This prevents developers from keeping the handle itself in faster memory (e.g. DTCM) while only placing the setup buffer in SRAM.
It reduces flexibility and forces a performance compromise.
The setup buffer should be separated from the handle:
PCD_HandleTypeDef should only store a pointer to the setup buffer.
The actual buffer can then be allocated by the user in a proper memory region (DMA-accessible SRAM).
For example:
uint32_t *Setup; /*!< Pointer to setup packet buffer */
This would make memory placement more flexible:
Developers can keep the handle in DTCM for fast CPU access.
Only the setup buffer needs to be placed in SRAM for DMA.
The current workaround is to move the entire handle into SRAM, but this is suboptimal because most fields in the handle do not require DMA access.