AnsweredAssumed Answered

Why can I not get past f_open with SD card

Question asked by greenwood.greg on Mar 5, 2018
Latest reply on Mar 19, 2018 by Alexander Wolf

I am working with STM32F746G-Disco board to prove out the use of the SD card.  I am at a point where I cannot get the code to write data to the card using the fs calls.  First, I have setup the board in CubeMX with all the peripherals for the disco board initialized although I am only working with the FATfs, SD card and the screen for debug. The Cube project file is attached.  The code is working up to the point where f_open is called but f_open does not seem to return.  The code looks like this:


  sdres = BSP_SD_Init();
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 94, (uint8_t *)"SD Init status Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 94, (uint8_t *)"SD Init status Fail", LEFT_MODE);


  sdres = f_mount(&sdFatfs, "", 0);
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD mount Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD mount Failed", LEFT_MODE);


  sdres = f_open(&sdFile, "test.txt", FA_OPEN_ALWAYS|FA_WRITE|FA_READ);
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD open Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD open Failed", LEFT_MODE);


  sdres = f_lseek(&sdFile, sizeof(&sdFile));
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD seek Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD seek Failed", LEFT_MODE);


  sdres = f_printf(&sdFile, "%s", buffSDwr);
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD print Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD print Failed", LEFT_MODE);


  sdres = f_close(&sdFile);
  if (sdres == FR_OK) BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD close Pass", LEFT_MODE);
  else BSP_LCD_DisplayStringAt(0, 124, (uint8_t *)"SD close Failed", LEFT_MODE);


The sdFile, sdFatfs, sdres, and buff... variables are all global to main.c being declared in the USER PV area.

When this runs, the LCD screen prints

SD Init status Pass

SD mount Pass


after which nothing else appears.  It is also interesting to note that if I set break points at the f_open call and just after the call, the debugger stops at f_open but when I click run to go to the next break point the execution pointer simply stops at the f_open call again.  ODD!  If i place the cursor a couple of lines down and select run to cursor, the same thing happens.  If I try to step over the f_open line the debugger ends up at the first instruction in the tick handler.  I have exhausted all the posts, youtube tutorials, and blogs and nothing has settled the issue.