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

ESP32-S3, reading files on SD Card through USB #129

Open RodEnry opened 1 year ago

RodEnry commented 1 year ago

Hello @chegewara, thanks for your great library. I'd like to get some clarifications because I can see a lot of examples and I'm a bit confused.

I have an ESP32-S3 which is connected to a micro SD card module via SPI. The library used for the SD is SdFat 2.

My goal is to access the files contained in the SD card by connecting the ESP32 to a PC via USB, exactly like an USB stick does. Which is the max speed obtainable when downloading files?

Cheers Enry

chegewara commented 1 year ago

Hi, it may be between 500-800kB/s.

RodEnry commented 1 year ago

@chegewara thanks! In order to reach my goal, I'll need to use the Host MCC example?

Cheers Enrico

RodEnry commented 1 year ago

Hello, I don't know why but I can't access to the mass storage from the PC. I can see this popup:

image

Any idea? Cheers Enry

chegewara commented 1 year ago

Host example is to connect pendrive to esp32.

This error may be due to timeout, because of low transfer speed of USB from esp32.

fepalmytho commented 7 months ago

Hi @RodEnry, i've been looking for days to find a way to do exactly the same than you. Make my ESP32-S3 appear as an USB stick, and reach by this way my SD CARD while connected to the PC (my SD card is a nand by the way, but connected and working as an SD card perfectly). I would like to know if you can share with me your code, and if you managed to make it work properly. I'm trying to make the sd_msc.ino code work, but i'm stuck with libraries missing, my knowledge is quite poor about how to set that and feed the correct information to visual studio code. For example, in the code, i had to comment #if CFG_TUD_MSC, as it makes me errors. I don't know what's the purpose of this line... Thanks a million, Frederic

RodEnry commented 7 months ago

Hi @RodEnry, i've been looking for days to find a way to do exactly the same than you. Make my ESP32-S3 appear as an USB stick, and reach by this way my SD CARD while connected to the PC (my SD card is a nand by the way, but connected and working as an SD card perfectly). I would like to know if you can share with me your code, and if you managed to make it work properly. I'm trying to make the sd_msc.ino code work, but i'm stuck with libraries missing, my knowledge is quite poor about how to set that and feed the correct information to visual studio code. For example, in the code, i had to comment #if CFG_TUD_MSC, as it makes me errors. I don't know what's the purpose of this line... Thanks a million, Frederic

Hello @fepalmytho, in the end I was stuck with some issues. I'm very interested in this topic. Maybe we can share the code or try to handle this?

Are you using this one? https://github.com/chegewara/EspTinyUSB/tree/master/examples/device/msc

Let me know RodEnry

fepalmytho commented 7 months ago

