cancel
Showing results for 
Search instead for 
Did you mean: 

[Feedback] USB Setup buffer should be separated from PCD_HandleTypeDef structure

lconlcong
Associate II

 

Description

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.


Suggestion

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.


Current Workaround

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.

 

0 REPLIES 0