My 2GB Transcan microSD card does not initialize correctly when my FRD-K64F is powered up. Only after pressing the reset button is the card accessible. Well, almost "only."
Using KDS, I have created a simple app based on the FRDM-K64F with PE and KSDK support.
Using PE, I added a debug console (debug_console), a memory card (fsl_sdcard) and a GPIO pin (fsl_gpio) to my project. The memory card is setup for 4-bit access, and the GPIO pin is setup as a card detect input. Everything is configured from the FRDM-K64F schematic.
On power up, the blocksize member in my sdhc_card_t structure is "0" (in fact, all members appear to be zeroed), and the card is not accessible. Pressing the reset button then initializes the card structure, and everything works as expected.
I have also found that shutting down the SDHC driver, then reinitializing the SDHC and the SDCARD drivers "fixes" the problem. Like this. . .
if (0 == memoryCard1_state.blockSize) { #if 0 SDCARD_DRV_Shutdown(&memoryCard1_state); #endif SDHC_DRV_Shutdown(FSL_FSL_SDHC1); if (kStatus_SDHC_NoError != SDHC_DRV_Init(FSL_FSL_SDHC1, &fsl_sdhc1_host, &fsl_sdhc1_InitConfig0)) { printf("SDHC_DRV_Init() error\r\n"); return false; } if (kStatus_SDHC_NoError != SDCARD_DRV_Init(&fsl_sdhc1_host, &memoryCard1_state)) { printf("SDCARD_DRV_Init() error\r\n"); return false; } if (0 == memoryCard1_state.blockSize) return false; } return true;
Notice that calling SDCARD_DRV_Shutdown() hung the processor. On the other hand, not calling SDHC_DRV_Shutdown() followed by SDHC_DRV_Init() was not sufficient to restore SD card access. Also, calling SDHC_DRV_Init() without first calling SDHC_DRV_Shutdown() was problematic.
I've attached my project.
Does anyone have any suggestions?
Original Attachment has been moved to: sdcard_test.zip
I was pulled away from this project for a while, but I'm back on it now.
Since my original post, I have attended FTF 2015, switched from KDS 2.0 to KDS 3.0, and switched from KSDK 1.1 to KSDK 1.2. I built a new project hoping the bug was fixed, but it's still there.
My original post implied that the problem only appeared when the board was first "powered up." I have done a lot more investigating since, and I don't believe that's a true statement. I do believe the problem presents itself when the code is launched with the OpenSDA debugger. Every time I launch the program with the debugger, the SD card driver fails to initialize. It returns an error code 3, which fsl_sdhc_driver.h enumerates as kStatus_SDHC_SetCardToIdle /*!< Failed to set card to idle */
If I then hit the reset button, it works. If I power cycle the board, it works.
The only way I can get it to work with the debugger is to shutdown the SDHC driver, reinitialize it and then reinitialize the SDCARD driver (as shown in the original post).
- Audi
In case this is relevant:
I faced several problems with SD cards and power consumption of them on the FRDM-K64F board: some SD-cards drain several hundreds of milli-Amps when inserted or powered up. And the 5V to 3.3V DC-DC converter was not able to power all the devices on the board (K20, K64F plus the SD card).
So is this problem only happening if you have the SD card inserted at power-up time?
Our solution was to use industrial grade SD cards which had a much better (lower) power-up current consumption.
Or you might backup the 3.3V on the header with some more milli-amps. You might be able to measure a power drop on the 3.3V too.
I hope this might be useful,
Erich
Have you solved?
I found out that some SDCards need some time to "wakeup" when first powered, so in my project I wait 1 second before trying to initialize the SDHC driver, and it always work.
If I don't wait, depending on the sdcard sometime it work, sometime I have the same behaviour as you.
Best Regards
Giacomo
Giacomo, I have not found a solution.
I have also noticed that some SD cards need a few seconds to "wake up." I did try putting in some different delays in different locations; but, nothing made a difference.
Thanks for the suggestion though.
- Audi
Hello Audi,
I have test your project on my side , and it can work well , the screenshot below is the information on hyperterminal.
Does i misunderstand your question ?
BR
Alice
Hi Alice,
Did you get it to work from KDS with the OpenSDA debugger? Or did you drag/drop onto the mbed drive?
Hi Audi ,
I recommend you test the SD demo under KSDK (...\KSDK_1.1.0\demos\sdhc_sdcard) .
BR
Alice
Yep. Did that first.
Most of my (SD) code was copy/paste from there.
- am
Hi
See whether you get the same behaviour with a FRDM-K64F binary from: µTasker Kinetis FRDM-K64F support
Regards
Mark
Kinetis: µTasker Kinetis support
K64: µTasker Kinetis FRDM-K64F support / µTasker Kinetis TWR-K64F120M support
For the complete "out-of-the-box" Kinetis experience and faster time to market
Hi
I moved your thread to the correct place.
Regards
Vicente