2024-05-08 04:40 AM
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.
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!
2024-05-08 08:47 AM
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.
2024-05-09 12:33 AM
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.
2024-05-09 05:48 AM
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.
2024-05-09 05:55 AM - edited 2024-05-09 05:57 AM
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.
2024-05-09 06:16 AM
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!
2024-05-09 06:27 AM - edited 2024-05-09 06:34 AM
I have completed all the settings in CubeMX. The table below shows the interrupt priorities.
Please tell me how to correctly set interrupt priorities?
2024-05-14 06:00 AM
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 */
}