cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746 USB Device MSC DMA Problem

Alex_777
Associate III

Hi, I am using STM32F746G_DISCO, STM32 CubeMX version: 6.11.1, STM32CubeIDE version: 1.15.0 and FW_F7 firmware package V1.17.1.
I tested the project: \STM32F746GDISCOVERY\STM32Cube_FW_F7_V1.17.0\Projects\STM32746G-Discovery\Applications\USB_Device\MSC_Standalone. It works fine.

Then I create the project with CubeMX (please see the attached file). I made the settings according to the STM32F746GDISCOVERY example.

I enabled ICache and DCache, Heap Size=  0x2000, Stack Size= 2000, MSC_MEDIA_PACKET= 512.

While debugging, I noticed that there were no interrupts, and the program was hanging in a loop, as shown in the picture below.

1.png

Then I commented out the while loop and the interrupts started working. I was able to read and write data to the uSD Card. I can't understand the reason for this behavior of the program. Please tell me what am I doing wrong?

Thanks!

 

 

7 REPLIES 7
FBL
ST Employee

Hi @Alex_777 

Could you disable the caches and see if we have the same behavior? Since you are dealing with DMA transfers on CM7 it could be linked potentially to cache coherency issue.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Hi, @FBL .

Thanks for reply.

I disabled ICache and DCache, but the behavior is the same. In the MSC USB device example for STM32F746G DISCOVERY I found the following information:

@Note If the user code size exceeds the DTCM-RAM size or starts from internal cacheable memories (SRAM1 and SRAM2),that is shared between several processors,
     then it is highly recommended to enable the CPU cache and maintain its coherence at application level.
      The address and the size of cacheable buffers (shared between CPU and other masters) must be properly updated to be aligned to cache line size (32 bytes).

My user code size is only 19,54KB and it is completely in DTCM-RAM. Please see on the picture below.

2.png

 

FBL
ST Employee

Hello @Alex_777 

Based on these inputs, the behavior is not linked to cache coherency. It could be timing issue instead. Check the configuration of the USB MSC device. Ensure that it is not interfering with the SD card operations. There might be shared resources or interrupt priority that need to be addressed. 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Code is far from ideal

Needs better timeout and bounding conditions.

The second loop needs to be bounded by TIME, not ITERATIONs

Likely seeing cascading failure, where the prior command didn't complete properly, so the next doesn't start nor interrupt.

The coherency issues on the F7 can be entirely avoided if the DMA buffers live in DTCM-RAM, the code doesn't need to be there.

I'd bound the first loop by TIME to, and fail with an error, not just stop and die there.. Removing it solves no problems.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I completely agree with you that the code is far from ideal, but unfortunately, such examples are provided by the ST company. In the near future I will try to implement your comments and write about the results.

Thank you for your help!

I have completed all the settings in CubeMX. The table below shows the interrupt priorities.

3.png

Please tell me how to correctly set interrupt priorities?

Alex_777
Associate III

I did the following experiment: I implemented the read and write functions as follows

 

int8_t STORAGE_Read_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

{

/* USER CODE BEGIN 6 */

int8_t ret = -1;

 

HAL_SD_ReadBlocks(&hsd1, buf, blk_addr, blk_len, HAL_MAX_DELAY);

 

/* Wait until SD card is ready to use for new operation */

while (HAL_SD_GetCardState(&hsd1) != HAL_SD_CARD_TRANSFER){}

ret = 0;

return ret;

 

/* USER CODE END 6 */

}

 

 

int8_t STORAGE_Write_FS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len)

{

/* USER CODE BEGIN 7 */

int8_t ret = -1;

 

HAL_SD_WriteBlocks(&hsd1, buf, blk_addr, blk_len, HAL_MAX_DELAY);

 

/* Wait until SD card is ready to use for new operation */

while (HAL_SD_GetCardState(&hsd1) != HAL_SD_CARD_TRANSFER){}

ret = 0;

return ret;

 

/* USER CODE END 7 */

} 

 

1.png
When MSC_MEDIA_PACKET = 512 all works good. But when I set this parameter to 1024, disk works is not correct.
The drive appears fine in Device Manager, but when I try to open it, Windows prompts me to format it.
Formatting cannot be performed, an error occurs.
I increased the heap and stack size to 0x10000, but that didn't solve the problem.
What could be the problem?