cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 USB DMA CDC does not work properly.

Yaroslav1
Associate II

Hi everyone. I have an issue with USB transmission in DMA mode (USB_OTG_HS, internal PHY, FullSpeed 12MBit/s). I am using a Cube generated project for STM32H743IGT6. If I disable DMA - it works fine. 

But when I enable DMA USB enumerates on PC and all is ok, at first look. Data receives and transmits. But if I start to transmit data to PC, it transmits until the total quantity reaches 313 WORDS. If I send by one byte, it makes 313 sends and after that CDC_Transmit_HS doesn't send anything and the interface is in TX state. If I send by two bytes it makes the same 313 packages (626 bytes total). If I send 1252 bytes - it sends, but after that I can't send anything. I am using FreeRtos and all memory allocated in SRAM1-SRAM2 domain (0x30000000) and MPU unit sets as:

 MPU_InitStruct.Enable = MPU_REGION_ENABLE;

 MPU_InitStruct.Number = MPU_REGION_NUMBER3;

 MPU_InitStruct.BaseAddress = 0x30000000;

 MPU_InitStruct.Size = MPU_REGION_SIZE_256KB;

 MPU_InitStruct.SubRegionDisable = 0x0;

 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;

 MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;

 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;

 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;

 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;

 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

I try to totally disable cache and MPU by commend call of  MPU_Config and SCB_EnableDCache - no effect, same issue.

1 REPLY 1
Yaroslav1
Associate II

Found solution on this forum https://www.armbbs.cn/forum.php?mod=viewthread&tid=109916 and it works for me. You need to tune values of FIFO size in USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev):

HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x80);