cancel
Showing results for 
Search instead for 
Did you mean: 

f_open not working in stm32f4 with FATFS

Rsrma.1
Associate III

I'm using STM32F4 Discovery board and its expansion board for SD-card interfacing. I'm using SD-cards with DMA2 and STM32CUBEIDE FW_F4 V1.24.2

Before pointing out error I want to attach below link as a reference which I've used in my code -

https://community.st.com/s/feed/0D50X00009bMM8bSAG?t=1598702550733

I tried to interface a SDcard but at f_open instruction system goes to SD_FindSCR() function in stm32f4xx_hal_sd.c and stuck there in a infinite loop.

The image for my stack is as below:

0693W000002lhz4QAA.png

My initialization code is as follows:

int main
{
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SDIO_SD_Init();
  MX_FATFS_Init();
  init_task();
 
 while (1)
  {
   
  }
}
 
void init_task()
{
  /* init code for FATFS */
	uint8_t uc_status;
 
  /* USER CODE BEGIN 5 */
	  MX_FATFS_Init();
	  initialize_sd(&uc_status);
 
uint8_t sd_state = BSP_SD_Init();
	uint8_t file_state;
	if(sd_state != MSD_OK)
	{
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
		*uc_status= sd_state;
		return;
	}
	file_state = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
	if(file_state != FR_OK)
	{
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
		*uc_status=file_state;
	}
 
	file_state = f_open(&SDFile, "sd20.log", FA_WRITE | FA_CREATE_ALWAYS);
	if (file_state != FR_OK)
	{
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
		*uc_status=file_state;
	}
}
static void MX_SDIO_SD_Init(void)
{
  hsd.Instance = SDIO;
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 0;
}
static void MX_DMA_Init(void) 
{
  __HAL_RCC_DMA2_CLK_ENABLE();
 
  /* DMA2_Stream3_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA2_Stream3_IRQn);
 
  /* DMA2_Stream6_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
}

0 REPLIES 0