cancel
Showing results for 
Search instead for 
Did you mean: 

"SD Card Support Issue on STM32F429IIT6 - Request for Technical Support"

Rushikesh1234
Associate II

i get `FR_NOT_READY`, `HAL_SD_ERROR_REQUEST_NOT_APPLICABLE` errors .

/* If requested card supports wide bus operation */
if((scr[1U] & SDMMC_WIDE_BUS_SUPPORT) != SDMMC_ALLZERO)
{
//...
return HAL_SD_
return HAL_SD_ERROR_REQUEST_NOT_APPLICABLE;
  }ERROR_NONE;
}
else
{
How do I fix this and make SD card work with 4bits wide bus?

 

sd card scematic   (part number-GTFP08431BEU)

 

Rushikesh1234_0-1698738438263.png

Microcontroller scematic  -

Rushikesh1234_1-1698738576535.png

 

13 REPLIES 13
FBL
ST Employee

Hello @Rushikesh1234 

 

I'm not sure if it's related to the same issue discussed in this thread.

Solved: SDIO interface not working in 4Bits with STM32F4 F... - STMicroelectronics Community

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Rushikesh1234
Associate II

i do the changes , but still it not fix

thanks regards,

Rushikesh1234
Associate II

https://community.st.com/t5/stm32-mcus-embedded-software/solved-stm32f446-sdio-findscr-fifo-is-zero/td-p/116325

 this same problem  i have , i  am using stm cubeide version 1.12.1  

Hello again @Rushikesh1234 

Which cube firmware version do you use? You need to update the CubeIDE as well... Have you managed to initialize the FAT filesystem with single wide bus?  Additional context about the use case and sharing your project would be helpful to investigate further.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

hello,

i am using stmcubeide version 1.12.1, and both 1 and 4  bit wide bus are not work 

when i use 4 bir mode it returns (FR_NOT_READY) error and for 1 bit mode  it returns (FR_DISK_ERR)   error.

code -

 
#include "main.h"
#include "fatfs.h"
 
SD_HandleTypeDef hsd;
UART_HandleTypeDef huart6;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SDIO_SD_Init(void);
static void MX_USART6_UART_Init(void);
 
extern char SDPath[4];  
extern FATFS SDFatFS;    
extern FIL SDFile;       
 
int main(void)
{
uint32_t byteswritten, bytesread;
uint8_t wtext[] = "STM32 FATFS works great!"; 
uint8_t rtext[_MAX_SS];
 
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SDIO_SD_Init();
MX_USART6_UART_Init();
MX_FATFS_Init();
 
FRESULT rc;
 
rc=f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
   if(rc != FR_OK)
 {
printf("\rMounted unsuccessfully\n\r");
Error_Handler();
 }
else
 {
printf("\rMounted successfully\n\r");
rc = f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE);
if(rc != FR_OK)
 {
printf("File creation error %d\n\r",rc);
 Error_Handler();
  }
else
  {
printf("\rFILE IS OPEN\n\r");
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
 if((byteswritten == 0) || (res != FR_OK))
  {
Error_Handler();
  }
 else
  {
printf("File write\n\r");
f_close(&SDFile);
printf("file has been closed\n\r");
   }
   }
   }
while (1)
  {
    
  }
 
}
 
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
  
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = 8;
  RCC_OscInitStruct.PLL.PLLN = 50;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 3;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}
static void MX_SDIO_SD_Init(void)
{
  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_4B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 0;
 
static void MX_USART6_UART_Init(void)
{
   huart6.Instance = USART6;
  huart6.Init.BaudRate = 115200;
  huart6.Init.WordLength = UART_WORDLENGTH_8B;
  huart6.Init.StopBits = UART_STOPBITS_1;
  huart6.Init.Parity = UART_PARITY_NONE;
  huart6.Init.Mode = UART_MODE_TX_RX;
  huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart6.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart6) != HAL_OK)
  {
    Error_Handler();
  }
 
 }
static void MX_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  
    __HAL_RCC_GPIOC_CLK_ENABLE();
  __HAL_RCC_GPIOH_CLK_ENABLE();
  __HAL_RCC_GPIOA_CLK_ENABLE();
  __HAL_RCC_GPIOD_CLK_ENABLE();
  
 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_6, GPIO_PIN_RESET);
 
  GPIO_InitStruct.Pin = GPIO_PIN_8;
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  GPIO_InitStruct.Pin = GPIO_PIN_6;
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}
int __io_putchar(int ch)
{
HAL_UART_Transmit(&huart6, (uint8_t*)&ch, 1, 100);
return ch;}
void Error_Handler(void)
{
__disable_irq();
  while (1)
  {
  }
 
#ifdef  USE_FULL_ASSERT
 
void assert_failed(uint8_t *file, uint32_t line)
{
}
  
 
#endif 

 

 

 

elso
Associate III

Hi, 

Does it work in 1 bit bus mode?

I had a bug when I configured it in the config .IOC to 4bit, it didn't work. However if I configured it as 1 bit, and in user-code of SDMMC init, added one extra function to turn it back to 4 bit, it worked. 

static void MX_SDMMC1_SD_Init(void)
{
  hsd1.Instance = SDMMC1;
  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
  hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
  hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
  hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd1.Init.ClockDiv = 4;

if (HAL_SD_Init(&hsd1) != HAL_OK)
  {
	  Error_Handler();
  }
  if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
  {
	  Error_Handler();
  }
}

Another Question is:

- What is the clock frequency? (See you are using clock divide factor of 0) Maybe it is too high. (I am using 96MHz with CK.DIV=4)

- What SD card are you using? Class, and model

- How is your FATFS --> Platform settings --> Detect_SDIO pin configures and connected?

 

Rushikesh1234
Associate II
static void MX_SDMMC1_SD_Init(void)
{
  hsd1.Instance = SDMMC1;
  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
  hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
  hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
  hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd1.Init.ClockDiv = 4;

if (HAL_SD_Init(&hsd1) != HAL_OK)
  {
	  Error_Handler();
  }
  if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
  {
	  Error_Handler();
  }
}

 i tried this but it not work, the clock frequency is 16 MHz,  i use sandisk 8 gb sd card  

  and yes Detect_SDIO is configured and connected in FATFS Platform setting.

static void MX_SDIO_SD_Init(void)
{
  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 = 4;
  HAL_SD_DeInit(&hsd); //In case of re-initialization

  if (HAL_SD_Init(&hsd) != HAL_OK)
  {
     return 1;
  }
  if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
  {
     return 1;
  }
  return 0;
}

You did rewrite it to look like this? Since you are using SDIO and not SDMMC1?

Rushikesh1234
Associate II

 thanks for replying,

 Yes i do changes according SDIO , still it won't work.