Page 1 of 1

ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 9:00 am
by kdsouza
Gentlemen,

I'm running ChibiOS 2.6,

I've got an SD card connected to the STM32F103RG via SPI2 and I was using the FatFS Demo provided in ChibiStudio.

With a 8GB Class 4 transcend card the system works without any issue after a software reset. So it initializes and everything and resumes operation.
Recently we got a pack of 4GB Class4 cards. These cards do not get initialized after a software reset or after pressing the reset button.

InsertHandler exits after mmcConnect

But if i remove power and put it back in, it initializes fine. This issue is only for Reset (button press) or software reset.

I am guessing the card is still active since it's last power on, is there a way to de-init or force init the card?
I tried adding delays in various places but no luck.

This is not a big deal if i use the 8GB cards, but I know these cards won't be around so we need to get the system working with any sort of cards, so this is an important issue.

Any insights?

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 9:05 am
by Giovanni
Hi,

It looks like the card is stuck in an initialized state because it does not get the reset like the CPU. I am not sure how this should be fixed, may be sending some kind of "init" command to the card before the normal connection procedure.

You should get the card documentation and see the recommended initialization procedure.

Giovanni

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 11:18 am
by kdsouza
Thanks Sir,

Well so i was following How to Use MMC/SDC from elmchan http://elm-chan.org/docs/mmc/mmc_e.html

Following the 1st step i tried

Code: Select all

 
     palSetPadMode(IOPORT2, 12, PAL_MODE_OUTPUT_PUSHPULL);
        palSetPadMode(IOPORT2, 13, PAL_MODE_OUTPUT_PUSHPULL); //CLK
        palSetPadMode(IOPORT2, 15, PAL_MODE_OUTPUT_PUSHPULL);
        palSetPad(IOPORT2, 12); //STMNS
        palSetPad(IOPORT2, 15); //STM MOSI

        chSysLockFromIsr();
        int x=0;
        for(x=0;x<500;x++)
        {
          palTogglePad(IOPORT2,13);
          chThdSleepMicroseconds(100);
        }
        chSysUnlockFromIsr();


But obviously that doesn't work. Any advice on how i can do the above steps ( 70 clocks with DI and CS high) ?

I am guessing I am close.

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 11:26 am
by Giovanni
Note that chThdSleepMicroseconds(7) does not actually sleep 7 microseconds, the real resolution is dictated by the system tick.

Anyway, the generation of clock pulses is already done by the driver.

Giovanni

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 12:11 pm
by kdsouza
send_command_R1 returns 1 from Poweroff to start.

On restart the same function returns FF(255). Could it mean it needs more time? Or the sd card is not willing to get resetted?

spiIgnore(mmcp->config->spip, 100); is responsible for the clocks yes?

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Tue May 03, 2016 12:40 pm
by Giovanni
spiIgnore() generates the clock pulses and puts the card in SPI mode, after the reset the card should already be in SPI mode.

Giovanni

Re: ST32F103RG FatFS Not Initializing on software reset

Posted: Thu Nov 30, 2017 5:36 pm
by pitdibi
Hi!
I've the same problem when a power fault pulse does reset microcontroller but doesn't reset the 4GB SD. As described in a precedent post, if I instead use a 32 GB SD, the bug doesn't occur. I've solved this problem inserting a circuit that removes power to SD in initializing phase of the microcontroller. But there is anyone who knows because this happens?
Regards
Pietro