[Ground-station] Esp32 and SD cards

Michelle Thompson mountain.michelle at gmail.com
Mon May 6 11:45:34 PDT 2019


This is a 4-line design.

Here is the relevant output from make monitor. There is indeed a complaint
about pull-ups.

=======================================================
===== Test using SD Card in SPI mode              =====
===== SD Card uses the same gpio's as TFT display =====
=======================================================

I (52) SDCard test: Initializing SD card
I (56) SDCard test: Using SPI peripheral
I (62) gpio: GPIO[19]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0|
Pulldown: 0| Intr:0
E (112) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
I (112) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (118) gpio: GPIO[25]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (127) gpio: GPIO[26]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
E (136) SDCard test: Failed to initialize the card (264). Make sure SD card
lines have pull-up resistors in place.

Now, checking the hardware:

This is a Hackerboxes kit #20. The SD Card is on a TFT display. The
particular TFT display is this one:
https://www.amazon.com/gp/product/B01CZL6QIQ/ref=ppx_yo_dt_b_asin_title_o03_s00?ie=UTF8&psc=1

There are resistors on the TFT display in the expected places and there is
3.3v on the SD card SPI pins when the board is powered up.

Looking at this board's schematic, the wrong pins were assigned for SPI
access to the SD Card.

The schematic is located in Step 4 in this website:
https://www.instructables.com/id/HackerBoxes-0020-Summer-Camp/

So, I updated the SD SPI to match the schematic. Unfortunately, same
errors.

=======================================================
===== Test using SD Card in SPI mode              =====
===== SD Card uses the same gpio's as TFT display =====
=======================================================

I (52) SDCard test: Initializing SD card
I (56) SDCard test: Using SPI peripheral
I (62) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0|
Pulldown: 0| Intr:0
E (112) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
I (112) gpio: GPIO[16]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (118) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (127) gpio: GPIO[0]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
E (136) SDCard test: Failed to initialize the card (264). Make sure SD card
lines have pull-up resistors in place.


Removing the card completely? Same errors. Hmmm.

=======================================================
===== Test using SD Card in SPI mode              =====
===== SD Card uses the same gpio's as TFT display =====
=======================================================

I (52) SDCard test: Initializing SD card
I (56) SDCard test: Using SPI peripheral
I (62) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0|
Pulldown: 0| Intr:0
E (112) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
I (112) gpio: GPIO[16]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (118) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
I (127) gpio: GPIO[0]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1|
Pulldown: 0| Intr:0
E (136) SDCard test: Failed to initialize the card (264). Make sure SD card
lines have pull-up resistors in place.


Next, I scrounged around to see if I missed anything super obvious.

In a community-provided repository for Hackerboxes #20 (
https://github.com/lmarty/Hackerboxes20), I found this:
"
IF THE SD ISN'T WORKING...

try holding down the flash button on the dev kit board as you boot
If that fixes it... Pop your TFT board off the project PCB and flip it
over. There are two small pads labled "j1" on the back, solder them
together."


But Hackerboxes replied with this:

"From what I understand, shorting J1 on the LCD module bypasses the voltage
regulator that converts the incoming 5V to the 3.3V needed by the LCD. J1
is intended to be shorted if you are providing 3.3V to the module to begin
with. Shorting J1 is probably not a great idea if the supply to the module
is 5V."

So I postponed that idea as just too janky.



But it has to be something simple I'm doing wrong.



Here's the code from tft_demo.c (from esp-idf examples directory) that
sources the errors.


    // Use settings defined above to initialize SD card and mount FAT
filesystem.
    // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
    // Please check its source code and implement error recovery when
developing
    // production applications.
    sdmmc_card_t* card;
    esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config,
&mount_config, &card);

    if (ret != ESP_OK) {
        if (ret == ESP_FAIL) {
            ESP_LOGE(TAG, "Failed to mount filesystem. "
                "If you want the card to be formatted, set
format_if_mount_failed = true.");
        } else {
            ESP_LOGE(TAG, "Failed to initialize the card (%d). "
                "Make sure SD card lines have pull-up resistors in place.",
ret);
        }
        return;
    }



OK so we failed to initialize the card, so climbing back
into esp_vfs_fat_sdmmc_mount() is the next step, just like it says to do in
the comments.

So I went and looked for it and I think I found it in
/esp/esp-idf/components/fatfs/src/esp_vfs_fat.h
/esp/esp-idf/components/fatfs/src/vfs_fat_sdmmc.c

And that's where I'm at as of right this minute.

More soon, pausing for any good advice anyone has from here on the list on
what to check next (in addition to digging through the library code).

Steve Conklin asked if we had an SPI decoder. I think we might.

-mdt



On Sat, May 4, 2019 at 9:53 AM Michelle Thompson <
mountain.michelle at gmail.com> wrote:

> This question is mainly for Wally, but posting here for anyone else that
> has experience with integrating SD cards into a project!
>
> I’m getting some errors with the example code from ESP-idf.
>
> Any best practices I should learn about?
>
> Like with many HTs and modern radios, mass storage for us will be very
> useful.
>
> -mdt
> --
> -Michelle W5NYV
>
> "Potestatem obscuri lateris nescis."
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openresearch.institute/pipermail/ground-station-openresearch.institute/attachments/20190506/c84e08b6/attachment.html>


More information about the Ground-Station mailing list