2020-11-23 03:24 AM
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
2020-11-23 03:26 AM
Small update: right now f_open return FR_NOT_READY
Looks like freertos is not initializing sdcard
2020-11-23 04:52 AM
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
2020-11-23 06:00 AM
Even more debug: SD_read from sd_diskio.c. Where status = osMessageQueueGet(SDQueueID, (void *)&event, NULL, SD_TIMEOUT); is called which returns osErrorTimeout.
2020-11-23 08:06 AM
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 );
2020-11-23 08:43 AM
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
2020-11-30 07:14 PM
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.