cancel
Showing results for 
Search instead for 
Did you mean: 

F_open looping

Chris5
Associate

Using Nucleo-H753ZI
Trying to write to SD card using:

 
  FATFS FatFs;
  FIL file;
  FRESULT FR_Status;
  FATFS *FS_Ptr;
  FR_Status = f_mount(&FatFs, SDPath, 1);
  if (FR_Status != FR_OK)
  {
	  printf("Error! While Mounting SD Card, Error Code: (%i)\r\n", FR_Status);
  }
  else{
	  printf("SD Card Mounted Successfully! \r\n\n");
  }
  static char hello_world[] ="hello world";
  UINT bytesWritten;
  if(HAL_SD_GetCardState(&hsd1) != HAL_SD_CARD_TRANSFER) {
      printf("Card not ready\n");
  }
  FR_Status = f_open(&file, "hello_world.txt", FA_WRITE | FA_CREATE_ALWAYS); //tried 0:/ and / infront of hello_world.txt
  FR_Status = f_write(&file, hello_world, sizeof(hello_world), &bytesWritten);
  FR_Status = f_close(&file);

The SDMMC peripheral is initialized in 4 bit mode and using a 20MHz clock.

Error occurs in stm32h7xx_hal_sd.c at:

It goes through the first sets of the for loops find then start going between the first if statement and the second.

    while (!__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXOVERR | SDMMC_FLAG_DCRCFAIL | SDMMC_FLAG_DTIMEOUT | SDMMC_FLAG_DATAEND))
    {
      if (__HAL_SD_GET_FLAG(hsd, SDMMC_FLAG_RXFIFOHF) && (dataremaining >= SDMMC_FIFO_SIZE))
      {
        /* Read data from SDMMC Rx FIFO */
        for (count = 0U; count < (SDMMC_FIFO_SIZE / 4U); count++)
        {
          data = SDMMC_ReadFIFO(hsd->Instance);
          *tempbuff = (uint8_t)(data & 0xFFU);
          tempbuff++;
          *tempbuff = (uint8_t)((data >> 8U) & 0xFFU);
          tempbuff++;
          *tempbuff = (uint8_t)((data >> 16U) & 0xFFU);
          tempbuff++;
          *tempbuff = (uint8_t)((data >> 24U) & 0xFFU);
          tempbuff++;
        }
        dataremaining -= SDMMC_FIFO_SIZE;
      }

      if (((HAL_GetTick() - tickstart) >=  Timeout) || (Timeout == 0U))
      {
        /* Clear all the static flags */
        __HAL_SD_CLEAR_FLAG(hsd, SDMMC_STATIC_FLAGS);
        hsd->ErrorCode |= HAL_SD_ERROR_TIMEOUT;
        hsd->State = HAL_SD_STATE_READY;
        hsd->Context = SD_CONTEXT_NONE;
        return HAL_TIMEOUT;
      }
    }

 

 

1 REPLY 1
AScha.3
Super User

So at first try with 1bit mode and start with mounting, open existing file and read.

If that's working fine, try write and then read it.

Just to reduce errors by connect and wiring. If fine, try 4bit mode, if needing the speed.

If you feel a post has answered your question, please click "Accept as Solution".