cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L462 FATFS+FREERTOS+DMA disk_ioctl causes Hard fault interrupt

SYako
Associate III

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

6 REPLIES 6
SYako
Associate III

Small update: right now f_open return FR_NOT_READY

Looks like freertos is not initializing sdcard

SYako
Associate III

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

SYako
Associate III

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

SYako
Associate III

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 );

SYako
Associate III

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

kgai
Associate III

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.​