Schema aangepast voor pullup weerstanden voor de SD kaart. Code verbeteringen in task_sdcard.

Mon, 05 Jul 2021 10:30:05 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 05 Jul 2021 10:30:05 +0200
changeset 106
191dccfe4252
parent 105
9e00845dc1ee
child 107
9e400c2fe22f

Schema aangepast voor pullup weerstanden voor de SD kaart. Code verbeteringen in task_sdcard.

kicad/Mainboard.sch file | annotate | diff | comparison | revisions
main/task_sdcard.c file | annotate | diff | comparison | revisions
--- a/kicad/Mainboard.sch	Thu Jul 01 20:26:45 2021 +0200
+++ b/kicad/Mainboard.sch	Mon Jul 05 10:30:05 2021 +0200
@@ -5,8 +5,8 @@
 encoding utf-8
 Sheet 2 3
 Title "Brewboard"
-Date "2018-05-23"
-Rev "1.1"
+Date "2021-07-05"
+Rev "1.2"
 Comp "MBSE"
 Comment1 "Mainboard"
 Comment2 ""
@@ -16,12 +16,12 @@
 $Comp
 L Converter_DCDC:OKI-78SR-3.3_1.5-W36-C U201
 U 1 1 60BEC1F6
-P 7050 800
-F 0 "U201" H 7050 1042 50  0000 C CNN
-F 1 "DD0503MA" H 7050 951 50  0000 C CNN
-F 2 "Converter_DCDC:Converter_DCDC_muRata_OKI-78SR_Vertical" H 7100 550 50  0001 L CIN
-F 3 "https://power.murata.com/data/power/oki-78sr.pdf" H 7050 800 50  0001 C CNN
-	1    7050 800 
+P 5950 800
+F 0 "U201" H 5950 1042 50  0000 C CNN
+F 1 "DD0503MA" H 5950 951 50  0000 C CNN
+F 2 "Converter_DCDC:Converter_DCDC_muRata_OKI-78SR_Vertical" H 6000 550 50  0001 L CIN
+F 3 "https://power.murata.com/data/power/oki-78sr.pdf" H 5950 800 50  0001 C CNN
+	1    5950 800 
 	1    0    0    -1  
 $EndComp
 $Comp
@@ -104,12 +104,12 @@
 $Comp
 L Diode:1N4148 D201
 U 1 1 60C25955
-P 5800 800
-F 0 "D201" H 5800 1017 50  0000 C CNN
-F 1 "1N4148" H 5800 926 50  0000 C CNN
-F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 5800 625 50  0001 C CNN
-F 3 "https://assets.nexperia.com/documents/data-sheet/1N4148_1N4448.pdf" H 5800 800 50  0001 C CNN
-	1    5800 800 
+P 4000 800
+F 0 "D201" H 4000 1017 50  0000 C CNN
+F 1 "1N4148" H 4000 926 50  0000 C CNN
+F 2 "Diode_THT:D_DO-35_SOD27_P7.62mm_Horizontal" H 4000 625 50  0001 C CNN
+F 3 "https://assets.nexperia.com/documents/data-sheet/1N4148_1N4448.pdf" H 4000 800 50  0001 C CNN
+	1    4000 800 
 	-1   0    0    -1  
 $EndComp
 $Comp
@@ -443,7 +443,7 @@
 Wire Wire Line
 	7750 1000 7750 800 
 Wire Wire Line
-	7750 800  7350 800 
+	7750 800  6850 800 
 NoConn ~ 7950 1100
 $Comp
 L power:GND #PWR0204
@@ -476,7 +476,7 @@
 Wire Wire Line
 	7850 900  7850 1100
 Wire Wire Line
-	7050 1100 7850 1100
+	5950 1100 7850 1100
 Connection ~ 7850 1100
 Wire Wire Line
 	7850 1100 7850 1600
@@ -578,19 +578,19 @@
 $Comp
 L power:+5P #PWR0201
 U 1 1 60D09831
