2525#include " ClassControllCamera.h"
2626#include " server_main.h"
2727#include " server_camera.h"
28+
29+
30+ #define __SD_USE_ONE_LINE_MODE__
31+
32+ #ifdef __SD_USE_ONE_LINE_MODE__
2833#include " server_GPIO.h"
34+ #endif
35+
2936static const char *TAGMAIN = " connect_wlan_main" ;
3037
3138#define FLASH_GPIO GPIO_NUM_4
@@ -37,34 +44,61 @@ void Init_NVS_SDCard()
3744 ESP_ERROR_CHECK (nvs_flash_erase ());
3845 ret = nvs_flash_init ();
3946 }
47+ // //////////////////////////////////////////////
4048
41- ESP_LOGI (TAGMAIN , " Initializing SD card " );
49+ ESP_LOGI (TAG , " Using SDMMC peripheral " );
4250 sdmmc_host_t host = SDMMC_HOST_DEFAULT ();
43- host.flags = SDMMC_HOST_FLAG_1BIT;
44- // sdmmc_host_t host = SDMMC_HOST_SLOT_1();
45- // host.flags = SDMMC_HOST_FLAG_1BIT;
46- sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT ();
47- slot_config.width = 1 ; // 1 line SD mode
48-
49- esp_vfs_fat_sdmmc_mount_config_t mount_config = { };
50- mount_config.format_if_mount_failed = false ;
51- mount_config.max_files = 5 ;
5251
53- gpio_set_pull_mode ((gpio_num_t ) 15 , GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
54- gpio_set_pull_mode ((gpio_num_t ) 2 , GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
52+ // This initializes the slot without card detect (CD) and write protect (WP) signals.
53+ // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
54+ sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT ();
5555
56+ // To use 1-line SD mode, uncomment the following line:
57+
58+ #ifdef __SD_USE_ONE_LINE_MODE__
59+ slot_config.width = 1 ;
60+ #endif
61+
62+ // GPIOs 15, 2, 4, 12, 13 should have external 10k pull-ups.
63+ // Internal pull-ups are not sufficient. However, enabling internal pull-ups
64+ // does make a difference some boards, so we do that here.
65+ gpio_set_pull_mode (GPIO_NUM_15, GPIO_PULLUP_ONLY); // CMD, needed in 4- and 1- line modes
66+ gpio_set_pull_mode (GPIO_NUM_2, GPIO_PULLUP_ONLY); // D0, needed in 4- and 1-line modes
67+ gpio_set_pull_mode (GPIO_NUM_4, GPIO_PULLUP_ONLY); // D1, needed in 4-line mode only
68+ gpio_set_pull_mode (GPIO_NUM_12, GPIO_PULLUP_ONLY); // D2, needed in 4-line mode only
69+ gpio_set_pull_mode (GPIO_NUM_13, GPIO_PULLUP_ONLY); // D3, needed in 4- and 1-line modes
70+
71+ // Options for mounting the filesystem.
72+ // If format_if_mount_failed is set to true, SD card will be partitioned and
73+ // formatted in case when mounting fails.
74+ esp_vfs_fat_sdmmc_mount_config_t mount_config = {
75+ .format_if_mount_failed = false ,
76+ .max_files = 5 ,
77+ .allocation_unit_size = 16 * 1024
78+ };
79+
80+ // Use settings defined above to initialize SD card and mount FAT filesystem.
81+ // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
82+ // Please check its source code and implement error recovery when developing
83+ // production applications.
5684 sdmmc_card_t * card;
5785 ret = esp_vfs_fat_sdmmc_mount (" /sdcard" , &host, &slot_config, &mount_config, &card);
86+
5887 if (ret != ESP_OK) {
5988 if (ret == ESP_FAIL) {
60- ESP_LOGE (TAGMAIN, " Failed to mount filesystem. If you want the card to be formatted, set format_if_mount_failed = true." );
89+ ESP_LOGE (TAG, " Failed to mount filesystem. "
90+ " If you want the card to be formatted, set format_if_mount_failed = true." );
6191 } else {
62- ESP_LOGE (TAGMAIN, " Failed to initialize the card (%d). Make sure SD card lines have pull-up resistors in place." , ret);
92+ ESP_LOGE (TAG, " Failed to initialize the card (%s). "
93+ " Make sure SD card lines have pull-up resistors in place." , esp_err_to_name (ret));
6394 }
6495 return ;
6596 }
97+
98+ // Card has been initialized, print its properties
6699 sdmmc_card_print_info (stdout, card);
67100
101+
68102 // Init the GPIO
69103 // Flash ausschalten
70104 gpio_pad_select_gpio (FLASH_GPIO);
@@ -113,7 +147,11 @@ extern "C" void app_main(void)
113147 register_server_tflite_uri (server);
114148 register_server_file_uri (server, " /sdcard" );
115149 register_server_ota_sdcard_uri (server);
150+
151+ #ifdef __SD_USE_ONE_LINE_MODE__
116152 register_server_GPIO_uri (server);
153+ #endif
154+
117155 register_server_main_uri (server, " /sdcard" );
118156
119157 TFliteDoAutoStart ();
0 commit comments