STMicroelectronics / STM32CubeH7

STM32Cube MCU Full Package for the STM32H7 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
https://www.st.com/en/embedded-software/stm32cubeh7.html
Other
518 stars 308 forks source link

H743IIT6 USB DMA and Dcache working together produce anomalies #298

Open andy817501 opened 1 month ago

andy817501 commented 1 month ago

Describe the set-up

Additional context when i used the usb_host and opened the dma and dcache, the usb cannot work I have divided the memory area used by USB DMA into RAM-D2,I have configured R2 MPU_ACCESS_NOT_BUFFERABLE , MPU_ACCESS_NOT_CACHEABLE , MPU_ACCESS_NOT_SHAREABLE and MPU_TEX_LEVEL1 and when I turn off DCAHCE, USB host and dma can be used normally,or I can use SCB->CACR |= SCB_CACR_FORCEWT_Msk And use __DSB() in the HAL_SCD_ShenfyURBChange_Callback function; It can also be used, but I'm not sure if it will affect performance. Is there any way not to turn off dcache and not to use SCB->CACR |= SCB_CACR_FORCEWT_Msk for dcache.

andy817501 commented 1 month ago

But I use USB_OTG_FS dma enable=ENABLE and turn on dcache to make it work as a cdc device, It can work normally,I don't need to turn off dcache or use SCB->CACR |= SCB_CACR_FORCEWT_Msk, but usb_host can not work , i find when i open the dcache and dma in usb host I do get 2-5 trasnfers through, and then it stalls.

ALABSTM commented 1 month ago

Hi @andy817501,

From your setup description, I see ThreadX and USBX. Are you trying to port these libraries to the STM32CubeH7 firmware? If yes, you can have a look to the x-cube-azrtos-h7 repository. You may find the answer to your question by browsing into the different applications available.

Please keep me informed.

With regards,

andy817501 commented 1 month ago

@ALABSTM I discovered after porting that USB_cdc_host DMA and Dcache are working together to produce anomalies,but the usb_cdc_device is no such issue

ALABSTM commented 1 month ago

Hi @andy817501,

Have you had a look at the x-cube-azrtos-h7 repository?

With regards,

andy817501 commented 1 month ago

yes,i had a look at the x-cube-azrtos-h7 repository , and make sure The DTCM (0x20000000) memory region do not be used ,and make sure to configure the USB pool memory region with attribute "Non-Cacheable" to ensure coherency between CPU and USB DMA

andy817501 commented 1 month ago

for Ux_Device_CDC_ACM , I Can use the dache + dma work together , But for Ux_Host_CDC_ACM i can not ,I have already provided detailed information before

ALABSTM commented 1 month ago

ST Internal Reference: 193167

ALABSTM commented 1 month ago

Hi @andy817501,

I forwarded your question to our development teams. Let's wait for their feedback.

With regards,

ALABSTM commented 1 month ago

See also STM32CubeF7#8

andy817501 commented 1 month ago

I had look this issue, but it only Mentioning the closure of dache,and use not cacheable Memory ,for the closure of dache i think it is unacceptable , for not cacheable Memory ,i had use it,But there will still be problems, We look forward to your reply

andy817501 commented 3 weeks ago

HI! @ALABSTM Tell me if you need any help or further information.

ALABSTM commented 2 weeks ago

Hi @andy817501,

You mentioned configuring a memory region to be not cacheable. Did you ensure that your USB buffers are also in this non-cacheable region? Should I understand you did, when reading the sentence "make sure to configure the USB pool memory region with attribute "Non-Cacheable""?

If needed, you can refer to the provided USB examples showing how to configure the MPU, as in the code snippet below:

https://github.com/STMicroelectronics/STM32CubeH7/blob/d0e2e3886ee013b56082e57f48ae9bc6c34c849a/Projects/STM32H743I-EVAL/Applications/USB_Host/CDC_Standalone/Src/main.c#L288-L343

Please let me know whether it helps.

With regards,

andy817501 commented 2 weeks ago

yes, I Configure the MPU attributes as Normal Non Cacheable for RAM_D2,and use RAM_D2 as the usb_cdc_device's dma buffers is permissible,but I can not use the usb_cdc_host with dma