STM32H7 SDMMC Removal and reinsertion crashes
Hi,
I'm having some issues regarding removing and reinserting an SD card on the STM32H722 using the provided HAL. I'm not doing anything special (no DMA, no interrupt). Just using the provided SDMMC1 and FATFS.
First, I noticed that the library won't initialise an SD card if it's not present the first time disk_initialize is called (f_mount -> find_volume). I fixed this by only setting the initialised flag to 1 if the disk actually initialised. I also added an uninitialise function (to be called if check_fs returns 4 (FR_DISK_ERR).
I've successfully used this same fix on a couple of other projects (using STM32F7 and STM32L4).
However, something is causing the stack to get trashed if the SD card is removed and reinserted.
I tracked this down to SD_SendSDStatus, where *pData is incremented beyond the 16bytes allocated to it. I've added a hotfix to stop this pointer behaviour, but I can't figure out how and why this is happening.
I can't get beyond this, so I'm a bit stuck. I know it's possible to recover somehow, as resetting my debug session brings the SD card back.
Any ideas as to what I'm missing??
Thanks in advance
-- EDIT --
SD_SendSDStatus fails due DCRCFAIL (every time it fails, but I only see this if I remove and reinsert the SD card)
