Author Topic: SD card problem with custom rp2040 `pico`  (Read 11160 times)

0 Members and 3 Guests are viewing this topic.

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #25 on: November 01, 2022, 12:07:20 am »
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 at https://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 at https://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 (see https://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: [Select]
oo import
block-dev import
sd import
fat32 import
simple-fat32 import

<simple-fat32-fs> class-size buffer: my-fs
<fat32-dir> class-size buffer: my-dir
<fat32-entry> class-size buffer: my-entry

2 3 4 5 0 <simple-fat32-fs> my-fs init-object

: ls-root ( -- )
  <fat32-entry> my-entry init-object
  my-dir my-fs root-dir@
  begin
    my-entry my-dir read-dir if
      my-entry entry-file? my-entry entry-dir? or if
        12 [:
          12 my-entry file-name@
          cr type space false
        ;] with-allot
      else
        false
      then
    else
      true
    then
  until
;

ls-root

Edit: Changed the code to properly ignore long file names (which previous produced blank entries).
« Last Edit: November 01, 2022, 04:55:34 am by tabemann »
 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #26 on: November 01, 2022, 02:01:03 am »
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).
 

Offline WillTurner

  • Regular Contributor
  • *
  • Posts: 69
  • Country: au
Re: SD card problem with custom rp2040 `pico`
« Reply #27 on: November 02, 2022, 01:28:54 am »
zeptoforth

Another one! You are the author?
So the list of RPi PICO platforms1 is
  • ZeptoForth
  • Arduino
  • Assembly
  • C/C++ SDK
  • FreeRTOS
  • Picomite and VGA MMBASIC variants
  • micropython
  • Fuzix

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).
I 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"
« Last Edit: November 02, 2022, 01:51:17 am by WillTurner »
 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #28 on: November 02, 2022, 01:57:52 am »
zeptoforth

Another one! You are the author?

Yep! 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).

So the list of RPi PICO platforms1 is
  • ZeptoForth
  • Arduino
  • Assembly
  • C/C++ SDK
  • FreeRTOS
  • Picomite and VGA MMBASIC variants
  • micropython
  • Fuzix

Don'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).

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).
I 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.

For my own testing purposes, my 32 GB SDHC/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.)

Footnote: "Platform" to be defined  :), but it might be something like development environments capable of being used to implement some kind of operating system?
Edit: "Platform"

zeptoforth 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.
« Last Edit: November 02, 2022, 02:26:35 am by tabemann »
 
The following users thanked this post: WillTurner

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2783
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #29 on: November 02, 2022, 04:16:40 am »

I 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.

It'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.
 
The following users thanked this post: WillTurner

Offline Sniper1Topic starter

  • Regular Contributor
  • *
  • Posts: 142
  • Country: ro
Re: SD card problem with custom rp2040 `pico`
« Reply #30 on: November 02, 2022, 04:58:58 pm »
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 PC

regarding the browser thing ill try tonight
 

Offline Sniper1Topic starter

  • Regular Contributor
  • *
  • Posts: 142
  • Country: ro
Re: SD card problem with custom rp2040 `pico`
« Reply #31 on: November 02, 2022, 05:08:16 pm »
Tried on Edge and it did not find any serials to connect to
 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #32 on: November 02, 2022, 11:25:44 pm »
Tried on Edge and it did not find any serials to connect to
When 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).
 

Offline paulca

  • Super Contributor
  • ***
  • Posts: 6548
  • Country: gb
Re: SD card problem with custom rp2040 `pico`
« Reply #33 on: November 05, 2022, 11:47:36 am »
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

"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 6962
  • Country: li
Re: SD card problem with custom rp2040 `pico`
« Reply #34 on: November 05, 2022, 02:28:57 pm »
While messing with sdcards on arm/mips/avr/pic I saw following issues typically:
1. wiring issues, long wires, level shifters
2. no pullup (like 10k) on certain pins when required
3. 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)..
« Last Edit: November 05, 2022, 02:31:23 pm by imo »
Readers discretion is advised..
 
The following users thanked this post: WillTurner

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: SD card problem with custom rp2040 `pico`
« Reply #35 on: November 05, 2022, 10:25:43 pm »
Javascript with raw hardware access.  Jesus wept.  Has nobody learn ANY lessons?

You obviously are not familiar with the matter. For starters, the browser prompts the user for access to a serial device, and web pages have no capacity 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, at https://github.com/tabemann/zeptocomjs/, read the source code for themselves, and use python3 -m http.server --bind localhost 9000 to start a web server running at localhost serving it.

a+rw will get your sacked in a lot of places.  It is NEVER the correct solution.

Try:

gpasswd -a user dialout

You'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.
« Last Edit: November 05, 2022, 11:27:33 pm by tabemann »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->