Skip to main content
Visitor II
September 19, 2022
Question

Interface SDMMC using FileX middleware issue in 4-bit bus width mode - STM32

  • September 19, 2022
  • 11 replies
  • 7223 views

Hi, i'm using STM32U575ZI-Q (in NUCLEO-U575), I want to write and read Fat32 files on SD using SDMMC interface, with FileX middleware. When I set the bus width in 1-bit the app work OK but when I switch the setting to 4-bit buswidth mode the app crashes, the debuging halt in the first reading command after SD initialization (in the HAL_SD_ReadBlocks function, it calls to SDMMC_CmdReadSingleBlock function and when it executes SDMMC_SendCommand the SDMMC bit transfer complete doesn't set)

I'm setting MCU CLK @ 160MHz (AHB & APB at 160MHz too), SDMMC CLK @ 6MHz (source PLL in 96MHz / (2* DIV) with DIV=8).

I repeat, in 1-bit buswidth the code working correctly ! But not in 4-bit mode

On the osciloscope I can see signals on pins D0-D3, so I can verify the 4-bit buswidth is set correctly.

I used a SDHC Standar and a SDHC UHS-1 and the result was the same.

The code includes fx_stm32_sd_driver_glue files.

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 SystemPower_Config();

 MX_GPIO_Init();

 MX_USART1_UART_Init();

 MX_ICACHE_Init();

 MX_FileX_Init();

 MX_SDMMC1_SD_Init();

 HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_SET);

 HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);

 HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_RESET);

 fx_thread_entry(0);

 while(1)

 {

  HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);

  HAL_Delay(400);

 }

 while (1)

 {

 }

}

void fx_thread_entry(ULONG thread_input)

{

 UINT status;

 ULONG bytes_read;

 CHAR read_buffer[32];

 CHAR buffer_SD[1560];

 CHAR data[] = "This is FileX working on STM32 \0";

 uint32_t a = 0;

 for (a = 0; a < 1560; ++a) {

 buffer_SD[a] = 'G';

 }

 buffer_SD[0] = 'd';

 buffer_SD[1] = 'i';

 buffer_SD[2] = 'v';

 buffer_SD[3] = '2';

 buffer_SD[1559] = '!';

 /* Open the SD disk driver. */

 status = fx_media_open(&sdio_disk, "STM32_SDIO_DISK", fx_stm32_sd_driver, 0,(VOID *) media_memory, sizeof(media_memory));

 /* Check the media open status. */

 if (status != FX_SUCCESS)

 {

  Error_Handler();

 }

 /* Create a file called STM32.TXT in the root directory. */

 status = fx_file_create(&sdio_disk, "STM32.TXT");

 /* Check the create status. */

 if (status != FX_SUCCESS)

 {

  /* Check for an already created status. This is expected on the

  second pass of this loop! */

  if (status != FX_ALREADY_CREATED)

  {

   /* Create error, call error handler. */

   Error_Handler();

  }

 }

 /* Open the test file. */

 status = fx_file_open(&sdio_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_WRITE);

 /* Check the file open status. */

 if (status != FX_SUCCESS)

 {

  /* Error opening file, call error handler. */

  Error_Handler();

 }

 /* Seek to the beginning of the test file. */

 status = fx_file_seek(&fx_file, 0);

 /* Check the file seek status. */

 if (status != FX_SUCCESS)

 {

  /* Error performing file seek, call error handler. */

  Error_Handler();

 }

 LED_BLUE_GPIO_Port->BRR |= LED_BLUE_Pin;

 /* Write a string to the test file. */

 status = fx_file_write(&fx_file, buffer_SD, sizeof(buffer_SD));

 /* Check the file write status. */

 if (status != FX_SUCCESS)

 {

  /* Error writing to a file, call error handler. */

  Error_Handler();

 }

 LED_BLUE_GPIO_Port->BSRR |= LED_BLUE_Pin;

 /* Close the test file. */

 status = fx_file_close(&fx_file);

 /* Check the file close status. */

 if (status != FX_SUCCESS)

 {

  /* Error closing the file, call error handler. */

  Error_Handler();

 }

 status = fx_media_flush(&sdio_disk);

 /* Check the media flush status. */

 if (status != FX_SUCCESS)

 {

  /* Error closing the file, call error handler. */

  Error_Handler();

 }

 /* Open the test file. */

 status = fx_file_open(&sdio_disk, &fx_file, "STM32.TXT", FX_OPEN_FOR_READ);

 /* Check the file open status. */

 if (status != FX_SUCCESS)

 {

  /* Error opening file, call error handler. */

  Error_Handler();

 }

 /* Seek to the beginning of the test file. */

 status = fx_file_seek(&fx_file, 0);

 /* Check the file seek status. */

 if (status != FX_SUCCESS)

 {

  /* Error performing file seek, call error handler. */

  Error_Handler();

 }

 /* Read the first 28 bytes of the test file. */

 status = fx_file_read(&fx_file, read_buffer, sizeof(data), &bytes_read);

 /* Check the file read status. */

 if ((status != FX_SUCCESS) || (bytes_read != sizeof(data)))

 {

  /* Error reading file, call error handler. */

  Error_Handler();

 }

 /* Close the test file. */

 status = fx_file_close(&fx_file);

 /* Check the file close status. */

 if (status != FX_SUCCESS)

 {

  /* Error closing the file, call error handler. */

  Error_Handler();

 }

 /* Close the media. */

 status = fx_media_close(&sdio_disk);

 /* Check the media close status. */

 if (status != FX_SUCCESS)

 {

  /* Error closing the media, call error handler. */

  Error_Handler();

 }

}

I guess the IDMA is not working properly but I'am not sure. If anyone can help me i appreciate it !

    This topic has been closed for replies.

    11 replies

    Visitor II
    May 8, 2023

    Well, using my version (STM32CubeIDE 1.9.0) it does not generate that code. So we found a very good solution. We switched to Nordic MCU and their HAL works.