Can anyone tell me what the correct values for using the sd-card on the pico demo board are?
I have a FAT32 formatted sd-card, that has been tested and works in 2 other LCD screen sd-cards (using different GPIO values) and I can read/write and list the files/folders.
Using the same code with the pico demo board, all I get now is ‘bad SCK pin’.
I’m looking for something that maps:
SD_CLK : (GPIO 5)
SD_DAT3 : (GPIO 22)
DAT2 : (GPIO 21)
DAT1 : (GPIO 20)
DAT0 : (GPIO 19)
CMD : (GPIO 18)
Hi, yes, I did a bit more logical deduction last night using that layout and determined that it should be:
CS = GPIO5 or GPIO22 - get same response
SCK = GPIO18
(If I set the following two to any other value the MicroPython library quite nicely tells me I am wrong)
MOSI = GPIO19
MISO =GPIO20
I really don’t want to have wasted £20 on a pico demo just so I can have VGA - pretty pointless if I cannot get the sd-card working with it. There must be something “simple” I am missing here?
I checked the wiring and I’m sure now that the SD-card is wired not for the SPI interface, but the SDIO interface. I have no experience with that, until now I only used SPI (including carlk3’s implementation). I found this link Pico w/4-bit SDIO interface example? - Raspberry Pi Forums, but I’m not sure if this helps.
Just a small update:
I was doing some random digging & I can confirm that the actual values are:
SCK: GPIO18
CS: GPIO22
MOSI: GPIO19
However, I still get the “SD Card not found” error… I was doing this as a “quick test” using MicroPython - just to make sure that I could read the sdcard from the device.
no worries! I’ve been doing a lot of that recently with this. Am open to all / any suggestions.
I’ve just hacked up some waveshare C code that accesses the sdcard on their 2.8" touchscreen - am basically removing all references to the LCD display… am nearly there. I have that code successfully accessing the sdcard on that device (the previous mentioned code ‘no-OS-FatFS’ was failing to access this sdcard too).
However, I now have a list of files being output and I can navigate into sub-folders and list them too, so some success on the waveshield device!
I’ll look to clean this code up and then see if I can move it over to then try it on the pico demo board… just have to change the config PINS… in theory…
I still don’t think that you will be able to access the SD-card on the pico-demo with SPI. According to the pinout on the product page, SD-CLK is wired to pin7, i.e. GP5, which is not a SPI clock-pin on the pico.
You are claiming that GPIO18 is SPI-SCK, but that pin is wired to SD-CMD (where you expect MOSI in SPI-mode).
I dug a bit deeper and whilst doing cmake I pass it the board type:
cmake -D"PICO_BOARD=vgaboard" … (not sure why that shows as 3 dots - should be 2)
which led me to find this file:
/opt/pico-sdk/src/boards/include/boards/vgaboard.h
that defined these values:
// Note DAT1/2 are shared with UART TX/RX (pull jumpers off header to access
// UART pins and disconnect SD DAT1/2) #define VGABOARD_SD_CLK_PIN 5 #define VGABOARD_SD_CMD_PIN 18 #define VGABOARD_SD_DAT0_PIN 19
and I was using SD_CS PIN 22 in my C code and spi1.
Using these values I still cannot get it to initialise from C/C++,
SD card mount file system failed ,error code :(3)
so maybe you are right… it might not be SPI?
In which case, are there any c/c++ examples out there that access the sd-card on the pico demo board? I cannot seem to find anything.
I did find an example of someone using the pico dvi board (hdmi version) and their code doesn’t seem to do anything smart with the sdcard, so I’m a bit baffled - did I just get a broken board and I’ve been chasing my tail all along?
I think you found the correct link (I failed). If you look at the source code, they implement SPI using PIO, i.e. they don’t use the hardware-spi function-blocks of the pico, but implement their own PIO-version. That’s why it is not relevant that the SD-CLK is not connected to a pico-spi-clk pin. You will find the code in the drivers/sdcard subdirectory.
So the next step for you would be to try to integrate that code into your project. Would be great if this works.
okay… I need bigger brains than I’ve got to figure this one out.
I’ve uploaded the code to here:
It contains the libraries grafted into a super-simple app that attempts to initialise and mount the sdcard for the Pico demo VGA board.
I’ve pasted my debug output into the sdcard_test.c file, but will reproduce it here:
SDCARD_TEST.C: system init response=0
SDCARD_TEST.C: SDCARD_SPI_BUS=1073987584
SDCARD_TEST.C: SDCARD_PIN_SPI0_CS=22
SDCARD_TEST.C: SDCARD_PIN_SPI0_SCK=18
SDCARD_TEST.C: SDCARD_PIN_SPI0_MOSI=19
SDCARD_TEST.C: SDCARD_PIN_SPI0_MISO=20
SDCARD_TEST.C: SDCARD_PIO=1344274432
SDCARD_TEST.C: SDCARD_PIO_SM=0
SDCARD_TEST.C: Let’s try to mount the SDcard
FF.C: inside f_mount about to call mount_volume
FF.C: about to call disk_initialize from within mount_volume
SDCARD.C: about to call init_spi() here, I think I was called by FF.C: mount_volume
SDCARD.C: we should be executing the PIO code here
SDCARD_TEST.C: SD card mount error: 3
SDCARD_TEST.C: sdcard_success=0
SDCARD_TEST.C: Bugger an error happened…again…
I put the filename on the front of the printf’s so I could trace through the logic of the code and make sure it was working as I thought it was. From what I can tell, it is indeed going through the correct steps… but still failing anyway.
I’ve tried with:
cmake …
make
and with the board specified:
cmake -D"PICO_BOARD=vgaboard" …
make
that doesn’t seem to make a difference.
I’ve tried changing from sp1 to sp0, just incase it is on the first device, done the same with pio1 and pio0 - same result.
Maybe I have a typo / assumption somewhere that is blazing obvious to someone else? but I think I’ve now tried everything I can to read an SDCard using the Pico demo VGA board, without success :-(
The good news is… I don’t think the GPIO PIN settings is the problem :-D That appears to be okay.
I still have to figure out the other pins, they are labeled SD_DAT0-SD_DAT3 in the shop. But I somewhere have a SD-pinout which labels all the pins in both ways, so give me some time.
SDCARD_TEST.C: system init response=0
SDCARD_TEST.C: SDCARD_SPI_BUS=1074003968
SDCARD_TEST.C: SDCARD_PIN_SPI0_CS=22
SDCARD_TEST.C: SDCARD_PIN_SPI0_SCK=5
SDCARD_TEST.C: SDCARD_PIN_SPI0_MOSI=18
SDCARD_TEST.C: SDCARD_PIN_SPI0_MISO=19
SDCARD_TEST.C: SDCARD_PIO=1345323008
SDCARD_TEST.C: SDCARD_PIO_SM=0
SDCARD_TEST.C: Let’s try to mount the SDcard
FF.C: inside f_mount about to call mount_volume
FF.C: about to call disk_initialize from within mount_volume
SDCARD.C: about to call init_spi() here, I think I was called by FF.C: mount_volume
SDCARD.C: we should be executing the PIO code here
SDCARD.C: pio_spi_init executed
SDCARD_TEST.C: Mounted OKAY!
SDCARD_TEST.C: Current directory is: /
SDCARD_TEST.C: sdcard_success=1
SDCARD_TEST.C: Woo!hoo! party time
i can only access the sd card successfully using the library that waveshare provides. I think the two boards have similar pinout, but i get a
…
SDCARD_TEST.C: SDCARD_PIN_SPI0_CS=22
SDCARD_TEST.C: SDCARD_PIN_SPI0_SCK=5
SDCARD_TEST.C: SDCARD_PIN_SPI0_MOSI=18
SDCARD_TEST.C: SDCARD_PIN_SPI0_MISO=19
…
SDCARD_TEST.C: SD card mount error: 3