Skip to main content
Forest L
Associate II
Jul 13, 2018 2:44 PM UTC
Question

f_mount fails using STM32L4 w/ SDMMC

Posted on July 13, 2018 at 16:44

I'm having a lot of difficulty getting FatFS working with SDMMC on my STM32L476 (RG-Nucleo) board. I'm working from code generated by CubeMX and have followed a number of forum posts suggesting alterations to get SDMMC working -- for instance, 

https://community.st.com/message/203639-sdmmc-on-stm32-l476-l4

 . Currently I'm getting an infinite loop when calling f_mount which I can trace back to

stm32l4xx_hal_sd.c:

while(!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DBCKEND))

{

This loop goes on infinitely -- it seems none of these flags are being set? What are some likely causes of this problem?

#hal #sdmmc #f_mount #stm32l4+ #fatfs
This topic has been closed for replies.

16 replies

Forest L
Forest LAuthor
Associate II
Aug 2, 2018 5:48 PM UTC

Sorry, where/how would I 'dump' the block contents?

By the way, I'm attempting to use DMA, and realize now that there are two interrupts attached to the SDMMC interface -- can this cause problems if they're not correctly configured and are maybe overlapping?

void SDMMC1_IRQHandler(void)

void DMA2_Channel4_IRQHandler(void)

Tesla DeLorean
Guru
Aug 2, 2018 6:34 PM UTC

You'd instrument the disk_read and/or disk_write functions to call dumping routines that show you what's in the memory buffer.

0690X0000060QuCQAU.jpg

STM32Cube_FW_L4_V1.11.0\Projects\STM32L476G-EVAL\Applications\FatFs\FatFs_uSD_DMA_RTOS\Src\stm32l4xx_it.c

void SDMMC1_IRQHandler(void)
{
 HAL_SD_IRQHandler(&hsd_eval);
}
 
void DMA2_Channel4_IRQHandler(void)
{
 if((hsd_eval.Context == (SD_CONTEXT_DMA | SD_CONTEXT_READ_SINGLE_BLOCK)) ||
 (hsd_eval.Context == (SD_CONTEXT_DMA | SD_CONTEXT_READ_MULTIPLE_BLOCK)))
 {
 BSP_SD_DMA_Rx_IRQHandler();
 }
 else if((hsd_eval.Context == (SD_CONTEXT_DMA | SD_CONTEXT_WRITE_SINGLE_BLOCK)) ||
 (hsd_eval.Context == (SD_CONTEXT_DMA | SD_CONTEXT_WRITE_MULTIPLE_BLOCK)))
 {
 BSP_SD_DMA_Tx_IRQHandler();
 }
}

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Forest L
Forest LAuthor
Associate II
Aug 2, 2018 8:14 PM UTC

Sorry if I'm just being an idiot. Looking at this and related problems has fried my brain.

I'm trying to print the buffer like this inside f_write():

 	 	while (*buff){
 	 		msglen = snprintf(msgBuf, 255, "%02X/%c ",(unsigned int) *buff,(char) *buff);
 	 		buff++;
			serialDisplay(msgBuf,msglen);
 	 	}

for any write occurrence whether or not it fails. This just gives me the same value out, 'B'. What am I missing?