MMC_SPI - Reads but won't write

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • MMC_SPI - Reads but won't write

    This problem really has me stumped.

    I'm using emFile to interface a NAND flash and SD card on my own hardware. The NAND works perfectly, no issues.

    The SPI MMC/SD is another issue. If my application allowed, I could probably stream a MP3 off of the SD card, but I can't seem to write to it. Yes, I have checked that the card is not write-protected.

    This is what emFile is reporting:
    FS error: MMC_SPI: _WriteSectors: Data not accepted.
    FS error: MMC_SPI: _WriteSectors: Data not accepted.
    FS error: MMC_SPI: _WriteSectors: Command not accepted.
    FS error: MMC_SPI: _WriteSectors: Command not accepted.
    FS error: LOGBLOCK: Failed to write sector(s): 0x000080FD-0x000080FD to "mmc:0:".

    After this, the card is not accessible. For example, I can't do a directory listing. I have to remove the card, and re-insert it into the holder to gain access again.

    These errors were obtained when I ran the sample code that just writes a simple text file. The file creation is successful, but the file is empty.

    Some board specifics:
    STM32F303VE processor running at 72Mhz.
    (SPI3) SPI clock rate is 281khz as measured with a scope.
    emFile version V4.04a

    I have tried a couple different cards. Both had a FAT file system and when that didn't work, I formatted one of them to a FAT32 file system (didn't fix anything).

    Any direction would be helpful. I'm not sure where to look.

    Thanks,
    Dave
  • Hello Dave,

    We are not aware of this behavior.

    The error messages suggest that the SPI data transfer is not working properly.
    I suggest you to check first if the SPI controller is correctly configured:
    - Data is sampled on the rising edge of the clock signal.
    - The clock signal is HIGH in idle state.
    You can find more information in the section "6.5.8.1.8 (*pfWrite)()" of the emFile manual.

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • [SOLVED] but I can't explain it... very well.

    The code I used to send multi bytes of data to the MMC/SD card:

    Source Code

    1. /* Check flags to make sure SPI is idle */
    2. SPI_WAIT(SD_CARD_SPI);
    3. do {
    4. /* Send byte of data */
    5. SPI_SendData8(SD_CARD_SPI, *pData++);
    6. /* Wait for SPI complete send */
    7. SPI_WAIT(SD_CARD_SPI);
    8. /* Read data register */
    9. (void)SPI_CARD_SPI->DR;
    10. } while (--NumBytes);
    Display All


    Looks reasonable, right? Except, remember that the data register is a 16-bits in the STM32F303 (and others).

    When I change the code to this:

    Source Code

    1. /* Read data register */
    2. SPI_ReceiveData8(SD_CARD_SPI);

    Everything works great. The call to function only reads 8-bits from the register and not 16 like I originally had. Again, it works but I can't really explain why reading the "throw away" data differently makes it work.

    Credit given to Tilen Majerle for his SPI code that I adapted.

    Thanks for the response. You were right... it was in the pfWrite code, but not how I imagined it would be.

    Dave