cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault Error in HAL_SD_Init()

MGuth.1
Associate III

Hi all

I'm struggling for a while getting a µSD Card to run via SDMMC on FileX. I'm using a Nucleo U575 Board with an external SDMMC/SDIO-breakout board. I tried to follow the "Fx_uSD_File_Edit" example for the U575I-EV board.
Long story short, I set up a FileX application thread on ThreadX and I'm trying to just open the media.

In main.c there's the automatically generated MX_SDMMC1_SD_Init() initializing the the SDMMC1 interface just after GPIOs and ICACHE were initialized. In main.c everything runs through without any error.
However, when entering the FileX application, the very first function getting called is MX_SDMMC1_SD_Init() again - as I configured FileX to initialize the SD IP (just as seen in the Fx_uSD_File_Edit-example). This time it ends in a HardFault in the Init. The one thing that I really don't understand is that it happens just on the call of 

  sdmmc_clk = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SDMMC);

in stm32u5xx_hal_sd.c

I enabled a breakpoint on the very first line of HAL_RCCEx_GetPeriphCLKFreq. The first time (called from inside main.c) it runs through flawlessly as stated above. But on the second call (from fx_stm32_sd_driver_glue.c) it doesn't even stop at the breakpoint but just going to a HardFault.

Can anyone explain this problem or try to give me a hint on how to fix this issue?

Best
M

6 REPLIES 6
Saket_Om
ST Employee

Hello @MGuth.1 

Please refer to article How to use FileX with eMMC for file system management for detailed steps to set your project. 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Hi Omar

Thanks for your answer and the attached How-to. I sticked to the guide as good as possible, choosing the SDMMC interface instead of the MMC interface. Also I didn't use LevelX as it doesn't have an option for SDMMC (or should I choose for NAND here?).

However, I'm still getting a HardFault when trying to open the media through

fx_media_open()
[...] -->
(media_ptr -> fx_media_driver_entry) (media_ptr)
[...] --> 
if (SDMMC_GetCommandResponse())

. Again I'm jumping to the HardFault Handler just when calling the SDMMC_GetCommandResponse() without any hint on the reason...
Any guesses what could be the reason for the failure?

 

Thanks in advance.

MGuth.1
Associate III

unbenannt.jpgThis is the point where the HardFault occurs. With the data given on the right (collapsed structures only hold zeros), hitting "Step Into" it goes directly into the Hard Fault.

SDMMC_GetCommandResponse just returns SDMMCx-->RESPCMD which equals SD_CMD. So the if-statement in line 1395 should be skipped and the programm should continue at line 1401. But when setting a breakpoint on 1401, it goes to the HardFault just as said above.
Does this help to narrow down the problem in any way?

Hello @MGuth.1 

Could you try to communicate with uSD directly with HAL and without FileX please?

You can refer to this example Projects/STM32U575I-EV/Examples/SD/SD_ReadWrite_DMALinkedList.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar
MGuth.1
Associate III

Hi @Saket_Om 

Thanks for your continuous input and help.

I just downloaded the example you linked to. I loaded it to my Nucleo U575 board without touching the external SD-breakout board (same connection as for the initial program). The example runs through without any problems. When inserting the µSD Card to my Computer afterwards I see it was formatted - or at least renamed.
So the basis, HAL-interface, seems to be working just fine. I assume this narrows the problem down to a configuration issue for FileX ?!

Hello @MGuth.1 

Please try adding fileX and check if it works. Once it does, try adding ThreadX.

Please look to this example as reference "Projects/STM32U575I-EV/Applications/FileX/Fx_File_Edit_Standalone"

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar