jgauchia / IceNav-v3

ESP32 Based GPS Navigator with OSM offline maps. (Under development)
GNU General Public License v3.0
50 stars 11 forks source link

sdmmc card #103

Closed zhjygit closed 2 months ago

zhjygit commented 5 months ago

Hi sir, i have no makerfabs esp32s3 board, my board is as the save, however the sd card is sdmmc type : image

I changed the main.cpp as follows:

_**

/**

  • @file main.cpp
  • @author Jordi Gauchía (jgauchia@jgauchia.com)
  • @brief ESP32 GPS Naviation main code
  • @version 0.1.6
  • @date 2023-06-14 */

define CALIBRATION_FILE "/TouchCalData1"

bool REPEAT_CAL = false; //sdmmc related;

include "FS.h"

include "SD_MMC.h" //sd_mmc card related

bool sdloaded = false;//flag of whether sd_mmc card is mounted or not

include

include

include

include

include

include

include

include

include

unsigned long millis_actual = 0;

include "hardware/hal.h"

include "hardware/serial.h"

//#include "hardware/sdcard.h"

include "hardware/tft.h"

ifdef ENABLE_COMPASS

include "hardware/compass.h"

endif

ifdef ENABLE_BME

include "hardware/bme.h"

endif

include "hardware/battery.h"

include "hardware/gps.h"

include "hardware/power.h"

include "utils/gps_maps.h"

include "utils/gps_math.h"

include "utils/sat_info.h"

include "utils/lv_spiffs_fs.h"

//#include "utils/lv_sd_fs.h"

include "utils/time_zone.h"

include "utils/preferences.h"

include "gui/lvgl.h"

include "tasks.h"

// Default pins for ESP-S3 // Warning: ESP32-S3-WROOM-2 is using most of the default GPIOs (33-37) to interface with on-board OPI flash. // If the SD_MMC is initialized with default pins it will result in rebooting loop - please // reassign the pins elsewhere using the mentioned command setPins. // Note: ESP32-S3-WROOM-1 does not have GPIO 33 and 34 broken out. // Note: if it's ok to use default pins, you do not need to call the setPins int clk = 47; int cmd = 21; int d0 = 48; int d1 = 45; int d2 = 13; int d3 = 14;

void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ Serial.printf("Listing directory: %s\n", dirname);

File root = fs.open(dirname);
if(!root){
    Serial.println("Failed to open directory");
    return;
}
if(!root.isDirectory()){
    Serial.println("Not a directory");
    return;
}

File file = root.openNextFile();
while(file){
    if(file.isDirectory()){
        Serial.print("  DIR : ");
        Serial.println(file.name());
        if(levels){
            listDir(fs, file.path(), levels -1);
        }
    } else {
        Serial.print("  FILE: ");
        Serial.print(file.name());
        Serial.print("  SIZE: ");
        Serial.println(file.size());
    }
    file = root.openNextFile();
}

}

void createDir(fs::FS &fs, const char * path){ Serial.printf("Creating Dir: %s\n", path); if(fs.mkdir(path)){ Serial.println("Dir created"); } else { Serial.println("mkdir failed"); } }

void removeDir(fs::FS &fs, const char * path){ Serial.printf("Removing Dir: %s\n", path); if(fs.rmdir(path)){ Serial.println("Dir removed"); } else { Serial.println("rmdir failed"); } }

void readFile(fs::FS &fs, const char * path){ Serial.printf("Reading file: %s\n", path);

File file = fs.open(path);
if(!file){
    Serial.println("Failed to open file for reading");
    return;
}

Serial.print("Read from file: ");
while(file.available()){
    Serial.write(file.read());
}

}

void writeFile(fs::FS &fs, const char path, const char message){ Serial.printf("Writing file: %s\n", path);

File file = fs.open(path, FILE_WRITE);
if(!file){
    Serial.println("Failed to open file for writing");
    return;
}
if(file.print(message)){
    Serial.println("File written");
} else {
    Serial.println("Write failed");
}

}

void appendFile(fs::FS &fs, const char path, const char message){ Serial.printf("Appending to file: %s\n", path);

File file = fs.open(path, FILE_APPEND);
if(!file){
    Serial.println("Failed to open file for appending");
    return;
}
if(file.print(message)){
    Serial.println("Message appended");
} else {
    Serial.println("Append failed");
}

}

void renameFile(fs::FS &fs, const char path1, const char path2){ Serial.printf("Renaming file %s to %s\n", path1, path2); if (fs.rename(path1, path2)) { Serial.println("File renamed"); } else { Serial.println("Rename failed"); } }

void deleteFile(fs::FS &fs, const char * path){ Serial.printf("Deleting file: %s\n", path); if(fs.remove(path)){ Serial.println("File deleted"); } else { Serial.println("Delete failed"); } }

void testFileIO(fs::FS &fs, const char * path){ File file = fs.open(path); static uint8_t buf[512]; size_t len = 0; uint32_t start = millis(); uint32_t end = start; if(file){ len = file.size(); size_t flen = len; start = millis(); while(len){ size_t toRead = len; if(toRead > 512){ toRead = 512; } file.read(buf, toRead); len -= toRead; } end = millis() - start; Serial.printf("%u bytes read for %u ms\n", flen, end); file.close(); } else { Serial.println("Failed to open file for reading"); }

file = fs.open(path, FILE_WRITE);
if(!file){
    Serial.println("Failed to open file for writing");
    return;
}

size_t i;
start = millis();
for(i=0; i<2048; i++){
    file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
file.close();

}

void init_sdmmc(void){ if(!SD_MMC.setPins(clk, cmd, d0)){ if(!SD_MMC.setPins(clk, cmd, d0, d1, d2, d3)){ Serial.println("Pin change failed!"); return; } } if(!SD_MMC.begin("/sdcard", true,true)){ Serial.println("Card Mount Failed"); return; } uint8_t cardType = SD_MMC.cardType();

if(cardType == CARD_NONE){
    Serial.println("No SD_MMC card attached");
    return;
}

bool sdloaded = true;//if sd_mmc card mounted

Serial.print("SD_MMC Card Type: ");
if(cardType == CARD_MMC){
    Serial.println("MMC");
} else if(cardType == CARD_SD){
    Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
    Serial.println("SDHC");
} else {
    Serial.println("UNKNOWN");
}

uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);

listDir(SD_MMC, "/", 0);
createDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 0);
removeDir(SD_MMC, "/mydir");
listDir(SD_MMC, "/", 2);
writeFile(SD_MMC, "/hello.txt", "Hello ");
appendFile(SD_MMC, "/hello.txt", "World!\n");
readFile(SD_MMC, "/hello.txt");
deleteFile(SD_MMC, "/foo.txt");
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
readFile(SD_MMC, "/foo.txt");
testFileIO(SD_MMC, "/test.txt");
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));

}

/**

  • @brief Setup
  • */ void setup() { Serial.begin(115200);

ifdef MAKERF_ESP32S3

Wire.setPins(I2C_SDA_PIN, I2C_SCL_PIN); Wire.begin();

endif

ifdef ENABLE_BME

bme.begin(BME_ADDRESS);

endif

ifdef ENABLE_COMPASS

init_compass();

endif

ifdef DEBUG

init_serial();

endif

powerOn(); load_preferences(); //init_sd(); //init_SPIFFS(); init_sdmmc(); init_LVGL(); init_tft(); init_gps(); init_ADC();

//map_spr.deleteSprite(); //map_spr.createSprite(768, 768);

//splash_scr(); // init_tasks();

ifdef DEFAULT_LAT

load_main_screen();

else

//lv_scr_load(searchSat);

endif

}

/**

  • @brief Main Loop
  • */ void loop() { //vTaskDelay(5);

    ifdef MAKERF_ESP32S3

    lv_tick_inc(5);

    endif

    lv_timer_handler(); //lv_task_handler();

    while (gps->available()>0) {

    ifdef OUTPUT_NMEA

    { debug->write(gps->read()); }

    else

    GPS.encode(gps->read());

    endif

    } }

**_

When i compile the code, the errors is src/gui/screens/Main/events/main_scr.h:40:34: warning: ISO C++ forbids converting a string constant to 'char' [-Wwrite-strings] MapTile OldMapTile = {"", 0, 0, 0}; ^ In file included from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1_init.hpp:25, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/LovyanGFX.hpp:31, from lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp:11, from src/hardware/tft.h:14, from src/main.cpp:32: .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp: In instantiation of 'bool lgfx::v1::LGFXBase::drawPngFile(T&, const char, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, float, float, lgfx::v1::datum::datum_t) [with T = fs::SDMMCFS; int32_t = int; lgfx::v1::datum::datum_t = lgfx::v1::textdatum::textdatum_t]': src/gui/screens/Main/events/map.h:158:74: required from here .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp:888:23: error: cannot declare variable 'file' to be of abstract type 'lgfx::v1::DataWrapperT' DataWrapperT file ( &fs ); \ ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp:896:5: note: in expansion of macro 'LGFX_FUNCTION_GENERATOR' LGFX_FUNCTION_GENERATOR(drawPng, draw_png) image

Waiting for you reply.

jgauchia commented 5 months ago

I think the issue is in the LovyanGFX configuration. If you are using the MAKERF_ESP32S3 environment, you need to be aware that there are same GPIOs configured in the TFT. Are you using a TFT? If so, you should configure it in the file https://github.com/jgauchia/IceNav-v3/blob/master/lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp

You can comment this too:

init_LVGL(); init_tft();

I don't know if you're using a TFT or what type it is.

zhjygit commented 5 months ago

I have no MAKERF_ESP32S3 board(I cannot buy it some reasons), here is my board: 4.3寸开发板原理图.pdf I thing the key difference is the sd card with sdmmc type; MAKERF_ESP32S3 board is the spicard, when the lvgl api draw pictures from sd card, the sdmmc type api is different from spi type, so, it failed with errors above.

zhjygit commented 5 months ago

When i changed the code from "xxx SD.xxx" to "xxx SD_MMC xxx", a lot of errors occur.

In file included from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/Light_PWM.hpp:20, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/device.hpp:41, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1_init.hpp:22, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/LovyanGFX.hpp:31, from lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp:11, from src/hardware/tft.h:18, from src/main.cpp:30: .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../../Light.hpp:22:1: error: expected ',' or ';' before 'namespace' namespace lgfx ^~~~~~~~~ In file included from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/device.hpp:41, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1_init.hpp:22, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/LovyanGFX.hpp:31, from lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp:11, from src/hardware/tft.h:18, from src/main.cpp:30: .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/Light_PWM.hpp:29:3: error: expected class-name before '{' token { ^ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/Light_PWM.hpp:45:10: error: 'bool lgfx::v1::Light_PWM::init(uint8_t)' marked 'override', but does not override bool init(uint8_t brightness) override; ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/Light_PWM.hpp:46:10: error: 'void lgfx::v1::Light_PWM::setBrightness(uint8_t)' marked 'override', but does not override void setBrightness(uint8_t brightness) override; ^~~~~~~~~~~~~ .pio/libdeps/MAKERF_ESP32S3/lvgl/src/core/lv_obj.c: In function 'lv_init': Archiving .pio\build\MAKERF_ESP32S3\lib238\libTinyGPSPlus.a .pio/libdeps/MAKERF_ESP32S3/lvgl/src/core/lv_obj.c:152:18: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] char * txt = "Á"; ^~~~ Indexing .pio\build\MAKERF_ESP32S3\lib238\libTinyGPSPlus.a Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_obj_pos.c.o Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_obj_scroll.c.o Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_obj_style.c.o Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_obj_style_gen.c.o Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_obj_tree.c.o Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_refr.c.o Archiving .pio\build\MAKERF_ESP32S3\lib77c\libTime.a Indexing .pio\build\MAKERF_ESP32S3\lib77c\libTime.a In file included from src/gui/screens/Main/main_scr.h:44, from src/gui/lvgl.h:53, from src/main.cpp:47: src/gui/screens/Main/events/main_scr.h:40:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] MapTile OldMapTile = {"", 0, 0, 0}; ^ Compiling .pio\build\MAKERF_ESP32S3\lib93f\lvgl\core\lv_theme.c.o In file included from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1_init.hpp:25, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/LovyanGFX.hpp:31, from lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp:11, from src/hardware/tft.h:18, from src/main.cpp:30: .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp: In instantiation of 'bool lgfx::v1::LGFXBase::drawPngFile(T&, const char*, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, float, float, lgfx::v1::datum::datum_t) [with T = fs::SDMMCFS; int32_t = int; lgfx::v1::datum::datum_t = lgfx::v1::textdatum::textdatum_t]': src/gui/screens/Main/events/map.h:157:74: required from here .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp:888:23: error: cannot declare variable 'file' to be of abstract type 'lgfx::v1::DataWrapperT<fs::SDMMCFS>' DataWrapperT<T> file ( &fs ); \ ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/LGFXBase.hpp:896:5: note: in expansion of macro 'LGFX_FUNCTION_GENERATOR' LGFX_FUNCTION_GENERATOR(drawPng, draw_png) ^~~~~~~~~~~~~~~~~~~~~~~ In file included from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/common.hpp:20, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../common.hpp:22, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/Bus_SPI.hpp:57, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/device.hpp:42, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1_init.hpp:22, from .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/LovyanGFX.hpp:31, from lib/makefabs-esp32s3parallel/LGFX_MakerFabs_Parallel_S3.hpp:11, from src/hardware/tft.h:18, from src/main.cpp:30: .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:91:10: note: because the following virtual functions are pure within 'lgfx::v1::DataWrapperT<fs::SDMMCFS>': struct DataWrapperT : public DataWrapper { ^~~~~~~~~~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:72:17: note: 'virtual int lgfx::v1::DataWrapper::read(uint8_t*, uint32_t)' virtual int read(uint8_t *buf, uint32_t len) = 0; ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:74:18: note: 'virtual void lgfx::v1::DataWrapper::skip(int32_t)' virtual void skip(int32_t offset) = 0; ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:75:18: note: 'virtual bool lgfx::v1::DataWrapper::seek(uint32_t)' virtual bool seek(uint32_t offset) = 0; ^~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:76:18: note: 'virtual void lgfx::v1::DataWrapper::close()' virtual void close(void) = 0; ^~~~~ .pio/libdeps/MAKERF_ESP32S3/LovyanGFX/src/lgfx/v1/platforms/esp32/../esp32/../../misc/DataWrapper.hpp:77:21: note: 'virtual int32_t lgfx::v1::DataWrapper::tell()' virtual int32_t tell(void) = 0;

Here is my sdmmccard.h:

project.zip As I said above, I used the sdmmc card type, with 4.3 tft lcd screen, the data sheet is as above 4.3寸开发板原理图.pdf Waiting for you reply.

jgauchia commented 2 months ago

Not SDMMC supported, only listed boards and specs