0 Replies Latest reply on Feb 22, 2017 9:18 AM by Anna

    FR_NO_FILESYSTEM ,FatFs,4-pins SDcard with Nucleo-L476RG

    Anna

      Hey all,

      I want to write to SD card, I'm Using cube-mx stm32 Nucleo-L476RG MCU ,and 4-pin SD card, 

      I attach my cube project, the main program has the following code:

       

      declaring and init :

      FATFS SDFatFs;
      FIL MyFile;
      extern char SD_Path[4]; /* SD logical drive path */
      /* USER CODE END 0 */

      int main(void)
      {

      /* USER CODE BEGIN 1 */
      FRESULT res;
      uint32_t byteswriten,byteread;
      uint8_t wtext[]="Hello from STM32!!\0";
      /* USER CODE END 1 */

      /* MCU Configuration----------------------------------------------------------*/

      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();

      /* Configure the system clock */
      SystemClock_Config();

      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_DMA_Init();
      MX_DFSDM1_Init();
      MX_SDMMC1_SD_Init();
      MX_FATFS_Init();
      MX_TIM6_Init();

      MX_SDMMC1_SD_Init();

       

       

       

      I am trying to write to sd card by the following code:

       

      if(res=f_mount(&SDFatFs,(TCHAR const*)SD_Path,0)!=FR_OK)
      {
      Error_Handler();
      }
      else
      {

      if(res=f_open(&MyFile,"0:/mywrite.txt",FA_CREATE_ALWAYS | FA_WRITE ) != FR_OK)
      {
      Error_Handler();
      }
      else
      {
      res=f_write(&MyFile,wtext,sizeof(wtext),(void*)&byteswriten);
      if((byteswriten==0) || (res!=FR_OK))
      {
      Error_Handler();
      }
      else
      {
      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
      }

      f_close(&MyFile);
      }
      }

      I get FR_NO_FILESYSTEM if the SD is connected and if the SD is not connected, I get FR_NOT_READY,

      Thanks for any help.