cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F1(STM32F103RCT6) Stm32CubeIDE fatfs sdio sdcard always returns FR_DISK_ERR

RKim.1
Associate II

Hello.

I've tried to test sdcard with fatfs on STM32F103RCT6.

I don't have a compleat 100% sure hardware or software, so I'm struggling to debug if its a software or hardware issue.

I've read trough some topics hear, one with issue with https://community.st.com/s/question/0D50X00009XkWceSAF/stm32f411re-stm32cube-fatfs-sdio-sdcard-always-returns-frdiskerr

I tried to set DMA along the link, but SDIO_RX and SDIO_TX were not found.

0693W00000FCVefQAH.png

Also, I couldn't find the 'Use dma template' item in FATFS settings.

0693W00000FCVjfQAH.png

I've generated the code from Stm32CubeIDE, and added a custom code:

int main(void)
{
  /* USER CODE BEGIN 1 */
	  FRESULT res;                                          /* FatFs function common result code */
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SDIO_SD_Init();
  MX_USART1_UART_Init();
  MX_FATFS_Init();
  MX_ADC1_Init();
  MX_USART2_UART_Init();
  /* USER CODE BEGIN 2 */
 
 
	RetargetInit(&huart1);
	printf("start test...\n");
 
	res = f_mount(&SDFatFS , &SDPath[0], 1);
//	if(res == FR_OK)
//		while(1);
 
	if(res == FR_OK)
		printf("mount ok! SDPath:%s\n", SDPath);
	else
		printf("mount fail:%d\n", res);
 
	res = f_mkdir("0:/abc");
//			if((res != FR_OK) && (res != FR_EXIST))
//				while(1);
	if(res != FR_OK)
	{
		printf("mkdir dir fail:%d\n", res);
	}
	else
	{
		printf("mkdir dir ok!\n");
	}
 
	res = f_mkdir("abc");
	if(res != FR_OK)
	{
		printf("mkdir dir fail:%d\n", res);
	}
	else
	{
		printf("mkdir dir ok!\n");
	}
 
	res = f_open(&SDFile, "LOG.TXT", FA_CREATE_ALWAYS | FA_WRITE);
	if(res != FR_OK)
	{
		printf("LOG.TXT open fail:%d\n", res);
	}
	else
	{
 
		printf("LOG.TXT open ok!\n");
	}
 
	res = f_open(&SDFile, "0:/LOG.TXT", FA_CREATE_ALWAYS | FA_WRITE);
	if(res != FR_OK)
	{
		printf("LOG.TXT open fail:%d\n", res);
	}
	else
	{
 
		printf("LOG.TXT open ok!\n");
	}
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

FR_DISK_ERR starts from the f_mount function.

The program environment is as follows.

  1. STM32CubeIDE - Version: 1.6.1
  2. STM32CubeMX - Version: 6.1.2
  3. See Attachment

Am i forgetting about something?

Please let me know the answer of this question.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @RKim.1​ 

In our F1 Firmware package, we provide examples without ioc files.

Otherwise, take a look at this training that Starts project from STM32CubeMX. This should help you.

BeST Regards,

Walid

View solution in original post

7 REPLIES 7

Hello @RKim.1​ ,

Can you try to port the following example provided under our F1 Firmware Package to your board :

  • Path : Firmware\Projects\STM3210C_EVAL\Applications\FatFs\FatFs_uSD

Please let me know if this example works for you. otherwise, it could be a hardware problem.

BeST regards,

Walid

Hello @RKim.1​ 

Did you try what I suggested?

Please click on Select as Best if my post fully answered your question. This will help other customers with the same issue to find the solution faster!

BeST Regards,

Walid

RKim.1
Associate II

I've reviewed your answer.

I reviewed the Firmware\Projects\STM3210C_EVAL\Applications\FatFs\FatFs_uSD file,

but I don't know how to apply it in STM32CubeIDE or STM32CubeMX.

Is there any way to apply it from STM32CubeIDE's .ioc or STM32CubeMX?

Hello @RKim.1​ 

In our F1 Firmware package, we provide examples without ioc files.

Otherwise, take a look at this training that Starts project from STM32CubeMX. This should help you.

BeST Regards,

Walid

RKim.1
Associate II

Thanks @Walid ZRELLI​  for the reply.

The STM32F7 series in the video you linked can set both RX and TX DMA settings,

0693W00000FE2EmQAL.png

But the STM32F1 series cannot settings.

0693W00000FCVpxQAH.png

Is it impossible to set DMA RX, TX in the .ioc file for STM32F1 series?

Is there no other way?

I would very much appreciate it if you confirm this question.

Best regards,

Robert

Hello @RKim.1​ 

This is normal because as mentioned in the reference manual SDIO DMA settings can only be configured on DMA2 Channel4 with peripheral to memory direction.

You can refer to the Reference manual.

BeST Regards,

Walid

Hello. @Walid ZRELLI​ 

  1. Are there any problems with reading and writing the SD card if it is configured in peripheral to memory direction only?
  2. Use dma template settings is no exists at STM32F1 series. Is it set automatically in STM32F1 series?0693W00000FE32SQAT.png0693W00000FCVjfQAH.png
  3. SD card does not work in STM32F1 series if this is set. Are there any problems with these settings?

BeST Regard​s,

Robert