-P 6350 800
-F 0 "#PWR0201" H 6350 650 50  0001 C CNN
-F 1 "+5P" H 6365 973 50  0000 C CNN
-F 2 "" H 6350 800 50  0001 C CNN
-F 3 "" H 6350 800 50  0001 C CNN
-	1    6350 800 
+P 4900 800
+F 0 "#PWR0201" H 4900 650 50  0001 C CNN
+F 1 "+5P" H 4915 973 50  0000 C CNN
+F 2 "" H 4900 800 50  0001 C CNN
+F 3 "" H 4900 800 50  0001 C CNN
+	1    4900 800 
 	1    0    0    -1  
 $EndComp
-Connection ~ 6350 800 
+Connection ~ 4900 800 
 Wire Wire Line
-	6350 800  6750 800 
+	4900 800  5650 800 
 Wire Wire Line
-	5950 800  6350 800 
+	4150 800  4900 800 
 $Comp
 L power:+5P #PWR0207
 U 1 1 60D0E708
@@ -738,13 +738,13 @@
 Wire Wire Line
 	3850 3550 3850 1300
 Wire Wire Line
-	3850 1300 7950 1300
+	3850 1300 5950 1300
 Wire Wire Line
 	4050 3650 3750 3650
 Wire Wire Line
 	3750 3650 3750 1500
 Wire Wire Line
-	3750 1500 7950 1500
+	3750 1500 6550 1500
 Wire Wire Line
 	1900 1100 2000 1100
 Wire Wire Line
@@ -776,7 +776,7 @@
 Wire Wire Line
 	3250 900  3250 800 
 Wire Wire Line
-	3250 800  5650 800 
+	3250 800  3850 800 
 $Comp
 L power:GND #PWR0203
 U 1 1 60E01D8A
@@ -991,7 +991,7 @@
 	1    0    0    -1  
 $EndComp
 Text Notes 3100 1100 0    50   ~ 0
-Instellen op 5,7 tot 6,0 volt.
+Instellen op 5,7 tot 6,0 volt.\nSpanning op +5P moet 5.1 tot 5.2 volt zijn.
 Wire Wire Line
 	2150 5450 1900 5450
 Wire Wire Line
@@ -1002,14 +1002,114 @@
 	2150 5150 2150 5100
 NoConn ~ 1900 5250
 $Comp
-L power:GND #PWR?
+L power:GND #PWR0220
 U 1 1 60DB46CB
 P 2600 6450
-F 0 "#PWR?" H 2600 6200 50  0001 C CNN
+F 0 "#PWR0220" H 2600 6200 50  0001 C CNN
 F 1 "GND" H 2605 6277 50  0000 C CNN
 F 2 "" H 2600 6450 50  0001 C CNN
 F 3 "" H 2600 6450 50  0001 C CNN
 	1    2600 6450
 	1    0    0    -1  
 $EndComp
