cancel
Showing results for 
Search instead for 
Did you mean: 

I try to use STM32F103RET6 to read a TF card. Report Disk Error

Mcai.1
Associate

 I build the whole program by the IDE.

Following is my code. I can read the CID of the card without select the fatfs middleware. The program report FR_DISK_ERR in f_open. The f_mount works fine.

int main(void)
 
{
 
 /* USER CODE BEGIN 1 */
 
 
 
 /* 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_RTC_Init();
 
 MX_USART1_UART_Init();
 
 MX_ADC1_Init();
 
 MX_SPI1_Init();
 
 MX_SPI2_Init();
 
 MX_USART2_UART_Init();
 
 MX_SDIO_SD_Init();
 
 MX_TIM1_Init();
 
 MX_USB_DEVICE_Init();
 
 MX_FATFS_Init();
 
 /* USER CODE BEGIN 2 */
 
 
 
 printf("\r\n ****** FatFs Example ****** \r\n\r\n");
 
 
 
 /*##-1- Register the file system object to the FatFs module ##############*/
 
 retSD = f_mount(&SDFatFS, "", 0);
 
 
 
 if(retSD){
 
	printf(" mount error : %d \r\n",retSD);
 
	Error_Handler();
 
 }
 
 else
 
	printf(" mount sucess!!! \r\n");
 
 uint8_t a[1024];
 
 printf("HAL_SD_InitCard %d\r\n",HAL_SD_InitCard(&hsd));
 
 retSD = f_open(&SDFile, "C.txt", FA_CREATE_ALWAYS | FA_WRITE);
 
 if(retSD){
 
	 printf(" open file error : %d\r\n",retSD);
 
 }
 
 else{
 
	 printf(" open file sucess!!! \r\n");
 
 }
 
 /* USER CODE END 2 */
 
 
 
 /* Infinite loop */
 
 /* USER CODE BEGIN WHILE */
 
  while (1)
 
  {
 
  /* USER CODE END WHILE */
 
	  retSD = f_open(&SDFile, "C.txt", FA_CREATE_ALWAYS | FA_WRITE);
 
	  if(retSD){
 
	 	 printf(" open file error : %d\r\n",retSD);
 
	  }
 
	  else{
 
	 	 printf(" open file sucess!!! \r\n");
 
	  }
 
  /* USER CODE BEGIN 3 */
 
 
 
 
 
 }
 
 /* USER CODE END 3 */
 
}

2 REPLIES 2

Hello

Line 99 causes reinitialization of SD card with default params.. no need to exist

Imen.D
ST Employee

Hello @Mcai.1​ and welcome to the STM32 Community,

Do you have still this problem to solve?

If your problem is resolved, please mark the reply as Best answer (click on "Select as Best").

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen