SDC Sporadic Issues

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
King John
Posts: 5
Joined: Mon Feb 26, 2018 5:36 pm
Been thanked: 1 time

SDC Sporadic Issues

Postby King John » Sun Jun 10, 2018 6:11 am

Hello,

I'm experiencing issues using the SDC driver on an STM32F407. I've got a generic STM32F4 board that has an onboard Micro SD card slot. It has 10k pullups to 3V3 on D0-D3, CMD, and SCK.

When calling sdcConnect it'll frequently fail. When it succeeds, I'm able to pull the CSD. I've pulled the CSD multiple times and it's always the same. I've tried multiple cards (which return different CSD's of course) and the result is the same. I'm running in 1BIT mode. I've set Alternate Mode 12. Activating the internal Pullups seems to make the issue less frequent, but even so I'm unable to mount with FatFS. It returns FR_DISK_ERR. Maybe data is getting corrupted while it tries to mount? Has anyone seen this before?

Thanks in advance!

User avatar
Giovanni
Site Admin
Posts: 11217
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 398 times
Been thanked: 332 times
Contact:

Re: SDC Sporadic Issues

Postby Giovanni » Sun Jun 10, 2018 11:02 am

Hi,

You should connect a logic analyzer, the pullup thing makes me think that you may need stronger pullups. Do you have capacitors close to the card?

Giovanni

King John
Posts: 5
Joined: Mon Feb 26, 2018 5:36 pm
Been thanked: 1 time

Re: SDC Sporadic Issues

Postby King John » Sun Jun 10, 2018 4:17 pm

Giovanni,

Thanks for your reply. There is one capacitor close to the card. Here's a schematic of the circuit. I was thinking the same thing, but I'd think that the internal pullups would get the job done, especially with the help of the 10k pullups. This is all SMD so changing resistors would be undesirable :). I've also attached a snip of the related code. I noticed in the samples that Alternate Pin Mode isn't set. Am I missing something there? Side note, blkIsInserted(&SDCD1) always returns TRUE. Is this normal behavior?

Image

Code: Select all

palSetPadMode(GPIOD, 2, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);
  palSetPadMode(GPIOC, 12, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);
  palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);
  palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);
  palSetPadMode(GPIOC, 10, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);
  palSetPadMode(GPIOC, 11, PAL_MODE_ALTERNATE(12) | PAL_STM32_PUPDR_PULLUP);

  sdcObjectInit(&SDCD1);
  sdcStart(&SDCD1, &sdccfg);

  if (blkIsInserted(&SDCD1)) {
    debug("Card inserted, initing SD card...");
    bool status = false;
    do {
      status = sdcConnect(&SDCD1);
      if (status != HAL_SUCCESS) {
        debug("SD Error!");
      }
      else {
        chprintf(&SD1, "CSD      : %08X %8X %08X %08X \r\n", SDCD1.csd[3],
                 SDCD1.csd[2], SDCD1.csd[1], SDCD1.csd[0]);
        break;
      }

    } while (TRUE);
   }

User avatar
Giovanni
Site Admin
Posts: 11217
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 398 times
Been thanked: 332 times
Contact:

Re: SDC Sporadic Issues

Postby Giovanni » Sun Jun 10, 2018 6:57 pm

Hi,

blkIsInserted(&SDCD1) is something you need to implement in your board.c file, there is no standard way for detection.

Giovanni

King John
Posts: 5
Joined: Mon Feb 26, 2018 5:36 pm
Been thanked: 1 time

Re: SDC Sporadic Issues

Postby King John » Thu Jun 14, 2018 4:47 am

Thank you for your help, Giovanni. I found that I had some jumpers on the same pins that are connected to the Micro SD adapter on my board. Must have had some capacitance that was corrupting the data going through. Amateur mistake, but hopefully can benefit from this post.


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 3 guests