SD card problem with custom rp2040 `pico` - Page 1
Forum section: electronics / general

author: Sniper1
author_rank: Regular Contributor
timestamp: October 24, 2022, 01:21:07 pm
content: So i more or les copied the rpi pico and made it to work it boots normally and runs basic code ok, i tested it with an DHT11.So i know it works well BUT here is my problem : I cant get the SD card to work.I tried all combinations of SD lib and RP2040_SD libs with both the card holder i built in and an external break out ( with this one even with another SPI bus)atm i am out of ideas.Here is a folder with all my attempts:https://github.com/immortal-sniper1/RP2040_basic_board/tree/main/SWNOTE: SD card is working well on PC and is formatted as FAT (it is 2GB so i expect no problems due to size)

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 24, 2022, 01:30:23 pm
content: Try:https://github.com/khoih-prog/RP2040_SD

author: Sniper1
author_rank: Regular Contributor
timestamp: October 24, 2022, 01:33:15 pm
content: Quote from: DavidAlfa on October 24, 2022, 01:30:23 pmI just did 20 min ago and it failed to detect the card or communicate with it both on the in built one , the same pins but with external adapter and on another set of pins.It is the _alt_lib files in my git

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 24, 2022, 01:51:27 pm
content: How are you connecting the card?Seems like something might be wrong?Avoid long wires, will mess up high frequencies.Remember card DI goes to MCU DO, and so on!Card DI=MOSI, DO=MISO

author: Sniper1
author_rank: Regular Contributor
timestamp: October 24, 2022, 02:05:43 pm
content: Quote from: DavidAlfa on October 24, 2022, 01:51:27 pmYES i was careful there when designing the embedded partwhile for the break out part i just followed the writing on the PCB

author: Sniper1
author_rank: Regular Contributor
timestamp: October 24, 2022, 04:34:52 pm
content: So i did another round of tests the SD card and breack out are fine since they worked well with an arduino so i can say all the problems are from the rp2040 code

author: WillTurner
author_rank: Regular Contributor
timestamp: October 25, 2022, 01:18:53 am
content: I'm also currently working on SD card issues.Testing across different software platforms has helped. I know that the hardware works with a FAT filesystem using Peter Mather and Geoff Graham's MMBASIC, but can't get it running under micropython. Micropython doesn't object to calls to mount the card, but it isn't - a copied file ends up in the 1.4MB flash filesystem. This is complicated by learning python at the same time as trying to debug the SD Card setup.More to follow when I get to the bottom of it.Edit: Swapped out the micropython Pico from my board, replacing it with another Pico, and flashed Picomite MMBasic V5.07.03 to it. Following configuration, I can read and write to a "DSE 60x Secure DIGITAL 256MB" card, partitioned using linux fdisk, with one primary 32MB partition, and formatted as FAT16 with linux mkfs. I think Peter and Geoff used Chan's file system implementation? Very curious. Maybe I'm doing it wrong in micropython, or expecting too much?

author: Sniper1
author_rank: Regular Contributor
timestamp: October 25, 2022, 05:32:34 pm
content: OK so i tried to use VS code with the SDK directly and failed to compile.Then i installed platform IO and it did compile and also i used rp2040_SD lib and it failed , againI also tried with the external adapter and another set of SPI pins

author: paulca
author_rank: Super Contributor
timestamp: October 26, 2022, 10:01:52 am
content: Might be worth tripple checking your schematic for the board.Check the pins for example, with a scope. If you don't have a scope set the relevant pins up as GPIO blinkies to make sure they are wired as you expect.It's so easy to make a mistake on a schematic and IDEs will not check the circuit is sane. If your first PCBs are good you are very, very lucky. Areas to check more heaily would be in any self-made components and foot print. Swapping a pin on one component in a schematic is a classic fail.

author: Peabody
author_rank: Super Contributor
timestamp: October 26, 2022, 02:27:24 pm
content: Could there be a power problem? Are you connecting the SD card's Vcc directly to pin 36 (3.3V out), with no voltage regulator or translation on the breakout board?Well, I'm just guessing, but in any case there are a number of Youtube videos on using an SD card with an RP2040 pico, covering both hardware and software, including one by Digikey.

author: MikeK
author_rank: Super Contributor
timestamp: October 26, 2022, 05:25:33 pm
content: Wasn't clear to me if this is using a bare SD card socket or an SD card module. Some modules have a level shifter, and many of those incorrectly run MISO through the level shifter which prevents that line from floating. As mentioned, making sure everything is connected properly is, of course, important. A carefully drawn schematic of the circuit being used would be helpful.

