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.

CC3235S: Unaligned SD card commands fail

Part Number: CC3235S
Other Parts Discussed in Thread: BOOSTXL-SHARP128, CC3200

We have a custom board with a CC3235S with a SD Card connected via the GPIOs.
We face a serious issue in the SD card communication where some commands (writes) to the SD Card either freeze (never returns) or returns SD_STATUS_ERROR.
We've traced the error to the SDHostCC32XX_write implementation in SDHostCC32XX.c: If the buffer is NOT word aligned, the call fails (else case of the "if (!(((uint_fast32_t)buf) & 0x03))" condition in line 716). We're using FreeRTOS and the 4.x Simplelink SDK (even tried the 5.x, without success).

We've already ruled out a FatFS issue by using direct SD access. We also tried multiple different sizes and brands for the SD card without success. Unfortunately, we don't have a Booster Pack with SD slot for a Launchpad at hand to reproduce the issue on a platform other than our custom board.

We've provided a minimal test case (see attached file) to reproduce the issue. Could you please have a look and help us to isolate and resolve this issue? Any help is greatly appreciated.

sdcard issue.zip

  • Hi,

    The word alignment check you mention is a requirement of the DMA peripheral of the CC32xx devices, which require word-aligned accesses. However, the else {}  case should still perform the write even if it isn't word aligned. So in your test, is the unaligned SD card command failing in that else{} case, where the DMA isn't used? Does it ever fail for word-aligned writes?

    Also, just to clarify is the error fairly consistently reproduced, or does it take a few tries before you encounter it?

    I have the BOOSTXL-SHARP128 that I can use to test your code, and will do that soon but knowing what to expect when I run your code will be helpful.

    Regards,

    Michael

  • Hi,

    So in your test, is the unaligned SD card command failing in that else{} case, where the DMA isn't used?

    Yes.

    Does it ever fail for word-aligned writes?

    I haven't seen crashes with word-aligned writes via DMA, although they could be that rare that it's pure coincidence.

    Also, just to clarify is the error fairly consistently reproduced, or does it take a few tries before you encounter it?

    Yes, the attached test case breaks every time on multiple custom boards.

    I have the BOOSTXL-SHARP128 that I can use to test your code, and will do that soon but knowing what to expect when I run your code will be helpful.

    That would be really helpful, thanks.

  • Hi,

    Thanks for following up with your info. I'll keep that in mind as I use my hardware to reproduce your issue.

    Regards,

    Michael

  • Hi,

    we finally got a Booster-Pack and were able to reproduce the issue there as well. So we're pretty confident that it is a bug in the Simplelink SDK and not an issue with our hardware. We used the sdraw example (drivers/sdraw/) to reproduce this bug:

    Add the following code (even simplier version of what I added initially as the test code) in the sdraw example:

    static void sdcard_test(Display_Handle display, SD_Handle sdcard_handle)
    {
        int result;
        uint32_t n_sectors, sector_size;
    
        n_sectors = SD_getNumSectors(sdcard_handle);
        sector_size = SD_getSectorSize(sdcard_handle);
    
        Display_printf(display, 0, 0, "n_sectors=%lu, sector_size=%lu\n", n_sectors, sector_size);
    
        uint8_t buffer[513] = { 0 };
    
        // Aligned buffer -> OK
        result = SD_write(sdcard_handle, buffer, 0, 1);
        Display_printf(display, 0, 0, "Aligned write: %d\n", result);
    
        // Misaligned buffer -> crash
        result = SD_write(sdcard_handle, buffer+1, 0, 1);
        if(result != SD_STATUS_SUCCESS) {
            Display_printf(display, 0, 0, "Failed to write to SD card, error=%d\n", result);
        } else {
            Display_printf(display, 0, 0, "done\n");
        }
    }

    and call it as sdcard_test(display, sdHandle); right after the "Display capacity information" block in sdraw.c and execute it on a Lanchpad with Booster-Pack: The aligned write always succeeds (provided that the address is actually aligned) and the unaligned write fails.

    Note that the remaining code of the example typically won't work after the the test code above has failed.

    Interestingly we observed two different failure behaviors: sometimes the call would just hang forever, other times we eventually (after ~10 seconds) got an SD_STATUS_ERROR response.

    Could you please confirm the issue on your hardware? Any help in resolving this issue is highly appreciated.

    Thanks!

  • Hi,

    Thanks for performing those tests with the sharp128 boosterpack.

    I'm currently having some setup issues with my sd card setup, so am not able to test out your code right away.

    If you suspect that the SimpleLink SDK might be the root cause of the bug, you can perhaps try the raw SDhost example from the CC3200 SDK. That SDK was written before the SimpleLink SDK, so we can see if that changes the behavior you're seeing.

    https://www.ti.com/tool/CC3200SDK

    Once you have that installed, import and build the sdhost example. It is a very basic sd access example, that you can use to test with. A couple of notes:

    1. Check pinmux.c to ensure your pin configurations are the same as what you're using for the CC3235 example. By default, they should be the same.

    2. You cannot directly flash the generated binary. Instead, you will need to manually load the generated .out to the CC3235 using the debugger. You can do so like so:

    1. Use View->Target Configurations to open the target configuration pane, then navigate to one of your CC3235 projects, right click and click on "Launch Selected Configuration". You should see the debug view launch, but not have any binary get loaded.

    2. Use Run->Connect Target to get the debugger to connect to the CC3235 using JTAG. Then, use Run->Load->Load Program to open the binary load menu. From there, click on Browse project, go to the CC3200 sdhost example and then select the built sdhost.out

    From there, click OK and it will load the CC3200 binary to your CC3235. Then, you can click on the Resume button as per usual to run the program. As the CC3200 and CC3235 share the same ARM Cortex M4 core and hardware peripherals, it should run without any compatibility issues.

    Let me know if the sdhost example works for your unaligned writes, or if you encounter the same issue.

    Regards,

    Michael