Skip to main content
Visitor II
June 23, 2021
Solved

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

  • June 23, 2021
  • 2 replies
  • 2232 views

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!

    This topic has been closed for replies.
    Best answer by Emilmart

    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 !

    2 replies

    Graduate II
    June 23, 2021

    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.

    EmilmartAuthorAnswer
    Visitor II
    June 24, 2021

    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 !

    Graduate II
    December 4, 2024

    Did you ever find a good example? 

    How did you raise priority of the SDMMC, Mine is locked to >=5

     

    Explorer II
    September 2, 2024

    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.