author: Sniper1
author_rank: Regular Contributor
timestamp: October 27, 2022, 06:43:51 pm
content: Quote from: paulca on October 26, 2022, 10:01:52 amI did and i saw no mistakes or at least i didnt see any ( well the mistake i made and i know i made is the orientation of the SD card holder but the pins are in the correct way.Time for blinks i guess

author: Sniper1
author_rank: Regular Contributor
timestamp: October 27, 2022, 06:53:51 pm
content: Quote from: Peabody on October 26, 2022, 02:27:24 pmthe breack out i use has caps and its own LDO and on my board the SMPS is built for 500mA so i think power is not a problemThe guy that does the digikey video uses the SDK directly and i failed to set that up but i can take another look ( for the 5+ time)

author: Sniper1
author_rank: Regular Contributor
timestamp: October 27, 2022, 06:55:45 pm
content: Quote from: MikeK on October 26, 2022, 05:25:33 pmit is BOTH since this way i rule out my circuit problemsRP2040 is 3v3 logic so no need for LVL shifting

author: Peabody
author_rank: Super Contributor
timestamp: October 28, 2022, 01:42:06 am
content: So you are feeding the 3.3V LDO on the breakout board with 5V from somewhere? I just want to be sure you aren't feeding it with 3.3V, which is what I believe the SMPS produces.

author: Sniper1
author_rank: Regular Contributor
timestamp: October 28, 2022, 11:16:15 am
content: Quote from: Peabody on October 28, 2022, 01:42:06 amwhen it comes to power i am sure i am doing it right

author: DavidAlfa
author_rank: Super Contributor
timestamp: October 28, 2022, 11:44:59 am
content: I don't think this is the proper place to discuss this.Go to Arduino forum, you'll find lots of other people with the same board, probably ran into the same issues.

author: WillTurner
author_rank: Regular Contributor
timestamp: October 29, 2022, 02:25:38 am
content: Quote from: WillTurner on October 25, 2022, 01:18:53 amWell, I have just managed to solve my issue. As far as diagnosing these things, it took me to the pits of despair. Don't forget that these problems cross all of the boundaries :- hardware, firmware, development environment, running environment, user software, the card itself, formatting, et cetera. No wonder it's hard. So the lesson to be learned in the immortal words of Commander Taggart is "never give up, never surrender!".I for one would like to know what the OP's solution was, when they get to the bottom of it all. As for my problem, in my code I called the mount pointCode:"sd"instead ofCode:'/sd'.

author: Sniper1
author_rank: Regular Contributor
timestamp: October 29, 2022, 07:32:15 am
content: Quote from: DavidAlfa on October 28, 2022, 11:44:59 amI already asked on reddit and rpi forum and not much in terms of results there was a post with some off TX RX as SPI pins i tried it and it wont even compileone of my mai problems in the may layers of abstractions happening :rp2040 sdk in arduino coreSPI libSD libAlso regarding the board i used pico in `` since it is essentially a pico but it is custom designed by me , but i can try asking there tooalso now that is it week end i can start testing pin by pin with a LED

author: Sniper1
author_rank: Regular Contributor
timestamp: October 29, 2022, 10:35:02 am
content: So i did a blink test on some of the pins and not all workedAnd since at lest one is part of SPI then it makes sense why it is not working well (or at all)In a way this in unexpected since i looked closely for the lines to be properly connected , not sure what would be the best test method to avoid problems like these in the future) maybe make a 10 led + resistor inline array?PS and since it is a semi crammed board i am not even sure how will i be able to rework that area , maybe with a I tip and some flux? Inspection is the real problem

author: rstofer
author_rank: Super Contributor
timestamp: October 29, 2022, 01:15:51 pm
content: When possible, I put 330 Ohm resistors in series with every GPIO. The value is low enough that it doesn't affect downstream devices and high enough to limit current to a safe value even when shorted. On fast edges, the resistor helps prevent reflections.

author: MikeK
author_rank: Super Contributor
timestamp: October 29, 2022, 01:45:42 pm
content: I think I bought my Salae clone logic analyzer specifically to debug an SD card comm issue some time ago. I got this one, but they can be purchased for even cheaper:https://www.amazon.com/gp/product/B077LSG5P2/

