465 json_log = malloc(sizeof(JSON_log)); |
465 json_log = malloc(sizeof(JSON_log)); |
466 |
466 |
467 ESP_LOGI(TAG, "Start SD card"); |
467 ESP_LOGI(TAG, "Start SD card"); |
468 sdmmc_host_t host = SDSPI_HOST_DEFAULT(); |
468 sdmmc_host_t host = SDSPI_HOST_DEFAULT(); |
469 host.slot = SDCARD_HOST_SLOT; // HSPI_HOST is in use by the TFT. |
469 host.slot = SDCARD_HOST_SLOT; // HSPI_HOST is in use by the TFT. |
|
470 host.max_freq_khz = 20000; // 20 MHz speed limit. |
470 spi_bus_config_t bus_cfg = { |
471 spi_bus_config_t bus_cfg = { |
471 .mosi_io_num = SDCARD_PIN_NUM_MOSI, |
472 .mosi_io_num = SDCARD_PIN_NUM_MOSI, |
472 .miso_io_num = SDCARD_PIN_NUM_MISO, |
473 .miso_io_num = SDCARD_PIN_NUM_MISO, |
473 .sclk_io_num = SDCARD_PIN_NUM_CLK, |
474 .sclk_io_num = SDCARD_PIN_NUM_CLK, |
474 .quadwp_io_num = -1, |
475 .quadwp_io_num = -1, |
487 sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); |
488 sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT(); |
488 slot_config.gpio_cs = SDCARD_PIN_NUM_CS; |
489 slot_config.gpio_cs = SDCARD_PIN_NUM_CS; |
489 slot_config.host_id = host.slot; |
490 slot_config.host_id = host.slot; |
490 |
491 |
491 /* |
492 /* |
|
493 * Since IDF 5.0 the SD card is dead slow. Use pullup resistors |
|
494 * on the board, see schematic. |
|
495 * Or just use gpio pullup as workaround. |
|
496 * Or both (not tested). |
|
497 * See https://github.com/espressif/esp-idf/issues/10493 |
|
498 */ |
|
499 gpio_set_pull_mode(SDCARD_PIN_NUM_MOSI, GPIO_PULLUP_ONLY); |
|
500 gpio_set_pull_mode(SDCARD_PIN_NUM_MISO, GPIO_PULLUP_ONLY); |
|
501 gpio_set_pull_mode(SDCARD_PIN_NUM_CLK, GPIO_PULLUP_ONLY); |
|
502 gpio_set_pull_mode(SDCARD_PIN_NUM_CS, GPIO_PULLUP_ONLY); |
|
503 |
|
504 /* |
492 * No errors from the sdspi_transaction driver. |
505 * No errors from the sdspi_transaction driver. |
493 */ |
506 */ |
494 esp_log_level_set("sdspi_transaction", ESP_LOG_NONE); |
507 esp_log_level_set("sdspi_transaction", ESP_LOG_NONE); |
495 |
508 |
496 /* |
509 /* |
504 .allocation_unit_size = 16 * 1024 |
517 .allocation_unit_size = 16 * 1024 |
505 }; |
518 }; |
506 |
519 |
507 ret = my_vfs_fat_sdspi_init("/sdcard", &host, &slot_config); |
520 ret = my_vfs_fat_sdspi_init("/sdcard", &host, &slot_config); |
508 if (ret == ESP_OK) { |
521 if (ret == ESP_OK) { |
509 ESP_LOGI(TAG, "SPI card interface ready"); |
522 ESP_LOGI(TAG, "SD card interface ready"); |
510 sdcard_state->host_ok = true; |
523 sdcard_state->host_ok = true; |
511 } else { |
524 } else { |
512 ESP_LOGE(TAG, "SPI card interface failed, abort task"); |
525 ESP_LOGE(TAG, "SD card interface failed: %s, abort task", esp_err_to_name(ret)); |
513 vTaskDelete(NULL); |
526 vTaskDelete(NULL); |
514 return; |
527 return; |
515 } |
528 } |
516 xEventGroupSDcard = xEventGroupCreate(); |
529 xEventGroupSDcard = xEventGroupCreate(); |
517 |
530 |