cancel
Showing results for 
Search instead for 
Did you mean: 

USB_OTG_HS Mass storage using internal DMA does not work

DmRozhd
Associate III

Hi all,

I am implementing Mass Storage class device with USB_OTG_HS. The implementation is configured from CubeMX and works perfectly until I enable USB_OTG_HS internal DMA. As soon I do this everythig stops, and no functions from usbd_storage_if.c are called anymore. Along with that there are no calls to Error_Handler().

Regards,

Dmitry

2 REPLIES 2
chaaalyy
Senior II

Hi :) I can´t really help you, i´m also stuck somewhere with USB_MSC device on a F746 Disco board... So i´m also very interested in your findings, could you provide further informations, how you configured your project in cubeMX and which additional code you needed ?

When i tracked down my own problems, it seemed to be FreeRTOS related because of some bad bugs in cubeIDE.

DmRozhd
Associate III

First of all, I am using STM32H753. The question is that USB DMA was only introduced in the latest silicon revision V. So the HAL code serving internal USB DMA may be relatively new and thus contain bugs, as work with DMA has some challenges on latest CPUs. Particularly, between any CPU and DMA access to the buffer CPU cache should be invalidated (in a case when DMA has written the buffer, and CPU intends to read) or cleaned (in the case CPU writes - DMA reads). Consequently, the buffer must be cache line (32-bytes) aligned.

As to additional code, it is very simple. I have just added a few lines in usbd_storage_if.c:

  • in the init function - configure 4-bit access with auto speed to SD card;
  • in the detect size function - return of SD card block size and block count;
  • in the block read and write functions - calls to polling SD block read and write.

Despite simplicity, it works relatively fast: 24MB/s write and 7MB/s read. To achieve that, message size for the USB device should be configured to 32768 (default is 512, and it makes everything very slow, as SD card is not intended to be read by a single block). Also, do care interrupt priorities (and of course do not forget to switch them on).

Then I have written some code to read ahead the next SD card block pool with DMA right upon the exit from the USB block read callback, that raised read speed to 10MB/s. It was tricky as the buffer of the USB callback is not cache line aligned. At this point I do not want to invest much more time in raising interface speed and switched to code other parts of the project. But from my point of view just having USB DMA on could help, thus I have asked this question as a background task (while I have severe difficulties with FIDO U2F HID interface).