Hi @RodEnry , Glad you're still interested in solving this problem, and so glad that i'm not "alone" to try to do something i guess "so basical"... I'm quite surprised that something so "obvious" is not documented somewhere on a tutorial on Internet... So, first of all, i don't have any code (for now) to share, as i'm just starting my researches. Just to understand my goal, lets explain in a few lines my project. I'm creating an "instrument" with a display. This instrument show informations, and i need to store them inside this project, as i don't want any wifi, bluetooth, GSM or whatever external connexion. I want this instrument to be totally autonomous. So i decided to store data, a lot of data (as .txt files). I took the ESP32-S3 as it has a lot of SPIFFS memory, but not enough. I've tried to implement a chip called Winbond W25QXX, but after researches, i was unable to make it work. Problems with libraries, and must of all, i was limited by my skills. It seems to be that you can't read and write on this chips like an SD card, you need to write by « bites » or even more complicated, well, it was really not a plug and play device, and really not userfriendly. So i decided to come back to an SD card (using an SD card Shield), which has a lot of capacity, and so easy to use with the dedicated code (library). But i didn’t like 2 things : First, it’s so vibrating sensitive, that sometimes i had to plug and unplug the SD card to make it work. If not, i had times to times the message « card failed » or « not mounted ». Well, i could not use it like this. (I’ve tried to solder the SD card directly to a prototype PCB, but i twas uggly, not reliable as my soldering skills are not as robots, and even more, as far as i understood, it was impossible to make it communicate directly with the ESP32 via some (a lot of) GPIO pins, and i had absolutely need of the card shield). Secondly, using a card shield, i didnt like the fact that a user could open the instrument, take away the SD card and plug it on a computer and see my data. So i’ve found an SD NAND chip (the XTSD04GLGEAG), which is connected as the SD card Shield (MISO, MOSI, CS and CLK pins). This chip is really tiny, has a lot of capacity, and react as an SD card with the same libraries (tested and approved). So now, here is where i’m starting to look for solutions to upload my files to this chip, in a easy way. But be reassured, all my thoughts are exactly the sames using an SD card with a shield, as it seems to be your goal too. I cannot unplug the chip and wire it to an USB cable to connect it directly to a computer. (Well at least i didnt find any information about this way). So i decided to create a code that makes work in paralell an SD Card, and my Chip. So i could transfer my data on the Sd card from the computer, and then via the code, copy paste all the files to the chip. I know that it’s possible, but not user friendly, so i « paused » this way. Second option, was to make the ESP32 appear as an USB mass Storage, and i found this famous TinyUSB code (the one from Chegewara that you’ve mentionned). It didnt work for 2 reasons: First one, because it was looking for a library #include "sdusb.h", that i had to find in his files on github, and this library was looking for another, that i had to add, which was looking for another etc…it was abyssal and endless. And still showing code errors. The second one, was that there was this condition #if CFG_TUD_MSC, which i absolutely don’t know what is for. I guess, like many other codes tested, that if for helping setting regarding the MCU used ?!. But as soon as i don’t comment this line, all my code is grey. But even commented, i was struggled by the libraries. Well, i decided to forget this code. So today, i’m trying to understand this page : https://www.reddit.com/r/arduino/comments/w4o8wn/esb32s3_nand_sd_storage_usb_msc_arduino_that/ And this one : https://github.com/frankcohen/ReflectionsOS/blob/main/Devices/Hoober/Software/07USBFlashDrive/07USBFlashDrive.ino I come back to you if i can move forward in any way. If someone else reads thoses lines, we are more than happy to get help ! Frederic.

chegewara commented 7 months ago

Sorry for no responding, but currently this library is on hold. I am overworked and the library seems to be not popular.

In the near future i will focus on some crypto AI app, which gives me $2000 a day with no risk and im not sure i get back to this library. Again, sorry for that.

fepalmytho commented 7 months ago

Hi, Thanks for updating us. So we are looking for other options. Good luck with your no risk API. Fred.

fepalmytho commented 7 months ago

Hi @RodEnry , I've been spending almost the entire day trying to make my SD card appear as an USB mass storage. With no luck. (but i have a solution, for me, here later). It's written on the first link i gave to you (reddit): "Unfortunately, Adafruit_TinyUSB does not compile under the ESP32-S3. " And it was supposed to be solved by their work "This sketch makes their idea work on an ESP32-S3-Mini-1". It's also needed to sold an USB cable to 2 GPIO in order to make the connexion directly to the computer. I've created such a wire, but libraries were always stucking me... And also, i didnt find a way to set the GPIO as i wanted. There was nowhere specified were to set the GPIO 19 and 20 as DATA lines for the USB wire, and also no where specified how to set the GPIO you want to use with your SD card shield. It could be the ideal solution, but i failed. And i still wonder why no one, "if it works so well", did a nice tutorial to solve this... It seems to be "so easy"... I was fed up, and i decided to come back to an FTP server that i tried to use to reach the internal memory of the ESP32 (called the SPIFFS). It was working well, and i was able to drag and drop files. My idea was to "target" the SD card, and not the SPIFFS. And i managed to do it. Send me your email address so i can send you the code and also explain what to modify for you, as it's not related to this topic. I know that it's not what you're looking for, but it's an easyway to drag and drop file in the SD card. You will need filezilla or any FTP server and some set up in the code. Regards, Fred.