author: paulca
author_rank: Super Contributor
timestamp: October 30, 2022, 11:21:36 am
content: Quote from: MikeK on October 29, 2022, 01:45:42 pmYes, they work.OP don't feel bad about wasting days and finding it the simplest error ever.I spent 3 hours last night diagnosing a non-responsive SPI slave TFT screen. I went through the code, I break pointed interrupts, I stepped through it, nothing. All working. Then I scoped the SPI lines and... having a very cheap 100Mhz scope and a 40MBit/s SPI I wasn't sure if I was seeing a data burst or a ringing gate! Turns out it was the later. (The ringing is from the MCU waking out of sleep on the 1Hz RTC signal.)I brought out the logic analyser and after fighting with it for 30 minutes I figured out it changes it's device name when the PulseView device scanner scans it and being in a VM this means you have to set your USB device filters carefully. Got it working and could see, from the looks of it a nice binary SPI master transfer every second as I should!Eventually I figured it out. While the STM32 PA6 pin is directly aligned with the Arduino Nano pin A6 and indeed PA1 was aligned with A1.... the other pins do not go in order. PA2 is not on A2 etc. 3 minutes with the proper pinout and bingo, it all suddenly worked.Similarly the night before I spent the entire afternoon and evenings work writing an STM32Hal driver for the DS3231 , just for an exercise. It failed. It failed repeatedly. Nothing on the I2C bus. I scoped it, I Logic Analysed it and just could see what I expected. Checked connections, three times, all "fine". Gave up and went to bed at 2am.The next morning within 30 seconds of looking at the breadboard I spotted it. The breadboard jumper wire for GND was not connected to the RTC's GND pin. It was connected to the SDA pin. So I had a 47k pulling up the SDA line and a direct connect to GND pulling it down. That's your problem right there! Indeed. It fixed it. All I can say is I've been out of the hobby for a year or two and I had forgotten just how much the little simple things will screw you up, far, far, more times than the complicated things will. It pays to assume you are in fact an idiot and start from there.EDIT: Oh and the cheap ADS1014 100Mhz scope... I should have trusted it more. Once I had the SPI issue fixed on the board, I could see the SPI transmissions clear as day with a very sharp squarewave, with bandwidth to spare to show the gate artifacts (ringing/overshoots/undershoots).

author: Sniper1
author_rank: Regular Contributor
timestamp: October 30, 2022, 11:51:32 am
content: Update:So i wrote a program that reads serial data and blinks the appropriate pin.Then i proceed to test each and every single pin and they all worked well. + it also tested that the labels on the PCB are correct ( except that i forgot a GND label but there was no space there....)I also tested if the board resets if i have a battery and i unplug the USB and it does not ! yaySo that leaves me with the only other possible problem : the software. an area that i tired like 5 versions of code so here we go againDoes anyone happen to have a ready made pico SD card test program ? i am sure it is something small but i cant figure it out

