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
TDK
Guru

If you're able to get the examples up and running, perhaps adapt that code to your board.

Long pigtailed wires on SDIO traces are not ideal. These signals are typically 48 MHz and won't work over long traces acting like antennas.

Might want to expand upon the details of "I wasn't able to get working".

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

Hola,

Using the graphical configurator, I enable the SDIO peripheral and in middleware, I enable FATFS.

That's all, including the card select input, without doing anything else. And upon running it, it runs fine but there are no files on the card.

in main.c:

 

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SDIO_SD_Init();
  MX_FATFS_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  HAL_GPIO_WritePin(led_Verde_GPIO_Port, led_Verde_Pin, GPIO_PIN_SET);
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 





in fatfs.c

 

void MX_FATFS_Init(void)
{
  /*## FatFS: Link the SD driver ###########################*/
  retSD = FATFS_LinkDriver(&SD_Driver, SDPath);

  /* USER CODE BEGIN Init */
  /* additional user code for init */
  uint32_t wbytes; /* File write counts */
   uint8_t wtext[] = "text to write logical disk"; /* File write buffer */

   FATFS mynewdiskFatFs; /* File system object for User logical drive */
   FIL MyFile; /* File object */
   char mynewdiskPath[4]; /* User logical drive path */

  if(retSD==0){
	  if(f_mount(&mynewdiskFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
	   {
	   if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
	   {
	   if(f_write(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) == FR_OK);
	   {
	   f_close(&MyFile);
	   }
	   }
	   }
  }
  /* USER CODE END Init */
}

 

pumarada
Associate III

???

TDK
Guru

What is different between the example that works and your own code?

FATFS is complicated in general. Probably not a lot of people wanting to invest a bunch of time in your particular project. CubeMX is not the most robust code generator, it's better to rely on the examples especially for complex code like SD or USB.

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

Just from my experience :  

- wires cpu -- sdcard should be < 50mm (short wires !)

- try with 1 bit (=standard) at first

- dont drive clk to high , 50MHz is max. 

- try port/pin speed setting medium or high 

- set pullups ON (on all lines)

Then it should work.

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

I'm testing with the basic configuration of CubeMX, and it's not working as the assistant leaves the code.

What works are the examples that come with the board, for example, FatFs_uSD for the STM32F412G-DISCO board.

I would like to confirm that I can configure and use the SD card based on an example that uses HAL in the simplest way possible.

I'm really seeing that the configuration assistant doesn't work well, and if I have to do all the code myself, even the basic configuration of the peripherals, I would discard said assistant and be done with it.

But still, I don't see a way to link the SDIO peripheral and the FatFs library; it always gives me some error.

Using the example and reviewing the code through the debugger, it's clear that the system is working very well, but it's using BSP functions that I have no idea where they are configured or defined or which libraries should be used to access them.

In short, the more I read, the less I understand, and it's something that frustrates me because, for example, using Espressif with IDF is much simpler.

I want to use STM for reasons of chip quality and efficiency, but I'm finding it very difficult to get started.

I know that the SD card should be configured with 1b and 400kHz and that it adjusts later, but I'm not even able to do that.

Hi,

I'm using the STM32F412-DISCOVERY test board, and it's understood that it already has the pull-ups and the board design supports the mentioned frequencies.

The issue is that I'm not able to write a simple file to the SD card, and the worst part is that I don't know how to do it. I would need help as simple as a straightforward code, very basic, that simply configures the SDIO, links it with FatFs, and creates a file on the SD card. From there on, I think I could find the mistakes I'm making.

I'll try to write the code on my own, without using CubeMX, and I'll let you know how it goes.

And thank you very much for helping me.

Regards.

 
 

A schematic of the card might work better and a picture in expressing the circuit.

As @AScha.3 mentions, you want short/even cables, pull-ups a the socket, the WaveShare SDIO  boards are a good example of an ideal circuit.

The F412-DISCO or one of the other EVAL/DISCO boards should have examples in Examples\Application\FatFS type subdirectories off the board trees. Sorry not a big fan of the CubeMX auto-gen approach. The BSP or MSP files should designate which GPIO is for Card Detect, and that's optional.

Debugging at the FatFS top-level is far less useful than at the DISKIO layer.

Make sure HSE_VALUE, PLL and clocking is set correctly for given board. For the F41x I'd disable SDIO HW Flow Control

 

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

This is the schematic of the SD card test board, and it works fine with Espressif.

 

Captura de pantalla de 2024-02-16 18-07-00.png