WeActStudio / WeActStudio.STM32F4_64Pin_CoreBoard

17 stars 6 forks source link

...help with SD Card... #2

Open alhenriqx opened 6 months ago

alhenriqx commented 6 months ago

Love the board for stm32f446 - I followed the schematic and assigned these pin configuration for SDIO Select 4 bits wide bus in stm32 cubemx

PC8 - SDIO_D0 PC9 - SDIO_D1 PC10 - SDIO_D2 PC11 - SDIO_D3 PC12 - SDIO_CLK PD2 - SDIO_CMD

PA8 - SD_DETECT - input - pull-down PB2 - LED - output push pull

And since I am clocking the MCU to 180MHZ the SDIO bus is set to 45MHZ and in the SDIO configuration I have SDIOCLK clock divide factor set to 3 - expecting it to be 15 MHZ

I am also using FATFS middleware.

In attempting to mount the microSD card - I keep receiving this error stm32f4xx_hal_sd.c in function static uint32_t SD_PowerON(SD_HandleTypeDef *hsd) {...

/ Send CMD41 / errorstate = SDMMC_CmdAppOperCommand(hsd->Instance, SDMMC_VOLTAGE_WINDOW_SD | SDMMC_HIGH_CAPACITY | SD_SWITCH_1_8V_CAPACITY);

if(errorstate != HAL_SD_ERROR_NONE)
{
  return HAL_SD_ERROR_UNSUPPORTED_FEATURE;
}

...}

The errorstate returned is SDMMC_ERROR_CMD_RSP_TIMEOUT.

I am wondering if anyone was able to get the microSD working on the board? And would you mind sharing how?

WeActStudio commented 6 months ago
/**SDIO GPIO Configuration
PC8     ------> SDIO_D0
PC9     ------> SDIO_D1
PC10     ------> SDIO_D2
PC11     ------> SDIO_D3
PC12     ------> SDIO_CK
PD2     ------> SDIO_CMD
*/
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
                      |GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

Check whether the pull-up function of GPIO is enabled

alhenriqx commented 6 months ago

Thank for you reply - I appreciate it.

I am using this firmware package for the mcu reference STM32F446RETx STM32Cube FW_F4 V1.28.0

So I started to step through ST's library, and I noticed that the mount failed due to SD detect pin state

PA8 - SD_DETECT is gpio_input

interesting enough - in the middleware file "fatfs_platform.c", the detect pin is expected to be reset state when card is inserted. which causes f_mount to fail - so I simply edited the self generated file

uint8_t BSP_PlatformIsDetected(void) { uint8_t status = SD_PRESENT; / Check SD card detect pin / if(HAL_GPIO_ReadPin(SD_DETECT_GPIO_PORT, SD_DETECT_PIN) != GPIO_PIN_RESET) <-- I changed this to GPIO_PIN_SET to make it work { status = SD_NOT_PRESENT; } / USER CODE BEGIN 1 / / user code can be inserted here / / USER CODE END 1 / return status; }

However mounting the disk still fails

looking further this command fails in this file stm32f4xx_hal_sd.c

errorstate = SDMMC_CmdAppOperCommand(hsd->Instance, SDMMC_VOLTAGE_WINDOW_SD | SDMMC_HIGH_CAPACITY | SD_SWITCH_1_8V_CAPACITY);

if(errorstate != HAL_SD_ERROR_NONE)
{
  return HAL_SD_ERROR_UNSUPPORTED_FEATURE;
}

SDMMC_CmdAppOperCommand returns HAL_SD_ERROR_CMD_RSP_TIMEOUT

I made sure all the pins were set to pull-up, even though I don't believe the clock pin should be pull-up but out of desperation I tried anyway.

I also tried setting sdio for 1-BIT and I still couldn't get that to work.

The SD card is a 32GB card formatted to FAT32

Please let me know if there is any more information you need. Would love to get this to work with 4-bit SDIO.

thanks again!