+$Comp
+L Device:R R210
+U 1 1 60E3770D
+P 5650 1800
+F 0 "R210" H 5720 1846 50  0000 L CNN
+F 1 "10K" H 5720 1755 50  0000 L CNN
+F 2 "" V 5580 1800 50  0001 C CNN
+F 3 "~" H 5650 1800 50  0001 C CNN
+	1    5650 1800
+	1    0    0    -1  
+$EndComp
+$Comp
+L Device:R R211
+U 1 1 60E38041
+P 5950 1800
+F 0 "R211" H 6020 1846 50  0000 L CNN
+F 1 "10K" H 6020 1755 50  0000 L CNN
+F 2 "" V 5880 1800 50  0001 C CNN
+F 3 "~" H 5950 1800 50  0001 C CNN
+	1    5950 1800
+	1    0    0    -1  
+$EndComp
+$Comp
+L Device:R R212
+U 1 1 60E38CD7
+P 6250 1800
+F 0 "R212" H 6320 1846 50  0000 L CNN
+F 1 "10K" H 6320 1755 50  0000 L CNN
+F 2 "" V 6180 1800 50  0001 C CNN
+F 3 "~" H 6250 1800 50  0001 C CNN
+	1    6250 1800
+	1    0    0    -1  
+$EndComp
+$Comp
+L Device:R R213
+U 1 1 60E39393
+P 6550 1800
+F 0 "R213" H 6620 1846 50  0000 L CNN
+F 1 "10K" H 6620 1755 50  0000 L CNN
+F 2 "" V 6480 1800 50  0001 C CNN
+F 3 "~" H 6550 1800 50  0001 C CNN
+	1    6550 1800
+	1    0    0    -1  
+$EndComp
+Wire Wire Line
+	7350 1200 5650 1200
+Wire Wire Line
+	5650 1200 5650 1650
+Connection ~ 7350 1200
+Wire Wire Line
+	5950 1650 5950 1300
+Connection ~ 5950 1300
+Wire Wire Line
+	5950 1300 7950 1300
+Wire Wire Line
+	7450 1400 6250 1400
+Wire Wire Line
+	6250 1400 6250 1650
+Connection ~ 7450 1400
+Wire Wire Line
+	6550 1500 6550 1650
+Connection ~ 6550 1500
+Wire Wire Line
+	6550 1500 7950 1500
+Wire Wire Line
+	5650 1950 5650 2050
+Wire Wire Line
+	5650 2050 5950 2050
+Wire Wire Line
+	6550 2050 6550 1950
+Wire Wire Line
+	6250 1950 6250 2050
+Connection ~ 6250 2050
+Wire Wire Line
+	6250 2050 6550 2050
+Wire Wire Line
+	5950 1950 5950 2050
+Connection ~ 5950 2050
+Wire Wire Line
+	5950 2050 6250 2050
+Wire Wire Line
+	6550 2050 6850 2050
+Wire Wire Line
+	6850 2050 6850 800 
+Connection ~ 6550 2050
+Connection ~ 6850 800 
+Wire Wire Line
+	6850 800  6250 800 
+Wire Notes Line
+	5400 1550 7100 1550
+Wire Notes Line
+	7100 1550 7100 2450
+Wire Notes Line
+	7100 2450 5400 2450
+Wire Notes Line
+	5400 2450 5400 1550
+Text Notes 5450 2400 0    50   ~ 0
+Plaats R210 t/m R213 indien nodig.\nIndien U201 niet nodig is, 3.3V vanaf de\nESP32 gebruiken.\nWeerstanden 10K tot 20K.
+Text Notes 6250 700  0    50   ~ 0
+U201 weglaten als SD module zelf een 3.3V regelaar heeft.\nDe SD kaart dan aansluiten op +5P.
 $EndSCHEMATC
--- a/main/task_sdcard.c	Thu Jul 01 20:26:45 2021 +0200
+++ b/main/task_sdcard.c	Mon Jul 05 10:30:05 2021 +0200
@@ -30,9 +30,8 @@
 int			card_handle = -1;
 static const char	*TAG = "task_sdcard";
 static sdmmc_card_t* 	card = NULL;
-static uint8_t		s_pdrv = 0;
-//static char		* s_base_path = NULL;
 static uint8_t		pdrv = FF_DRV_NOT_USED;
+char			drv[3] = {'0', ':', 0};
 
 
 #define SDCARD_HOST_SLOT	VSPI_HOST		///< HSPI_HOST is used by the TFT
@@ -215,7 +214,7 @@
 
 
 
-static esp_err_t mount_prepare_mem(const char *base_path, BYTE *out_pdrv, char **out_dup_path, sdmmc_card_t** out_card)
+static esp_err_t mount_prepare_mem(const char *base_path, BYTE *out_pdrv, char **out_dup_path)
 {
     esp_err_t err = ESP_OK;
     char* dup_path = NULL;
@@ -231,7 +230,7 @@
     // not using ff_memalloc here, as allocation in internal RAM is preferred
     card = (sdmmc_card_t*)malloc(sizeof(sdmmc_card_t));
     if (card == NULL) {
-        ESP_LOGD(TAG, "could not locate new sdmmc_card_t");
+        ESP_LOGD(TAG, "could not malloc sdmmc_card_t");
         err = ESP_ERR_NO_MEM;
         goto cleanup;
     }
@@ -243,7 +242,6 @@
         goto cleanup;
     }
 
-    *out_card = card;
     *out_pdrv = pdrv;
     *out_dup_path = dup_path;
     return ESP_OK;
@@ -287,23 +285,23 @@
 	return ESP_ERR_INVALID_STATE;
     }
 
