TomDDG / ZXPicoMD

Raspberry Pico ZX Spectrum Microdrive Hardware Emulator
GNU General Public License v2.0
59 stars 5 forks source link

SD card issue #12

Open kgbplus opened 4 months ago

kgbplus commented 4 months ago

The device is working except reading SD card. It can detect when a card is inserted or removed but can't read it (it displays an sd card picture with a cross). To check wiring I installed Circuitpython and uploaded this code:

import sdcardio
import board
import busio
import os
import storage

spi = busio.SPI(board.GP18, board.GP19, board.GP16)
sd = sdcardio.SDCard(spi, board.GP17)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')

os.listdir('/sd')

It can read my sd card, but the device's firmware can't. I may be using an incorrect SD card. What could cause such issues?

TomDDG commented 4 months ago

This could be the card detect pin. Have you used the adafruit micro sd card reader? My firmware checks this pin to ensure a card is present and will show the x symbol if not. So even though all ok if the detect signal is missing it won't work.

kgbplus commented 4 months ago

It seems it is a detect pin! When I tried to debug it, I reproduced the schematic on the breadboard and noticed that it started working when I disconnected DET wire. I am using not the original SD card breakout board but some clone from aliexpress. Could you please tell me - what is the expected behavior of DET signal?

TomDDG commented 4 months ago

The gpio is high if card present

kgbplus commented 4 months ago

Thanks! Now I found that the DET signal on my SD card board is inverted (it is low when card is inserted and high when not inserted). Is it possible to build a firmware with inverted logic?

TomDDG commented 4 months ago

Yes I can will upload at the weekend

NuClear235 commented 3 months ago

My SD card module has it inverted too, but I added inverting transistor to stay compatible with original firmware.

NuClear235 commented 3 months ago

Or isnt possible to add another PICO pin using where will be reading of this inverted signal? Then would be possible to choose what SD reader will need. One pin normal, second pin inverted… Firmware will stay universal.

TomDDG commented 3 months ago

I'm wanting to add an ability to flip the pin and keep the firmware common. I'm thinking pressing and holding a button when that x screen shows to flip the pin and then saving that to the flash.

kgbplus commented 3 months ago

I would appreciate any solution that doesn't require me to produce new pcb

NuClear235 commented 3 months ago

Nice idea, Tom.

TomDDG commented 3 months ago

I've uploaded a test firmware with the pin inverted, can you please test it and let me know. If all ok I'll look to add the more sophisticated option

https://github.com/TomDDG/ZXPicoMD/blob/main/UF2/zxpicomd_v1.7_invertcarddetect.uf2

kgbplus commented 3 months ago

WIN_20240803_13_16_24_Pro I checked this firmware and now everything is working! Thanks a lot!