Skip to main content
Visitor II
November 23, 2020
Question

STM32L462 FATFS+FREERTOS+DMA disk_ioctl causes Hard fault interrupt

  • November 23, 2020
  • 5 replies
  • 1273 views

I'm using custom board with stm32l462re with sd card.

Without freertos and dma i'm able to write/read to sd card (32MHz on sdmmc clock, 1 bit mode, 10 clock divide factor). As project grows I decided to use freertos.

But now f_open send hard fault (disk_ioctl in Middlewares/Third_Party/FatFs/src/diskio.c)

What have I tried:

setting sdmmc in 4bit mode

different clock divide factors

physically removing sd card(same error)

disk_ioctl code:

DRESULT disk_ioctl (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE cmd,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
 DRESULT res;
 
 res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
 return res;
}

My source code for testing:

/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
{
 /* USER CODE BEGIN 5 */
 /* Infinite loop */
 record_init();
 osDelay(200);
 record_start("test.raw", 10);
 for(;;)
 {
 osDelay(1);
 }
 /* USER CODE END 5 */
}
....
void record_init(void)
{
	FRESULT fresult;
	fresult = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
...
}
 
void record_start(const char *path, int seconds)
{
	FRESULT fresult;
	fresult = f_open(&SDFile, path, FA_CREATE_ALWAYS | FA_WRITE);
....
}

Current cubemx settings:

FreeRTOS set to CMSIS_V2 default

0693W000005CHCNQA4.png0693W000005CHCDQA4.png0693W000005CHC8QAO.png0693W000005CHByQAO.png0693W000005CHBoQAO.png

    This topic has been closed for replies.

    5 replies

    SYakoAuthor
    Visitor II
    November 23, 2020

    Small update: right now f_open return FR_NOT_READY

    Looks like freertos is not initializing sdcard

    SYakoAuthor
    Visitor II
    November 23, 2020

    After doing everything from scratch f_open return FR_DISK_ERR, and not triggering hard fault interrupt. Tried to adjust clock divider....Still FR_DISK_ERR

    SYakoAuthor
    Visitor II
    November 23, 2020

    Even more debug: SD_read from sd_diskio.c. Where status = osMessageQueueGet(SDQueueID, (void *)&event, NULL, SD_TIMEOUT); is called which returns osErrorTimeout.

    SYakoAuthor
    Visitor II
    November 23, 2020

    Even more debug: right now 100% sure that BSP_SD_ReadCpltCallback is called and message is sended, but freertos is stalled in vPortValidateInterruptPriority, inside configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );

    SYakoAuthor
    Visitor II
    November 23, 2020

    I was able to fix previous error by setting DMA priority to 8. By changing DMA to single SDMMC (instead of SDMMC_TX and SDMMC_RX) I'm able to open file, but I cant write to file, BSP_SD_WriteCpltCallback never occurs

    Visitor II
    December 1, 2020

    there is a bug during this situation. you have to change the DMA peripheral dynamicly to RX OR TX. this bug has not been solved by st so far.​