chegewara / EspTinyUSB

ESP32S2 native USB library. Implemented few common classes, like MIDI, CDC, HID or DFU (update).
MIT License
473 stars 70 forks source link

sd_mscerror #138

Open 755516538 opened 1 year ago

755516538 commented 1 year ago

Hello, I encountered an error when using the tinyusb example "sd_msc.ino". An error will occur if the file size of the SD card exceeds 512 bytes. Can you teach me how to repair it

chegewara commented 1 year ago

Hi, i dont understand what problem do you have, sorry. If you describe it more, maybe i can help.

755516538 commented 1 year ago

Thank you for your reply. Preparation for problem recurrence: 1.esp32s3

  1. Text file larger than 512 bytes (000.txt) 3.sd_ Msc sample code Step:
  2. Modify the example to read and write the SD card correctly.

    define SD_ MISO 37

    define SD_ MOSI 39

    define SD_ SCK 38

    define SD_ CS 40

  3. Burn the program to esp32s3
  4. Copy "000. TXT" to esp32disk.
  5. Unplug the esp32 and disconnect it from the computer
  6. Insert esp32 into the computer and connect it to the computer, and open the USB flash drive
  7. Open "000.TXT" in the USB flash drive, and some contents of the file are lost. image
chegewara commented 1 year ago

Its because you did not unmount device under system properly. Im not sure, but this small snippet in your .ino may help to fix it:

#include "ff.h"
#include "diskio.h"
void tud_msc_write10_complete_cb(uint8_t lun)
{
    if (disk_ioctl(0, CTRL_SYNC, NULL) != RES_OK)
    {
        Serial.printf("failed to sync\n");
    }
}

PS you also has to make sure all data are transferred to esp32 before you unplug it

755516538 commented 1 year ago

Ok, thank you very much for your help