This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHCC3235MOD: CC3235MOD LanchPad and microSD Card BoosterPack: sometimes dead in SD_open()

Part Number: LAUNCHCC3235MOD
Other Parts Discussed in Thread: TEST2, CC3200, SYSCONFIG

Hi,

I recently encountered an issue about micro SD card operation. My project uses CC3235MOD LaunchPad and micro SD Card BoosterPack, adopted the "sdraw" example code in the SDK. What the project does is do some SD card R/W operation then hibernate a while, then does it again. But it sometimes dead in the SD_open() about 1/5 probability.

The hardware connection followed the example code, no change. I use less than 5cm jumping wire and I pretty sure it’s a stable connection. SD clk runs at 8MHz, no change from the example code as well.

Software: the usage followed the example code as SD_init(); SD_open(); SD_initialize(); SD_write(); SD_read(); SD_close(). All the read and write operation is fine, no error occured.

When it goes wrong, it always stucked in the file sdhost.c shown as below:

This problem has bothered me for quite some time. It does not look like a connection issue since R/W never goes wrong. Please help and give me some idea to fix it. Thanks in advance!

P.S. the version of SDK is simplelink_cc32xx_sdk_4_30_00_06

  • Hi,

    It does seem interesting that the you get stuck waiting for the sd host interface reset to complete. Is the sdhost init consistently failing after about 5 open/close cycles, or is is somewhat random but with a roughly 1/5 probability?

    There are a couple things you can try:

    1. Can you place a small busy-wait after the first module reset, and before the second internal reset in the SDHostInit() function of sdhost.c? The UtilsDelay() function would be ideal, and waiting 100-1000ms will be enough for this test, to see if there is some timing issue with the init function.

    2. Have you tried not using hibernate, but simply calling open/close in a loop? If you perform that test, do you still run into this issue?

    Regards,

    Michael

  • Hi Micheal,

    Thanks for your reply!

    This failing happened randomly and roughly 1/5 probability on average.

    Regarding your suggestion, I'll try them ASAP.

    1. I wanna make sure I follow your idea, put UtilsDelay(999*1000*80/3) included in "utils.h" in front of Line 92 the While loop in sdhost.c?

    2. I first found this happened when I used CCS to debug my project, I thought it was an accident. Now I still may encounter this problem even I keep loading the program for debug in CCS. I will do the test using sleep() instead of hibernating, Is that OK?

    Thanks,

    Fei

  • Hi Micheal,

    I have done the two tests, they are not working. I put delay before and after the internal reset command. It's the same result.


    I checked the Manual "SWRU543A", the Chapter 11.5 Table 11-1, the SanDisk card needs some additional delay, It's that the problem? Maybe I should try Transcend card or put some delay in my code. The question is where should I put the delay and how long it needs.

    I noticed the microSD booster board connected the CS pin of the microSD card, but I did not connect the CS pin to the CC3235MOD board. Is that OK? Or should I do something to the CS pin?

    Thanks,

    Fei

  • Hi Fei,

    Sure, you can try a different SD card and see if the same behavior occurs.

    Using sleep() works for the non-hibernate test. If you don't have the power policy enabled then the device won't use any LPDS or hibernate.

    For the SDhost interface on the CC3235, it only supports one data line so the CS signal is not used. The boosterpack includes the CS signal because many MCUs don't have an SDhost peripheral, only SPI.

    Just to clarify your test, if you reset the CC3235, does the SD host interface function correctly again? Also, have you tried flashing the code persistently onto the CC3235, rather than loading the program using JTAG through CCS?

    Regards,

    Michael

  • Hi Michael,

    I flashed the cc3235 board to run my project, it would stuck in the SD open() occasionally until I pressed the button to reset the board or re-plug the power.

    Thanks,

    Fei

  • HI Fei,

    Good to know that after reset the code returns to normal functionality.

    Were you able to test another SD card to see if you saw the same behavior?

    Regards,
    Michael

  • Here are some updated test results.

    1. Used Sandisk microSD card, Commented out Line87 & Line92 in the sdhost.c, flashed the program into the board, the project dead in somewhere in the SD_write() operation after about 20 hours.

    2. Used Transcend 16GB SDHC MicroSD card, resume the sdhost.c, flashed the program into the board, the project dead in somewhere in the SD_write() operation after about 14 hours.

    Some details about my application: recording sound from Ti audio booster board and write to microSD card last for 30 seconds and then hibernate, woke up to repeat the same operation every 10 minutes. All codes modified from example projects.

    Is this a timing issue of the SD controller or a driver bug?

    In Table 11-1 of the "Technical reference manual(SWRU543A)", it mentioned that "This card requires some additional delay after the card select command is sent to the card, and before sending a read or write command; otherwise, the command will never complete." How long the delay is and where should I put it?

    Appreciate any suggestions and help!

    Thanks
    Fei

  • Hi Fei,

    It's interesting that your code is getting stuck in SD_write() for those SD cards. Does the SD_open() work correctly during the failure case?

    There isn't a specific delay value specified, you will need to experiment with your hardware. That being said, it probably has no relation to your issue, as that comment is more for situations where the read/write commands don't appear to be reliable at all. For the case where the failure only occurs after 14-20 hours, the card select delay is probably not the cause.

    If you wanted to add a delay, the simplest method is to probably modify the selectCard() function of SDHostCC32XX.c. This is the function that is called when the card select function is needed by the driver. Adding a short delay before the return would be worth a try.

    Regards,
    Michael

  • Hi Michael,

    I simplified the test and only modified the example project "sdraw_nortos" to eliminate irrelevant factors.

    All tests used Transcend 16GB SDHC MicroSD card. Run in CCS environment.

    Test1: The pseudo-code of the project is as below:

    SD_open();
    SD_initialize();
    while(1) {
    SD_write(4KB); 646 times // to simulate my application
    SD_read(4KB); 646 times
    sleep(10); // sleep 10 seconds
    }
    SD_close();

    Resutl: This test is OK. It successfully wrote the entire card.

    Test2: The pseudo-code of the project is as below:

    while(1) {
    SD_open();
    SD_initialize();
    SD_write(4KB); 646 times // to simulate my application
    SD_read(4KB); 646 times
    SD_close();
    sleep(10); // sleep 10 seconds
    }

    Resutl: Failed pretty quickly. It will be dead during the SD_open() which is Line92 in sdhost.c

    Test3: same as Test2, but comment out Line87 and Line92 in sdhost.c

    Resutl: Failed. It will be stuck in during the SD_open() or SD_initialize() but before SD_write().

    Test4: same as Test2, but comment out Line74 and Line79 along with Line87 and Line92 in sdhost.c

    Resutl: Failed similar with Test2.

    Like I said before, all failed results only can be back to normal by pressing the reset button on the board.

    I found comment lines in sdhost.c seems not working, I should rebuild the driverlib.a? How?

    I think this might be caused by the initialization progress, could you please verify it? THANKS A LOT!

    Regards,
    Fei

  • Hi Fei,

    To rebuild the driverlib libraries, you need to use the make file in the driverlib directory.

    Some instructions on how to run the make file can be found in the quick start guide, section 7.3. You can find the quick start guide at <sdk dir>/docs/simplelink_mcu_sdk/Quick_Start_Guide.html

    Following those instructions, you can invoke gmake on the makefile within the source/ti/devices/cc32xx/driverlib/ folder to rebuild the driverlib.a with your changes.

    In terms of the initialization process, your basic steps are correct. The main question is if there is some characteristic of the CC32xx SD host peripheral that does not handle a soft reset as expected. What happens if you perform a soft reset of the MCU + peripherals using PRCMMCUReset()?

    Regards,

    Michael

  • Hi Michael,

    Thanks a lot for your guidance! I successfully rebuilt the driverlib.a. I will do the test without the reset operations in sdhost.c.

    Another update test result I wanna share with you is I used hibernate instead of sleep. The result is almost the same as the test2. So it's no necessary to test using PRCMMCUReset(), right?

    Thanks,

    Fei

  • Hi Fei,

    There was some E2E post on the CC3200 SD card peripheral that mentioned that PRCMMCUReset() fixed things. So, giving that a try would be worthwhile.

    Regards,

    Michael

  • Hi Michael,

    I have completed a few tests and here are the results:

    1, modify sdhost.c, comment out Line74 and Line79 along with Line87 and Line92, rebuild the driverlib.a. The pseudo-code of the project is as below:

    SD_open();
    SD_initialize();
    SD_write(4KB); 646 times // to simulate my application
    SD_read(4KB); 646 times
    PRCMHibernateEnter(); // 10 seconds

    Result: dead after 766 times loop, stuck in SD card initialization progress, I'm not sure which line of code.

    2,resume sdhost.c and using PRCMMCUReset() instead of PRCMHibernateEnter().

    Result: dead after 15 times, stuck in Line92 of sdhost.c

    It's so weird test1 still have the issue of initializing.

    What's your opinion?

    Thanks,
    Fei

  • Some updates:

    I found if the reset operation in sdhost.c had been commented out(Line 87 alone or with Line 74), the program would be dead after several times in the code of line 1060 in SDHostCC32XX.c. Reload program in CCS can't clear it, must reset.

    The code is MAP_SDHostSetExpClk(hwAttrs->baseAddr, MAP_PRCMPeripheralClockGet(PRCM_SDHOST), SD_INIT_FREQ_80KHZ); and the map fuction is SDHostSetExpClk() in sdhost.c, It seems relate with the clock setup in the SD controller.

    The return value of MAP_PRCMPeripheralClockGet(PRCM_SDHOST) is 26,666,666, and the baseAddr is 0x44010000. they are all correct.

  • Hi Fei,

    Thanks for performing those tests. It's unfortunate that the PRCMMCUReset() doesn't appear to solve things, with only a hard reset being effective.

    I think that in the end, I think there is some characteristic of the SD host peripheral that is not resuming from the hibernate or soft reset state as expected.

    Have you tried using SPI to access your SD card, instead of the SD host peripheral? The SPI peripheral will work across hibernate cycles, as that is what we use internally to connect the main MCU with the NWP core. You should be able to modify the underlying HAL of the fatfs library to use SPI instead of the SD host peripheral APIs, and then wire the SPI pins of the CC3235 to your SD card instead of the SD host pins. Could you give that a try?

    Regards,

    Michael

  • Hi Michael,

    Thanks for your follow-up!

    Unfortunately there is no solution to the SD interface initialization issue. Switch to the SPI interface should work, but I have a few questions.

    Since we need to transfer data from the SD card to the WiFi interface, is there any potential problem with the SPI bus?

    I haven't found fatfs example using SPI in the CC3235 SDK, where can I found the example code to speed up the job.

    Thanks a lot!

    Best,
    Fei

  • P.S.
    I was confused when I set up the pins in syscfg, the SPICC32XXDMA and UDMACC32XX were grey out, is that OK for SPI implementation? It's for sure we need DMA function when R/W SD card.

  • Hi Fei,

    There isn't any issue with using the SPI interface with the SD card together with Wi-Fi. I have tested the SPI peripheral at the max rate of 20MHz with max speed Wi-Fi streaming and haven't encountered any issues.

    In terms of setup, the default fatsd example should actually support SD access over SPI. In sysconfig, under the SD peripheral options, there is the option to switch the interface to SD SPI.

    Switching that will swap the low-level hardware access functions from being implemented with SD host to being implemented with SPI. Of course, you will need to swap the pins being used to access your SD card so that they match up with the SPI pins of the CC32xx as well as the proper SPI pins of the SD card. The pins to use will be listed in PinMux of the SPI peripheral, but do keep in mind there is also the CS pin that is implemented as a GPIO - do check the sysconfig SD Slave Select setup to ensure that pin is correct too.

    Working from the fatsd example, I all of the needed SPI/DMA hardware should be loaded and configured once you make the switch in the SD peripheral config. Let me know if you still encounter difficulties building for SD SPI.

    Regards,

    Michael

  • Hi Michael,

    Thank you so much for your instructions! I have successfully switched the interface to SD SPI.

    But I ran a simple test, the R/W speed of the card was pretty slow. How to change the SPI bit rate? Is the parameter "spiParams.bitRate" in SDSPI_initializein() in SDSPI.c? I changed it from 25000000 (2.5MHz) to 20000000 (20MHz). But it seems still very slow.

    Thank you again!

    Regards,
    Fei

  • Hi Fei,

    The spiParams.bitRate is the correct place to change the SPI interface bitrate.

    Is the SD card read/write noticeably slower with SPI compared to the SD Host interface, how are you testing the performance of the SD card?

    Regards,

    Michael

  • Hi Micheal,

    I used PRCMSlowClkCtrGet() to get the running time. But I found it was not working by modifying spiParams.bitRate in SDSPI.c.

    I tried to recompile the drivers_cc32xx.a, but failed. What should I do? Is there any way to set the bitrate at the application level?

    Thanks,

    Fei

  • Update:

    I found a document and successfully re-compiled the driver_cc32xx.a.  <CC32xx SimpleLink Core SDK User's Guide>

    I ran some tests and got the result shown below. (Buffer size 4KB, transcend 16GB ultimate 600x)

    spiParams.bitRate Write  Read
    default value 2.5MHz 203KB/s 248KB/s
    20MHz 574KB/s 1076KB/s

    Does this test data look normal?

    Thanks,
    Fei

  • Hi Fei,

    Your test results look reasonable. There will be some delay per command, so even if the clock rate is 20MHz you won't be able to hit the max possible data rate depending on the overhead you're seeing. For example, large block transfers are much more efficient than small transfers.

    If you want to increase the speed further, you will probably need to research best practices for SD card access to reduce the library efficiency as much as possible. As the fatfs library is third-party, I suggest you look at documentation and guidance off the forum for further information.

    Let me know if you need further help or have more questions on using an SD card with the CC3235.

    Regards,

    Michael