cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F412.. disco -- Unable to get the sdcard working.

pumarada
Associate III

I've been testing ST chips and started with the STM32F411 using my own board for testing with the SD card, which I wasn't able to get working.

Thinking it was my fault, I ordered the STM32F412 Discovery board and I can confirm that using the examples, the SD card works fine.

When I try to get it running on my own, without examples, configuring through the Device Configuration Tool, I'm unable to make it work.

I must be doing something else wrong, but I don't know what, and I've been struggling with it for two days now.

Can you help me, please?

Thank you and regards.

17 REPLIES 17

After doing some research, I believe I have identified the reason why the graphical configurator for the SDIO and FATFS peripheral is not working on the STM32F412-Discovery board.

Apparently, there is a discrepancy in the pin configuration between the board and the graphical configurator, making it impossible to use the configurator without making changes to the libraries.

On the board, the pins are assigned as follows:

PC8 -> D0
PC9 -> D1
PC10 -> D2
PC11 -> D3
PC12 -> CK
PD2 -> CMD

While the graphical configurator uses:

PC8 -> D0
PC9 -> D1
PA9 -> D2
PC11 -> D3
PB15 -> SCK
PA6 -> CMD

It's really baffling to encounter this kind of discrepancies.

I wonder if no one at STM has noticed this, or if it's some kind of joke...

Regards.

>It's really baffling to encounter this kind of discrepancies.

>I wonder if no one at STM has noticed this, or if it's some kind of joke...

Do you mean that you've selected in the "graphical configurator" the STM32F412 Discovery board, and it produced wrong pin selection for the SDIO? Then please report a bug.

But if you've configured a custom board (started from the MCU selection), the configurator can start from some default pinout that does not match the board. The user has to check the pinout and manually reassign whatever is wrong.

 

 

Sure, the issue is that if you configure the SDIO peripheral from the graphical interface, it automatically decides to adjust the outputs using one of the possible combinations, and the design of the STM32F412ZGT6-DISCO board is using another pin configuration, possibly to provide compatibility with the USB terminal. Therefore, the configuration made through the graphical environment is not valid, and that's why it fails. Once configured through the graphical interface, you need to access the file STM32Cube/Repository/STM32Cube_FW_F4_V1.28.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c and change the pin configuration, or at least that's how I managed to solve it.

 

void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
  if(hsd->Instance==SDIO)
  {
  /* USER CODE BEGIN SDIO_MspInit 0 */

  /* USER CODE END SDIO_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDIO|RCC_PERIPHCLK_CLK48;
    PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;
    PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_SDIO_CLK_ENABLE();

    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
    __HAL_RCC_GPIOC_CLK_ENABLE();
    /**SDIO GPIO Configuration
    PA6     ------> SDIO_CMD
    PB15     ------> SDIO_CK
    PC8     ------> SDIO_D0
    PC9     ------> SDIO_D1
    PA9     ------> SDIO_D2
    PC11     ------> SDIO_D3
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  /* USER CODE BEGIN SDIO_MspInit 1 */
    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_NOPULL;
    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_NOPULL;
	GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
	GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
	HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* USER CODE END SDIO_MspInit 1 */
  }

}

 

Anyway, it would be good to raise awareness about the issue, do you know how to do it?

Thank you.

Hi,

you can use different pins on some peripherals - just click in the "graphical configurator" on the pin, you want some function to be, and select this from the list. Then this pin has the functionality you want.

If you start the design (new -> project ...) with selecting the cpu , the IDE/Cube cannot know, on which pins you want a peripheral to be (if there is a possible selection of more than one) , you have to set it to the pin you want it.

If you select the board (nucleo-xxx or so) , then it should make the pins usage as needed on this board.

If you feel a post has answered your question, please click "Accept as Solution".

Hola,

That is true, but if you choose a peripheral from the drop-down menu, it assigns you a group of pins, when in reality there could be more combinations and by not being able to decide which combination to use and having to configure the pins independently, the nature of the configurator is lost.

Pavel A.
Evangelist III

by not being able to decide which combination to use and having to configure the pins independently, the nature of the configurator is lost.

But how the configurator could know, unless you refer to a known board? The configurator can find alternative pins for every functions, if they exists. It detects pin conflicts. What else to wish? You've just unlocked a valuable experience point: realized that a peripheral can have alternative pin assignments. 

> the nature of the configurator is lost.

Which nature ?  Reading the future or your brain ?  This features only in paid version 159.8.6 . :)

>when in reality there could be more combinations

Right...press Strg on keyboard and click on the pin of interest...then you see all possible variants blinking.

Choose one of them...or not. As you like. (Except your PC can read your mind already...then it will happen automatically. )

 

-----

Sorry, if this sounds not super "nice" - but hey, this is just a tool to generate code, as you set it.

What you expect more then ?  If you not tell it , what it should do - what should it do then ??

If you feel a post has answered your question, please click "Accept as Solution".
pumarada
Associate III

I think you don't understand what I'm referring to, rather I'm sure.

I'll repeat, it's not an independent pin, it's a peripheral, and as a group of pins, there aren't so many variations. It would be as simple as being able to decide which set of pins to use. It's not that difficult to understand.

Anyway, I don't see the tools provided as robust, and having to code from scratch, there are more suitable systems.

I'm responding in the same tone I receive.

Best regards.