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 

 

 

34 REPLIES 34

@SofLit wrote:

Did you watch the video of the card detection config with CubeMx that I shared in a previous comment?


I'll do it ! But it's not the same µP - In the video we have the STM32F746G-DISCO and in my case I have the STM32L552ZET6QU. Ok, the principle is pretty much the same, I'm going to continue watching this video

Thank you


@DYann.1 wrote:


For 1 line of code there are 4 or 5 references and it becomes unreadable..


Does it?

All you need to do is to find the lines that are actually used - take out the ones that are not needed.

No need to explore the definitions behind those lines at this point.

When you've cut it down to just the SD-Card stuff, there will be a lot less there, so a lot easier to follow 


@Andrew Neil wrote:


Does it?


Of course, and the inputs and outputs are linked to the development card but this is not my case, I only have the same microprocessor and nothing else. I don't have the same components, nor the BSPs and other libraries so I watch the SOFLIT video is better for me. 

You missed the point.

The point was to do this on the EV - so you're starting from a known-working project.

Cut that down so it's just doing the ST-Card.

Then you have a smaller, simpler  project to port to your own hardware..

 


@DYann.1 wrote:


the SOFLIT video is better for me. 


Yes, that's another fine approach.


@DYann.1 wrote:

@SofLit wrote:

Did you watch the video of the card detection config with CubeMx that I shared in a previous comment?


I'll do it ! But it's not the same µP - In the video we have the STM32F746G-DISCO and in my case I have the STM32L552ZET6QU. Ok, the principle is pretty much the same, I'm going to continue watching this video

Thank you


It's the same process. We cannot create the same video for each board/processor.

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.

@Andrew Neil wrote:

You missed the point.

The point was to do this on the EV - so you're starting from a known-working project.




I do it twice but it doesn't work all the time, I don't use the example provided in the evaluation card kit.

void SD_Init (void)
{
	  if (MX_FATFS_Init() != APP_OK) {
	    Error_Handler();
	  }
	  if (PRESENT_SD() != APP_OK) {
		  Error_Handler();
	  }
	  if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
	      {
	          Error_Handler();
	      }
      if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
      {
          Error_Handler();
      }
}

void SD_Close (void)
{
	if (nb==0)
	{
  	 f_close(&SDFile);
	 f_mount(&SDFatFS, (TCHAR const*)NULL, 0);
	 nb=1;
	}
}

I do it like this: I initialize then I carry out the writes on the SD card and at the end I close the file, it works but not all the time and I don't understand very well. I took portions of code from the example but I must have forgotten something and find what is missing, for 1 month I have not yet found it so I prefer to go on another development path. Let's talk about the video if you like, on the other hand on the video it's not the same evaluation card !


@SofLit wrote:

It's the same process. We cannot create the same video for each board/processor.


Yes but you can give an SD example with the .ioc file and it will be easier for everyone. Because, for me it's a bit complicated and your example code is too complicated to migrate the code to another card with only the same microprocessor and yet writing and reading from an SD card is a very simple process but you make it more complicated so that no one understands except yourself

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.

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.

@SofLit wrote:

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


Are you sure ? Of course I need to configure these steps :   

MX_FATFS_Init
PRESENT_SD
f_mount
f_open
f_write or f_read
SD_Close 

Do you have my code example previously, it works but not all the time, because I must have forgotten part of the code in your example, your code is incomprehensible and again the process of writing and reading an SD card is very simple. Have you understood and assimilated my answer to improve your way of working ?


@DYann.1 wrote:


 for me it's a bit complicated and your example code is too complicated 


Managing a filesystem and SD-Card isn't exactly simple - it's not a beginner's project.

It sounds like what you really need is to spend some more time with the basics, and learning to navigate,  understand, and debug code?