author: WillTurner
author_rank: Regular Contributor
timestamp: October 31, 2022, 02:19:34 am
content: Quote from: WillTurner on October 25, 2022, 01:18:53 amIt's a quick process to flash MMBasic onto your pico device. If you do so, you can verify your hardware, confirming your premise that you have something incorrect in your Arduino implementation. The zip file downloaded from Geoff's website (an internet search away) contains a manual, and uf2 file. There are two versions, you probably want the Backpack version. Once you get to the MMBasic prompt via your terminal program of choice, the card is configured by (change the pin numbers appropriately)Code:OPTION SYSTEM SPI GP14, GP15, GP12which will cause a reboot,Code:OPTION SDCARD GP13which may also cause a reboot (can't remember). When you are set up, and back at the prompt,Code:FILESwill show the card contents.Edit: for clarity.

author: tabemann
author_rank: Contributor
timestamp: November 01, 2022, 12:07:20 am
content: Try it out with zeptoforth on the Pico:First install the latest zeptoforth UF2 file for the RP2040 with the usual USB Mass Storage Device method. You can get it athttps://github.com/tabemann/zeptoforth/releases/download/v0.46.4/zeptoforth-0.46.4.tar.gz. The UF2 file will be under bin/0.46.4/rp2040/zeptoforth_full-0.46.4.uf2 . Afterwards, start up zeptocom.js, which is online athttps://tabemann.github.io/zeptocomjs/zeptocom.html(note that this requires up-to-date Chrome, Chromium, Edge, or Opera; Firefox does not work with it, and nor do mobile browsers), click "Connect" and select your serial device you want to use, paste the text below (with modifications depending on which pins you are using and which SPI peripheral you are using) into the edit pane on the right of the screen, and then click "Send", which will download the code to the Pico and execute it. If all goes well, a listing of the root directory on your SD card (note that this must be an SDHC or SDXC card — old-style SD cards are not supported) will be listed (without long filename support) on the lefthand pane, which is a terminal displaying the output of zeptoforth.Note that the "2 3 4 5" below are the GPIO pins (using the GPIO, not the Pico, pin numbering - GPIO pin 2, for instance, is Pico pin 4) used for SPI to talk to the SDHC/SDXC card; the last pin must always be the Chip Select pin. The "0" right thereafter is the SPI peripheral you are using; this will depend on which GPIO pins you are using (seehttps://microcontrollerslab.com/wp-content/uploads/2021/01/Raspberry-Pi-Pico-pinout-diagram.svg). Also note that the Chip Select pin does not relate to which SPI peripheral you are using because the zeptoforth SDHC/SDXC layer drives the Chip Select pin directly rather than using the RP2040's built-in SPI peripheral to drive it.Code:oo importblock-dev importsd importfat32 importsimple-fat32 import<simple-fat32-fs> class-size buffer: my-fs<fat32-dir> class-size buffer: my-dir<fat32-entry> class-size buffer: my-entry2 3 4 5 0 <simple-fat32-fs> my-fs init-object: ls-root ( -- )<fat32-entry> my-entry init-objectmy-dir my-fs root-dir@beginmy-entry my-dir read-dir ifmy-entry entry-file? my-entry entry-dir? or if12 [:12 my-entry file-name@cr type space false;] with-allotelsefalsethenelsetruethenuntil;ls-rootEdit: Changed the code to properly ignore long file names (which previous produced blank entries).

author: tabemann
author_rank: Contributor
timestamp: November 01, 2022, 02:01:03 am
content: One thing to be wary of is SD card interface boards that are marketed as being for Arduino - I bought one (well it was in a pack of two), and it expected 5v VCC, but I had fed in 3.3v VCC from my Pico, and I had the hardest time getting it to work (it didn't). Then I realized I needed to feed in 5v VCC (even though the Pico provided 3.3v logic - this board was designed to convert between 5v logic and 3.3v logic) and it worked, but to be on the safe side I bought another pair of SD card interface boards, these being 3.3v only, for both VCC and logic, and they worked perfectly.One thing to note is you mention that your SD card is 2 GB - then it might not work with zeptoforth as it might be an old-style SD card rather than an SDHC or SDXC card (even though I'm surprised if you bought it new recently and it was such; my mother owns an expensive but kinda old camera that requires old-style SD cards and it is a pain for her to find them, because all the usual manufacturers today do not really sell them).

author: WillTurner
author_rank: Regular Contributor
timestamp: November 02, 2022, 01:28:54 am
content: Quote from: tabemann on November 01, 2022, 12:07:20 amAnother one! You are the author?So the list of RPi PICO platforms1isZeptoForthArduinoAssemblyC/C++ SDKFreeRTOSPicomite and VGA MMBASIC variantsmicropythonFuzixQuote from: tabemann on November 01, 2022, 02:01:03 amI like those old-style cards. Don't toss them out when you get a new camera, or phone, or whatever! Yes, they are getting hard to find. Although they take up board space, they are physically robust, and come with a physical write protect switch. A simple adapter allows micro-SD cards to be used. For me, a surprising discovery was that 256MB is about four times larger than necessary. In fact, a 32MB file system is pretty decent, especially if all you are doing is moving text files between boards. Which makes fuzix an interesting choice.Footnote: "Platform" to be defined, but it might be something like development environments that are capable of being used to implement some kind of operating system?Edit: "Platform"

author: tabemann
author_rank: Contributor
timestamp: November 02, 2022, 01:57:52 am
content: Quote from: WillTurner on November 02, 2022, 01:28:54 amYep! zeptoforth is an inlining native code Cortex-M Forth that supports the Pico (and other RP2040 boards with compatible Winbond flash), the STM32F407, STM32F746, and STM32L476 DISCOVERY boards, and the STM32F411 "Black Pill" (along with unofficial support for the STM32F411 Nucleo 64).Quote from: WillTurner on November 02, 2022, 01:28:54 amDon't forget Mecrisp-Stellaris! Matthias Koch et al (Jan Bramkamp did much of the work on the Pico port) have a very nice Forth there that supports the Pico and many other Cortex-M platforms as well (and which supports far more platforms than my own zeptoforth — especially when one considers the original Mecrisp for the MSP430, Mecrisp-Quintus for RISC-V and MIPS, Mecrisp-Across for tethered crosscompiling from Mecrisp-Stellaris on a Cortex-M board to a MSP430 MCU, and Mecrisp-Ice for some FPGA boards).Quote from: WillTurner on November 02, 2022, 01:28:54 amFor my own testing purposes, my 32GBSDHC/SDXC cards are ridiculously large. Unless one is taking video or storing an OS image (e.g. for a Raspberry Pi) 32 GB is more than enough space for most purposes.(Note that by "old-style" I mean the kind of cards that were limited to 2 GB in size that used the old SD card protocol where block offsets in bytes were used rather than block indices.)Quote from: WillTurner on November 02, 2022, 01:28:54 amzeptoforth essentially aims to be a Forth-based OS for Cortex-M microcontrollers, even though it may not be what many people think of when they think of an "OS" (e.g. filesystem access is not an integral part of the system, and with little difficulty it can be built without if one so wishes). But the same is true even of FreeRTOS, which zeptoforth is much more comparable to than even the likes of µClinux.

author: Peabody
author_rank: Super Contributor
timestamp: November 02, 2022, 04:16:40 am
content: Quote from: WillTurner on November 02, 2022, 01:28:54 amIt's not actually a switch that does anything. The controller reading the card has to detect the position of the slide, and act accordingly. But it doesn't have to. An alternate firmware for Canon point-and-shoot cameras called CHDK is enabled by putting the slide in the "lock" position, after which it saves photos to the card normally.

author: Sniper1
author_rank: Regular Contributor
timestamp: November 02, 2022, 04:58:58 pm
content: Well it is 2GB since it is an old one that i had around , and i felt is wourl be a waste to buy a new 16GB+ one since i just want to log some data not HD video , and i dont want to use and eeprom since it is easy to get the SD out and in a PCregarding the browser thing ill try tonight

author: Sniper1
author_rank: Regular Contributor
timestamp: November 02, 2022, 05:08:16 pm
content: Tried on Edge and it did not find any serials to connect to

author: tabemann
author_rank: Contributor
timestamp: November 02, 2022, 11:25:44 pm
content: Quote from: Sniper1 on November 02, 2022, 05:08:16 pmWhen I've tried using zeptocom.js under Windows it has been a pain to get Windows to register virtual COM ports from USB-serial devices (it took forever for me). Normally I use it under Chrome or Chromium on Linux and have not had a problem (aside from when I forget to chmod a+rw /dev/ttyUSB0 after rebooting or disconnecting and reconnecting my USB-serial dongle).

author: paulca
author_rank: Super Contributor
timestamp: November 05, 2022, 11:47:36 am
content: Javascript with raw hardware access. Jesus wept. Has nobody learn ANY lessons?a+rw will get your sacked in a lot of places. It is NEVER the correct solution.Try:gpasswd -a user dialout

author: iMo
author_rank: Super Contributor
timestamp: November 05, 2022, 02:28:57 pm
content: While messing with sdcards on arm/mips/avr/pic I saw following issues typically:1. wiring issues, long wires, level shifters2. no pullup (like 10k) on certain pins when required3. missing a large capacitor close to the sdrcard's Vcc/Gnd pins (like 10 or 22uF ceramic multilayer)4. too high sdcard clock frequency (better start with couple of MHz when issues)5. and then some advanced issues like - sdcard write latency (!needs FIFO), or wrong delays or number of retries or wrong card interface settings (all in the sw driver)..

author: tabemann
author_rank: Contributor
timestamp: November 05, 2022, 10:25:43 pm
content: Quote from: paulca on November 05, 2022, 11:47:36 amYou obviously are not familiar with the matter. For starters, the browser prompts the user for access to a serial device, and web pages havenocapacity to override the content or function of this prompt. Additionally, it is only usable with HTTPS or localhost, so the only way for a man-in-the-middle to compromise things is if your root certificates are compromised. And anyways, if the reader really wanted to be on the safe side, they could git clone the source from GitHub, athttps://github.com/tabemann/zeptocomjs/, read the source code for themselves, and usepython3 -m http.server --bind localhost 9000to start a web server running at localhost serving it.Quote from: paulca on November 05, 2022, 11:47:36 amYou're assuming that my personal laptop is being used as a multiuser system, which it isn't. The only accounts in use are my personal account, accounts for some daemons (I don't have sshd or httpd running for that matter), and root.Thank you for the snarky comments.