-    err = mount_prepare_mem(base_path, &pdrv, &dup_path, &card);
+    err = mount_prepare_mem(base_path, &pdrv, &dup_path);
     if (err != ESP_OK) {
-        ESP_LOGE(TAG, "mount_prepare failed");
+        ESP_LOGE(TAG, "mount_prepare_mem 0x%x", err);
         return err;
     }
 
     //the init() function is usually empty, doesn't require any deinit to revert it
     err = (*host_config->init)();
     if (err != ESP_OK) {
-        ESP_LOGE(TAG, "host init returned rc=0x%x", err);
+        ESP_LOGE(TAG, "host_config->init() 0x%x", err);
         goto fail;
     }
 
     // configure SD host
     err = my_init_sdspi_host(host_config->slot, slot_config, &card_handle);
     if (err != ESP_OK) {
-	ESP_LOGE(TAG, "my_init_sdspi_host() rc=0x%x", err);
+	ESP_LOGE(TAG, "my_init_sdspi_host() 0x%x", err);
 	goto fail;
     }
     return ESP_OK;
@@ -337,7 +335,7 @@
     esp_err_t err = ESP_OK;
 
     if (card == NULL) {
-	ESP_LOGE(TAG, "card not NULL");
+	ESP_LOGE(TAG, "card NULL");
 	return ESP_ERR_INVALID_STATE;
     }
 
@@ -356,7 +354,7 @@
     err = sdmmc_card_init(host_config, card);
     if (err != ESP_OK) {
 	if (err != ESP_ERR_INVALID_RESPONSE) {  // No card present, do not log
-	    ESP_LOGI(TAG, "sdmmc_card_init failed 0x(%x)", err);
+	    ESP_LOGI(TAG, "sdmmc_card_init failed 0x%x", err);
 	}
 	goto fail;
     }
@@ -369,9 +367,8 @@
      * mount to vfs fat
      */
     ff_diskio_register_sdmmc(pdrv, card);
-    s_pdrv = pdrv;
     ESP_LOGD(TAG, "using pdrv=%i", pdrv);
-    char drv[3] = {(char)('0' + pdrv), ':', 0};
+    drv[0] = (char)('0' + pdrv);
 
     // connect FATFS to VFS
     err = esp_vfs_fat_register(base_path, drv, mount_config->max_files, &fs);
@@ -383,6 +380,7 @@
     }
 
     // Try to mount partition
+    // See: esp-idf/components/fatfs/src/ff.h
     FRESULT res = f_mount(fs, drv, 1);
     if (res != FR_OK) {
 	err = ESP_FAIL;
@@ -412,7 +410,6 @@
 	return ESP_ERR_INVALID_STATE;
     }
     // unmount
-    char drv[3] = {(char)('0' + s_pdrv), ':', 0};
     f_mount(0, drv, 0);
     return ESP_OK;
 }
@@ -467,6 +464,8 @@
     ESP_LOGI(TAG, "Start SD card");
     sdmmc_host_t host = SDSPI_HOST_DEFAULT();
     host.slot = SDCARD_HOST_SLOT;	// HSPI_HOST is in use by the TFT.
+    //host.flags = SDMMC_HOST_FLAG_SPI | SDMMC_HOST_FLAG_DEINIT_ARG | SDMMC_HOST_FLAG_1BIT;
+    //host.max_freq_khz = 10000;
     spi_bus_config_t bus_cfg = {
         .mosi_io_num = SDCARD_PIN_NUM_MOSI,
         .miso_io_num = SDCARD_PIN_NUM_MISO,
@@ -491,7 +490,7 @@
     /*
      * No errors from the sdspi_transaction driver.
      */
-//    esp_log_level_set("sdspi_transaction", ESP_LOG_NONE);
+    esp_log_level_set("sdspi_transaction", ESP_LOG_NONE);
 
     /*
      * Options for mounting the filesystem.
@@ -513,7 +512,6 @@
 	vTaskDelete(NULL);
 	return;
     }
-
     xEventGroupSDcard = xEventGroupCreate();
 
     /*
@@ -532,7 +530,10 @@
 
 		DIR* dir = opendir("/sdcard/w/log");
 		if (dir == NULL) {
+		    ret = mkdir("/sdcard/w", 0755);
+		    ESP_LOGI(TAG, "mkdir(/sdcard/w)=%d", ret);
 		    ret = mkdir("/sdcard/w/log", 0755);
+		    ESP_LOGI(TAG, "mkdir(/sdcard/w/log)=%d", ret);
 		} else {
 		    closedir(dir);
 		}

mercurial