cancel
Showing results for 
Search instead for 
Did you mean: 

SDMMC Hardfault_Handler() at HAL_SD_InitCard (STM32H7 + Fatfs + freeRTOS + DMA)

Emilmart
Senior

Hi,

I'm using an STM32H7A3ZI MCU, with freeRTOS, fatFS & DMA

I have set the SDMMC2 peripheral with 4 bit mode & DMA (by default in STM32H7 MX config). I have implemented the code from this example to test my SD card (microSDHC 32Gb, also test on 2Gb SD).

I set the example code inside a RTOS task (1024 stack size) (CubeMX detects that I use RTOS so the sd_diskio file is set for rtos with queues and so, however I didn't implement queues in the example code)

My problemen is that at the HAL_SD_InitCard part, I have and HardFault_Handler error at this line :

>>> HAL_Delay(1U + (74U * 1000U / (sdmmc_clk)));

(in stm32h7xx_hal_sd.c)

0693W00000BboY1QAJ.png 

On the hardware part I have 47k pullup on data & CMD pins, the voltage supply is OK. I try also without the 47k pullup & with internal pull up. I have set the SD clock to 12.5Mhz.

Any idea on what could cause this problem ?

You can find my full code here:

https://github.com/pa0694/IOC_SDMMC

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Tesla, thanks for your answer.

Indeed, with further investigation I notice that it comes from freeRTOS. I raised the priority of the SDMMC task and the hardfault dissapears... to now lead to a MemManage_Handler error (still using freeRTOS). I need to find a good template example with SDMMC & freeRTOS, as I'm not quite sure of my code.

But I can confirm that without freeRTOS, the SDMMC periphal is working !

View solution in original post

3 REPLIES 3

Try having a proper Hard Fault Handler, and unpacking the fault state, the registers, and the disassembly to better understand the nature of the fault.

Initial thought it might be a divide by zero, but that seems to have been checked earlier.

Perhaps the fault is not quite where you think it is due to optimization or code movement. Try turning optimization off on the routine, but more specifically look at the low level code the MCU is actually executing rather than the high level stuff.

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

Hi Tesla, thanks for your answer.

Indeed, with further investigation I notice that it comes from freeRTOS. I raised the priority of the SDMMC task and the hardfault dissapears... to now lead to a MemManage_Handler error (still using freeRTOS). I need to find a good template example with SDMMC & freeRTOS, as I'm not quite sure of my code.

But I can confirm that without freeRTOS, the SDMMC periphal is working !

Leo99
Associate III

I have a similar problem and the HAL_SD_InitCard() uses the HAL_Delay() but the SysTick is not running since RTOS is active.

The IOC configuration with RTOS and SDMMC insert the call to MX_SDMMC1_SD_Init() before the initialization of RTOS.