Skip to main content
DYann.1
Senior II
June 21, 2024
Question

How to configure SD CARD via STM32CubeIDE

  • June 21, 2024
  • 6 replies
  • 3657 views

Hello,

I would like to know how to configure the SD card of an STM32L552E-VE evaluation board, I have an example with this evaluation card 'FatFs_uSD_Standalone' but It's not easy for me to understand how to configure the 'SDMMC' with this board since there is no '.IOC' file. I have the example code but not the '.IOC' configuration file. Can anyone tell me how to configure the SD card via STM32CubeIDE ?

Thank you for helps.

6 replies

mƎALLEm
Technical Moderator
June 21, 2024

Hello,

This video shows how to configure SD interface using CubeMx for FatFs file system usage .

Hope it helps.

"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."
DYann.1
DYann.1Author
Senior II
June 21, 2024

@mƎALLEm wrote:

Hello,

This video shows ho to configure SD interface using CubeMx for FatFs file system usage .

Hope it helps.


Hello,

Thanks, I'll look at it...

DYann.1
DYann.1Author
Senior II
June 24, 2024

Hello,

I can see the video but in this step I don't have the same configuration

DYann1_0-1719219843669.png

And my evaluation card does not have a DMA tab? Maybe I'm missing a library ?

DYann1_1-1719219983127.png

Yet the NVIC is activated. Probably the STM32F7 board is not the same as STM32L5 that why I don't have the DMA tab ?

Thanks

ST Employee
June 24, 2024

Hello,
this config of SD card on STM32L552E-VE board can help you. If you use SD card for the application 'FatFs_uSD_Standalone' must enable SDMMC1 global interrupt.

I will be waiting for your feedback.
Elhem_ZAY_0-1719223637287.pngElhem_ZAY_1-1719223675305.pngElhem_ZAY_2-1719223698869.pngElhem_ZAY_3-1719223723527.png

DYann.1
DYann.1Author
Senior II
June 24, 2024

Hello M. Elhem,

Thank you for this information, after having verified I don't have the SD card but the µSD card, I think it's the same communication protocol for both ? Should I check the box 'NVIC Interrupt Table' or not ? After your previous picture we don't  validate NVIC Interrupt Table.

When I try to generate de code by STMCubeIDE I have this message :

DYann1_0-1719232941183.png

Thanks

DYann.1
DYann.1Author
Senior II
June 24, 2024

Hello,

After login and download the update now i can have the code, now I can compare with the example code. Thank you.

DYann.1
DYann.1Author
Senior II
June 25, 2024

Hello,

After comparing the code I more or less found the configuration via CubeMX but I don't know where to find this information ? Could you tell me where they are located in the CLock configuration window ?

DYann1_0-1719318452797.png

Thank you for your helps

Regards

 

mƎALLEm
Technical Moderator
June 25, 2024

From the clock configuration menu and set SDMMC1 clock source to PLLP:

SofLit_0-1719321803781.png

 

The related generated code will be available le in stm32l5xx_hal_msp.c:

void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
 if(hsd->Instance==SDMMC1)
 {
 /* USER CODE BEGIN SDMMC1_MspInit 0 */

 /* USER CODE END SDMMC1_MspInit 0 */

 /** Initializes the peripherals clock
 */
 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC1;
 PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLP;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
 Error_Handler();
 }

:

 

 

"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."
ST Employee
June 25, 2024

Hello,
Clock Config of SD is correct and it is located in "SystemClock_Config" function.
Please find attached this lien of "FatFs_uSD_Standalone" application on STM32L552E-EV can help you :
https://github.com/STMicroelectronics/STM32CubeL5/tree/master/Projects/STM32L552E-EV/Applications/FatFs/FatFs_uSD_Standalone

you can compare your code generated with CubeMX with this application.
Good work.
Best regards.

DYann.1
DYann.1Author
Senior II
June 25, 2024

Hello,

I have this example as I said at the beginning of my topic. And in this example (FatFs_uSD_Standalone) I have this code in the function void SystemClock_Config(void) :

void SystemClock_Config(void)
{
 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Configure the main internal regulator output voltage
 */
 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE0) != HAL_OK)
 {
 Error_Handler();
 }
 /** Initializes the RCC Oscillators according to the specified parameters
 * in the RCC_OscInitTypeDef structure.
 */
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
 RCC_OscInitStruct.MSIState = RCC_MSI_ON;
 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
 RCC_OscInitStruct.PLL.PLLM = 1;
 RCC_OscInitStruct.PLL.PLLN = 55;
 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 {
 Error_Handler();
 }
 /** Initializes the CPU, AHB and APB buses clocks
 */
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
 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_5) != HAL_OK)
 {
 Error_Handler();
 }
 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SDMMC1;
 PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLL;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
 {
 Error_Handler();
 }
}

 This part of code is very strange and misplaced

DYann1_0-1719334021438.png

I was looking for something that I already had since I configured it in my .ioc file via STM32Cube IDE but which is placed elsewhere not in the function 'void SystemClock_Config(void)' but in the function 'void HAL_SD_MspInit(SD_HandleTypeDef* hsd)'. Thus It's impossible to compare to something that is not comparable. Why are you hiding the '.ioc' file in the FatFs_uSD_Standalone example ? What is your interest in wasting developers' time ?

mƎALLEm
Technical Moderator
June 25, 2024

Why are you hiding the '.ioc' file in the FatFs_uSD_Standalone example ? What is your interest in wasting developers' time ?

At the time STM32L5 series released we don't provide ioc files in its CubeHAL examples such as many older STM32 products. We are here to help you as we can. So no need to be aggressive.

"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."
DYann.1
DYann.1Author
Senior II
June 27, 2024

Hello,

I would like to know how to have the configuration have the same code from the STM example via the .IOC file. 

The example has this code

DYann1_0-1719478136600.png

Via my STM32CubeIDE, after configuring my Clock Configuration I can have this code

DYann1_1-1719478379884.png

I'm missing this line below, is this really important ?

DYann1_2-1719478464404.png

And my .ioc file has a red cross

DYann1_3-1719478673798.png

Do you have any idea how to configure my clock to have the same code as the example provided by STM ? Thank you for your helps.

Regards