cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble creating a working HAL + FatFS + SDIO + DMA+ FreeRTOS solution.

Alec Davis
Associate III

0690X000008iBCsQAM.pngUsing the sample application from STM32Cube_FW_F4_V1.24.0\Projects\STM324xG_EVAL\Applications\FatFs\FatFs_uSD_RTOS\SW4STM32 and opening with TrueStudio compiles and works.

I'm unable to import the above project to STM32CubeIDE, but that's in the release notes.

However, using CubeMX 5.x or STM32CubeIDE to create a simple SDIO + FatFS + FreeRTOS doesn't work, will not write to the SD card. Remove FreeRTOS and undo the DMA changes and it will work.

What needs to be made available is an IOC file for all devices like the examples already offered in the CUBE F4 library.

Using previous SPL examples from 5 years ago also work.

The device I'm currently struggling with is an STM32F407/417, currently in a product with NO-OS but working fine and logging to SD card.

The STM32CubeIDE looks promising, but need to be able to create working code.

Edit 4th June 2019: Just added a basic project generated by CubeIDE that demonstrates that CubeIDE is unable to create a working example.

It never gets past 

if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, buffer, sizeof(buffer)) != FR_OK)

Note: in MX_SDIO_SD_Init hsd.Init.BusWide = SDIO_BUS_WIDE_1B although CubeMX had 4bwide

edit 6 June 2019

working project uploaded f4disco_sdio_dma_fatfs_rtos.zip

All that was wrong was the task stack size of 128 words was too small, changed to 256 and now works. Hope somebody finds this useful.

Question to ST, why doesn't 4b wide SDIO work????

You can set it in the Device Configuration Tool, but it still puts SDIO_BUS_WIDE_1B in MX_SDIO_SD_Init().

Adding "hsd.Init.BusWide = SDIO_BUS_WIDE_4B;" like below doesn't work!

static void MX_SDIO_SD_Init(void)
{
 
  /* USER CODE BEGIN SDIO_Init 0 */
 
  /* USER CODE END SDIO_Init 0 */
 
  /* USER CODE BEGIN SDIO_Init 1 */
 
  /* USER CODE END SDIO_Init 1 */
  hsd.Instance = SDIO;
  hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
  hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
  hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 2;
  /* USER CODE BEGIN SDIO_Init 2 */
  hsd.Init.BusWide = SDIO_BUS_WIDE_4B;
  /* USER CODE END SDIO_Init 2 */
 
}

Thanks Alec Davis

2 REPLIES 2
Alec Davis
Associate III

From Above:

Question to ST, why doesn't 4b wide SDIO work????

You can set it in the Device Configuration Tool, but it still puts SDIO_BUS_WIDE_1B in MX_SDIO_SD_Init().

Adding "hsd.Init.BusWide = SDIO_BUS_WIDE_4B;" like below doesn't work!

Doesn't it initialize the interface in 1-bit, and then switch

bsp_driver.c

/* USER CODE BEGIN BeforeInitSection */
/* can be used to modify / undefine following code or add code */
/* USER CODE END BeforeInitSection */
/**
  * @brief  Initializes the SD card device.
  * @retval SD status
  */
uint8_t BSP_SD_Init(void)
{
  uint8_t sd_state = MSD_OK;
  /* Check if the SD card is plugged in the slot */
  if (BSP_SD_IsDetected() != SD_PRESENT)
  {
    return MSD_ERROR;
  }
  /* HAL SD initialization */
  sd_state = HAL_SD_Init(&hsd);
  /* Configure SD Bus width (4 bits mode selected) */
  if (sd_state == MSD_OK)
  {
    /* Enable wide operation */
    if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
    {
      sd_state = MSD_ERROR;
    }
  }
 
  return sd_state;
}

Do you have pull-ups on your DATA/CMD pins? If not select pull-up in the pin config. Also consider dropping the speed-slew/rate is you don't have series resistors.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..