greiman / SdFat

Arduino FAT16/FAT32 exFAT Library
MIT License
1.08k stars 509 forks source link

SD NAND XTSD01G (surface mounted chip) not formating #476

Closed fepalmytho closed 8 months ago

fepalmytho commented 8 months ago

Hi Greiman, First of all, thanks a million for all the work you've done on this topic. I come back to you as i face a "tiny "problem with a project i've made (based on ESP32-S3). It used to work with an SD card, where i read and write datas.(big datas, so SPIFFS was not enough in case you ask). I wanted to avoid SD cards for vibrating/mecanic reliability, so i ended using this SD NAND (1Gbit): https://www.lcsc.com/product-detail/NAND-FLASH_XTX-XTSD01GLGEAG_C558837.html So it's a surface mounted chip that acts as an SD card, soldered in my PCB (you for sure know this, but i specify it for other readers). I send data to the SD nand via a FTP server (as i can't plug it directly to the computer as an usual SD card). It works fine, but time to time, the SD fails (specially when i "stress" it, like asking readings frequently). I've tried different settings, like changing the frequency, or delaying readings, but still, the SD crashes and is then "unmounted". Even if in the code i try to mount it again (Sd.begin), i can't. I need to reset the ESP32, so unpower the SD nand, to make it work again. I've been investigating for days without finding a solution, and i decided to come bakc to basics: How this SD nand is formatted? What if this SD is corrupted? So i decided to format it properly and landed on your post.

I've managed to make it (the code) work, but i think there is something wrong:

1/ The outcome is always "dataAfterErase: ones": (after check with my FTP server, i can see that files still exist).

init time: 176 ms

Card type: SD2 sdSpecVer: 2.00 HighSpeedMode: true

Manufacturer ID: 0XB OEM ID: XT Product: XTSDA Revision: 1.1 Serial number: 0X26EE1E58 Manufacturing date: 9/2023

cardSize: 127.93 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks eraseSingleBlock: true dataAfterErase: ones

OCR: 0X80FF8000

SD Partition Table part,boot,bgnCHS[3],type,endCHS[3],start,length 1,0X80,0X1,0X1,0X0,0X6,0XFE,0XFF,0XFF,234,248342 2,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0 3,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0 4,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0

Scanning FAT, please wait.

Volume is FAT16 sectorsPerCluster: 4
fatStartSector: 250
dataStartSector: 768
clusterCount: 61952 freeClusterCount: 61615

type any character to start

2/ And also, when i launch serial monitor again, i get (initialization failed): So i need to unplg/plug it again to come back to first behaviour above). And that makes me believe that when i "stress" the SD NAND, or something goes wrong, it crashes and is unable to mount again.

SdFat version: 2.2.0

Assuming the SD is the only SPI device. Edit DISABLE_CS_PIN to disable an SPI device.

Assuming the SD chip select pin is: 10 Edit SD_CS_PIN to change the SD chip select pin. Done

type any character to start

SD initialization failed. Do not reformat the card! Is the card correctly inserted? Is there a wiring/soldering problem?
Is SD_CS_PIN set to the correct value?
Does another SPI device need to be disabled? SD errorCode: SD_CARD_ERROR_CMD8 = 0x6
SD errorData = 0x20

type any character to start

What do you think i should do to make it reliable? Thanks a million for your time and precious skills! Frederic.

greiman commented 8 months ago

What do you think i should do to make it reliable?

I have no idea. I can't even guess what's happening.