cancel
Showing results for 
Search instead for 
Did you mean: 

Riverdi SDMMC1 FR_NOT_READY error

efe_electronica
Associate II

 I am encountering the FR_NOT_READY and FR_INVALID_OBJECT error when trying to mount the SD card and write a file in RVT101HVSFWCA0 Riverdi display. Could you please advise on how to resolve these issues?

7 REPLIES 7

Have you asked Riverdi ?

https://riverdi.com/contact 

SofLit
ST Employee

Hello,

According to the examples provided under https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H745I-DISCO/Applications/FatFs/FatFs_Shared_Device/CM7/Src/main.c

I don't see that you linked the driver using  FATFS_LinkDriver().

 

  if(FATFS_LinkDriver(&MMC_Driver, MMCPath) == 0)
  {
    /* ..... Some code before */
    FS_FileOperations();
  }
}

static void FS_FileOperations(void)
{
  FRESULT res;
  uint32_t byteswritten, bytesread;

  /* Register the file system object to the FatFs module */
  if(f_mount(&MMCFatFs, (TCHAR const*)MMCPath, 0) != FR_OK)
  {
    goto error;
  }
 /* Some code after ... */

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I reviewed the example you provided and corrected my code. The MX_FATFS_Init() function is executed before the StartCARDTask() function. Now I can mount the SD card but I still have the same error when using f_open() or f_write ().

efe_electronica_0-1726500500124.png

efe_electronica_2-1726500889060.png

 

 

Hello,

Please use </> button to show your code instead of sharing a screenshots of it.

What errors you get for these APIs?

What if you use the same example (as it is) from what I posted and adapt it to your Hardware (clocks+IOs)? do you get the same behavior?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

This is my code, I also tried your example and reconfigured the hardware but I still have the same error

 

uint8_t retSD;    /* Return value for SD */
char SDPath[4];   /* SD logical drive path */
FATFS SDFatFS;    /* File system object for SD logical drive */
FIL SDFile;       /* File object for SD */

/* USER CODE BEGIN Variables */

/* USER CODE END Variables */

void MX_FATFS_Init(void)
{
  /*## FatFS: Link the SD driver ###########################*/
  retSD = FATFS_LinkDriver(&SD_Driver, SDPath);

  /* USER CODE BEGIN Init */
  StartCARDTask();
  /* USER CODE END Init */
}
Disk_drvTypeDef disk = {{0},{0},{0},0};
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Links a compatible diskio driver/lun id and increments the number of active
  *         linked drivers.
  * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits.
  * @PAram  drv: pointer to the disk IO Driver structure
  * @PAram  path: pointer to the logical drive path
  * @PAram  lun : only used for USB Key Disk to add multi-lun management
            else the parameter must be equal to 0
  * @retval Returns 0 in case of success, otherwise 1.
  */
uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)
{
  uint8_t ret = 1;
  uint8_t DiskNum = 0;

  if(disk.nbr < _VOLUMES)
  {
    disk.is_initialized[disk.nbr] = 0;
    disk.drv[disk.nbr] = drv;
    disk.lun[disk.nbr] = lun;
    DiskNum = disk.nbr++;
    path[0] = DiskNum + '0';
    path[1] = ':';
    path[2] = '/';
    path[3] = 0;
    ret = 0;
  }

  return ret;
}

/**
  * @brief  Links a compatible diskio driver and increments the number of active
  *         linked drivers.
  * @note   The number of linked drivers (volumes) is up to 10 due to FatFs limits
  * @PAram  drv: pointer to the disk IO Driver structure
  * @PAram  path: pointer to the logical drive path
  * @retval Returns 0 in case of success, otherwise 1.
  */
uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path)
{
  return FATFS_LinkDriverEx(drv, path, 0);
}

/**
  * @brief  Unlinks a diskio driver and decrements the number of active linked
  *         drivers.
  * @PAram  path: pointer to the logical drive path
  * @PAram  lun : not used
  * @retval Returns 0 in case of success, otherwise 1.
  */
uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun)
{
  uint8_t DiskNum = 0;
  uint8_t ret = 1;

  if(disk.nbr >= 1)
  {
    DiskNum = path[0] - '0';
    if(disk.drv[DiskNum] != 0)
    {
      disk.drv[DiskNum] = 0;
      disk.lun[DiskNum] = 0;
      disk.nbr--;
      ret = 0;
    }
  }

  return ret;
}

/**
  * @brief  Unlinks a diskio driver and decrements the number of active linked
  *         drivers.
  * @PAram  path: pointer to the logical drive path
  * @retval Returns 0 in case of success, otherwise 1.
  */
uint8_t FATFS_UnLinkDriver(char *path)
{
  return FATFS_UnLinkDriverEx(path, 0);
}

/**
  * @brief  Gets number of linked drivers to the FatFs module.
  * @PAram  None
  * @retval Number of attached drivers.
  */
uint8_t FATFS_GetAttachedDriversNbr(void)
{
  return disk.nbr;
}
void StartCARDTask(void)
{
	for (;;)
	{
		MX_SDMMC1_SD_Init();
		HAL_SD_MspInit(&hsd1);
		HAL_SD_MspDeInit(&hsd1);
		osDelay (1);
		// Montar el sistema de archivos
		res = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
		if (res == FR_OK)
		{
			printf("Tarjeta SD montada correctamente en la unidad '0:'.\n");
			res = f_open(&SDFile, "prueba", FA_CREATE_ALWAYS | FA_WRITE);
			if (res == FR_OK)
			{
				// Escribir datos en el archivo
				res = f_write(&SDFile, "Hola, Mundo!", 12, &bw);
				if (res == FR_OK && bw == 12)
				{
					printf("Archivo creado y escrito correctamente.\n");
				}
				else
				{
					printf("Error al escribir en el archivo.\n");
				}
				f_close(&SDFile);
			}
			else
			{
				printf("Error al abrir el archivo.\n");
			}
		}
		else
		{
			printf("Error al montar la tarjeta SD. Código: %d\n", res);
		}
		f_mount(NULL, "", 1);

		// Terminar la tarea
		osThreadTerminate(NULL);
	}
	osDelay (10000) ;
}

 

 

If you tried the example as it is and didn't work, you need to check your SD card: it could be corrupted or not compatible.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I am using a type 10 SD card (10MB/s), which one do you recommend?