• ESP32Forth SD Card Initialization

    From Van Kichline@21:1/5 to All on Sat Aug 26 15:15:16 2023
    I'm having quite a bit of trouble using SD cards with Esp32Forth.
    I have exactly one setup that works: An Adafruit ESP32 Feather with an AdaLogger board (which contains an SD card socket.)
    Many boards don't have a setting in the Arduino IDE 2.0, such as the LilyGo T8 which includes an SD socket. I find I can modify the SD Test example program to work correctly with this board by replacing SD.begin() with:
    SPI.begin(14, 2, 15, 13); //SCK, MISO, MOSI, SS
    SD.begin(13);
    (Both changes are required.)
    However, I've been unable to introduce these changes to Esp32Forth successfully.
    I've modified the Forth definition of SD.begin to call the C function SD.begin(13). I modified SD.beginDefaults to push 13 rather than SS. I added SPI.begin(14, 2, 15, 13); to the end of setup(), but when I start Esp32Forth and enter:
    SD SD.begin
    it always returns 0. (It returns a 1 on success.)
    I have several other boards with similar issues, I just cannot get the SD to initialize, but can run the (modified) SD Test program on them successfully.
    Can someone provide some guidance on how to get the SD up and running on Esp32Forth when SD.begin does not succeed?
    Thanks for your time!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Van Kichline@21:1/5 to All on Sat Aug 26 19:45:13 2023
    A little more info from trying to get the LilyGo T8's SD card working on ESP32Forth:
    At the top of ESP32forth.ino, I inserted:
    #define SS 13
    #define MOSI 15
    #define MISO 2
    #define SCK 14
    I changed XV(SD, "SD.begin", SD_BEGIN, PUSH SD.begin()) to XV(SD, "SD.begin", SD_BEGIN, PUSH SD.begin(SS))
    I added a bit of extra code:
    void print_pins() { printf("SCK=%d, MOSI=%d, MISO=%d, SS=%d\n", SCK, MOSI, MISO, SS); }
    ...and added a word to OPTIONAL_SD_SUPPORT:
    XV(SD, "SD.Pins", SD_PINS, print_pins())

    I have also added the following to setup():
    SPI.begin(14, 2, 15, 13); //SCK, MISO, MOSI, SS

    SD.begin still fails, simply returning zero.
    SD.Pins returns: SCK=14, MOSI=15, MISO=2, SS=13 (as expected) if and only if I include the SPI.begin(14, 2, 15, 13); in setup().

    Also, I found that adding the 4 #defines to the SD Test example had no effect, I could not eliminate either of the required changes for the LilyGo T8 board.
    The #defines do make SD.beginDefaults return the correct SS, however.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Schultz@21:1/5 to Van Kichline on Sun Aug 27 09:30:20 2023
    On 8/26/23 5:15 PM, Van Kichline wrote:
    I'm having quite a bit of trouble using SD cards with Esp32Forth.

    I have some SD card code in eForth (sort of) for both the MSP430 and
    ARM. (MSP430 uses the SPI interface while the ARM uses 4 bit SD.) I
    don't use Arduino unless forced to so I can't help with that.

    The sort of refers to having to code it in assembler so it was part of
    eForth. Compiling from the SD card being kind of hard without it. :-)

    http://davesrocketworks.com/electronics/msp430/eforth/index.html

    You will of course want to read the SD (simplified) specification.

    https://www.sdcard.org/downloads/pls/

    Up to version 9.0 now I see. Full up initialization can be quite
    complicated if you want to support SD 1.0 and MMC cards.


    --
    http://davesrocketworks.com
    David Schultz

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Van Kichline@21:1/5 to David Schultz on Sun Aug 27 16:41:00 2023
    On Sunday, August 27, 2023 at 7:30:32 AM UTC-7, David Schultz wrote:
    On 8/26/23 5:15 PM, Van Kichline wrote:
    I'm having quite a bit of trouble using SD cards with Esp32Forth.
    I have some SD card code in eForth (sort of) for both the MSP430 and
    ARM. (MSP430 uses the SPI interface while the ARM uses 4 bit SD.) I
    don't use Arduino unless forced to so I can't help with that.

    The sort of refers to having to code it in assembler so it was part of eForth. Compiling from the SD card being kind of hard without it. :-)

    http://davesrocketworks.com/electronics/msp430/eforth/index.html

    You will of course want to read the SD (simplified) specification.

    https://www.sdcard.org/downloads/pls/

    Up to version 9.0 now I see. Full up initialization can be quite
    complicated if you want to support SD 1.0 and MMC cards.


    --
    http://davesrocketworks.com
    David Schultz
    Thanks for this! I believe my main problem is that the Arduino IDE does some "magic" to set the SPI pins when a board is selected, and I can't find any detailed documentation about how that's done, or how to compensate when there is no compatible board
    definition. After doing more research on this, it really looks like an Arduino question more than a Forth question. Some seem to have solved this specific problem for Esp32Forth; I was just hoping to find someone with a simple pattern to follow. I'm not
    lazy, but when IDE's rely on magic, sometimes you need to find a magician.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David Schultz@21:1/5 to Van Kichline on Sun Aug 27 19:29:56 2023
    On 8/27/23 6:41 PM, Van Kichline wrote:
    Thanks for this! I believe my main problem is that the Arduino IDE
    does some "magic" to set the SPI pins when a board is selected, and I
    can't find any detailed documentation about how that's done, or how
    to compensate when there is no compatible board definition. After
    doing more research on this, it really looks like an Arduino question
    more than a Forth question. Some seem to have solved this specific
    problem for Esp32Forth; I was just hoping to find someone with a
    simple pattern to follow. I'm not lazy, but when IDE's rely on
    magic, sometimes you need to find a magician.
    The magic is inside source files which are hiding somewhere in the
    library distribution. Compiled from scratch each time you start up the
    IDE. So find them, then dig around till you find the source file you
    need to fiddle with. If you are lucky there will already be an option to
    do what you want. If you are very lucky it will be well commented.

    --
    http://davesrocketworks.com
    David Schultz

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)