cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler on sdio + FreeRTOS

bvale.2
Associate II

Hello

I am currently developing a card where I need to write logs to an SD card, for this I use an STM32F411 + plus a home made card. First I followed the following tutorial to write on the card: 

https://controllerstech.com/interface-sd-card-with-sdio-in-stm32/

this works, but when I wanted to adapt it to use it with RTOS, I always fall in the hardFault_Handler as soon as I get to the f_stat command.

code task:

#include "fatfs.h"
#include "sdio.h"
 
extern char SDPath[4];
extern FATFS SDFatFS;
extern FIL SDFile;
 
 
void task_sd(void *pvParameters){
	printf(" ------------------ \r\n");
	printf("test carte SD \r\n\r\n");
 
	if (SD_Mount(sd) == HAL_OK){
		printf("montage reussi \r\n");
	}
	SD_CreateFile(sd, "test.txt");
	Unmount_SD(sd);
 
	while (1)
	{
		vTaskDelay(1000);
	}
	vTaskDelete(NULL);
}

function of the library:

HAL_StatusTypeDef SD_CreateFile(char *name){
	FIL	fil;
	FRESULT fresult = f_stat(name, &fno);
 
	if (fresult == FR_OK){	// file already exists
		return HAL_ERROR;
 
	}else {	// the file does not exist
		fresult = f_open(&fil, name, FA_CREATE_ALWAYS|FA_READ|FA_WRITE);
 
		if (fresult != FR_OK){	// file not created
			return HAL_ERROR;
		}
 
		fresult = f_close(&fil);
		if (fresult != FR_OK){	// file not created
			return HAL_ERROR;
		}
	}
	return HAL_OK;
}

Someone has an idea to help me?

Thank you in advance for your answer

0 REPLIES 0