cancel
Showing results for 
Search instead for 
Did you mean: 

Understand SD Card detect pin initialization

DYann.1
Senior II

Hello,

I would like to understand the code to carry out my software integration :

 

    /* Configure SD pin detect */
    __SD_DETECT_GPIO_CLK_ENABLE();
    __HAL_RCC_PWR_CLK_ENABLE();

 

And This refers to lines of code that I am lost, for the first line for example

 

#define __SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOG_CLK_ENABLE()

 

And after :

 

#define __HAL_RCC_GPIOG_CLK_ENABLE()           do { \
                                                    __IO uint32_t tmpreg; \
                                                    SET_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOGEN); \
                                                    /* Delay after an RCC peripheral clock enabling */ \
                                                    tmpreg = READ_BIT(RCC->AHB2ENR, RCC_AHB2ENR_GPIOGEN); \
                                                    UNUSED(tmpreg); \
                                                  } while(0)

 

I would just like to configure the SD card to be able to write the code from an example on the evaluation card. My real card is not the evaluation card and I would like the code just necessary. Do you have an example for STM32L5xx with the file .ioc for example.

Thank you 

 

 

36 REPLIES 36

@DYann.1 wrote:




it works but not all the time and I don't understand very well.!


So spend some time to understand it.

Debug what is going wrong when it fails.

Just testing for "not OK" gives you no insight into what's going wrong:

void SD_Init (void)
{
  if (MX_FATFS_Init() != APP_OK) {
    Error_Handler();
  }
  if (PRESENT_SD() != APP_OK) {
    Error_Handler();
  }

Add some diagnostic output so that you can see what's going on.

Have a variable to catch the return code, and print it.

eg,

  printf( "MX_FATFS_Init: " );
  result = MX_FATFS_Init();
  if( result != APP_OK ) {
    printf( "error %d\n", result );
    Error_Handler();
  }
  printf( "OK\n" );

  printf( "PRESENT_SD: " );
  result = PRESENT_SD();
  if( result != APP_OK ) {
    printf( "error %d\n", result );
    Error_Handler();
  }
  printf( "OK\n" );

 

etc, etc, ...

 


@DYann.1 wrote:




it works but not all the time  


But, near the start of this thread, you said:

 


@DYann.1 wrote:


I have a STM32L552E-EV and I have a program that works very well on this evaluation card 


So study that to see how it should work ...


@Andrew Neil wrote:

So study that to see how it should work ...


I try but it's too difficult for me, I abandon this track and I'm watching the video.


@DYann.1 wrote:


I try but it's too difficult for me


Maybe explore STM32duino - Arduino on STM32 ?

https://github.com/stm32duino

https://www.stm32duino.com/

https://docs.arduino.cc/libraries/stm32duino-examples/

 

Or just use an Arduino?


@SofLit wrote:

Not possible to provide ioc file for each case/board.

The video is simple and you can easily follow it. You need just the SDcard detection not the all configuration of FatFs.


Now after watching the video, In my configuration I can't see I don't see the DMA Settings tab, is it normal ?

DYann1_0-1736440078058.png

In the video I can see this tab :

DYann1_1-1736440319708.png

Is this due to the type of microprocessor or the STMCube IDE environment which is not up to date ?

Thank you for your answer

Your question was about the card detection and not about the all SD card configuration.

Did you find how to configure the SDcard pin detection in CubeMx or not? if yes please accept the comment that answered your original question: "Understand SD Card detect pin initialization" and open a new thread on how to configure FatFs on STM32L5 using CubeMx.

Thank you for your understanding.

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.
PS:
1 - This is NOT an online support (https://ols.st.com) but a collaborative space.
2 - Please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help.

@SofLit wrote:

Your question was about the card detection and not about the all SD card configuration.

Did you find how to configure the SDcard pin detection in CubeMx or not? if yes please accept the comment that answered your original question: "Understand SD Card detect pin initialization" and open a new thread on how to configure FatFs on STM32L5 using CubeMx.

Thank you for your understanding.


Sorry, you're right, I forgot the question from my Topic.

Thank you


New thread here: https://community.st.com/t5/stm32cubemx-mcus/how-to-configure-fatfs-on-stm32l5-using-cubemx/td-p/760464