sdcard_init.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stddef.h>
  8. #include "esp_err.h"
  9. #include "driver/gpio.h"
  10. #include "sdmmc_cmd.h"
  11. #include "driver/sdmmc_types.h"
  12. #include "driver/sdspi_host.h"
  13. #include "ff.h"
  14. #include "esp_vfs_fat.h"
  15. #include "wear_levelling.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @brief Convenience function to get FAT filesystem on SD card registered in VFS
  21. *
  22. * This is an all-in-one function which does the following:
  23. * - initializes SDMMC driver or SPI driver with configuration in host_config
  24. * - initializes SD card with configuration in slot_config
  25. * - mounts FAT partition on SD card using FATFS library, with configuration in mount_config
  26. * - registers FATFS library with VFS, with prefix given by base_prefix variable
  27. *
  28. * This function is intended to make example code more compact.
  29. * For real world applications, developers should implement the logic of
  30. * probing SD card, locating and mounting partition, and registering FATFS in VFS,
  31. * with proper error checking and handling of exceptional conditions.
  32. *
  33. * @note Use this API to mount a card through SDSPI is deprecated. Please call
  34. * `esp_vfs_fat_sdspi_mount()` instead for that case.
  35. *
  36. * @param base_path path where partition should be registered (e.g. "/sdcard")
  37. * @param host_config Pointer to structure describing SDMMC host. When using
  38. * SDMMC peripheral, this structure can be initialized using
  39. * SDMMC_HOST_DEFAULT() macro. When using SPI peripheral,
  40. * this structure can be initialized using SDSPI_HOST_DEFAULT()
  41. * macro.
  42. * @param slot_config Pointer to structure with slot configuration.
  43. * For SDMMC peripheral, pass a pointer to sdmmc_slot_config_t
  44. * structure initialized using SDMMC_SLOT_CONFIG_DEFAULT.
  45. * @param mount_config pointer to structure with extra parameters for mounting FATFS
  46. * @param[out] out_card if not NULL, pointer to the card information structure will be returned via this argument
  47. * @return
  48. * - ESP_OK on success
  49. * - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
  50. * - ESP_ERR_NO_MEM if memory can not be allocated
  51. * - ESP_FAIL if partition can not be mounted
  52. * - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
  53. */
  54. esp_err_t esp_vfs_fat_sdmmc_mount_mh(const char* base_path, const sdmmc_host_t* host_config, const void* slot_config, const esp_vfs_fat_mount_config_t* mount_config, sdmmc_card_t** out_card);
  55. /**
  56. * @brief Convenience function to get FAT filesystem on SD card registered in VFS
  57. *
  58. * This is an all-in-one function which does the following:
  59. * - initializes an SPI Master device based on the SPI Master driver with configuration in
  60. * slot_config, and attach it to an initialized SPI bus.
  61. * - initializes SD card with configuration in host_config_input
  62. * - mounts FAT partition on SD card using FATFS library, with configuration in mount_config
  63. * - registers FATFS library with VFS, with prefix given by base_prefix variable
  64. *
  65. * This function is intended to make example code more compact.
  66. * For real world applications, developers should implement the logic of
  67. * probing SD card, locating and mounting partition, and registering FATFS in VFS,
  68. * with proper error checking and handling of exceptional conditions.
  69. *
  70. * @note This function try to attach the new SD SPI device to the bus specified in host_config.
  71. * Make sure the SPI bus specified in `host_config->slot` have been initialized by
  72. * `spi_bus_initialize()` before.
  73. *
  74. * @param base_path path where partition should be registered (e.g. "/sdcard")
  75. * @param host_config_input Pointer to structure describing SDMMC host. This structure can be
  76. * initialized using SDSPI_HOST_DEFAULT() macro.
  77. * @param slot_config Pointer to structure with slot configuration.
  78. * For SPI peripheral, pass a pointer to sdspi_device_config_t
  79. * structure initialized using SDSPI_DEVICE_CONFIG_DEFAULT().
  80. * @param mount_config pointer to structure with extra parameters for mounting FATFS
  81. * @param[out] out_card If not NULL, pointer to the card information structure will be returned via
  82. * this argument. It is suggested to hold this handle and use it to unmount the card later if
  83. * needed. Otherwise it's not suggested to use more than one card at the same time and unmount one
  84. * of them in your application.
  85. * @return
  86. * - ESP_OK on success
  87. * - ESP_ERR_INVALID_STATE if esp_vfs_fat_sdmmc_mount was already called
  88. * - ESP_ERR_NO_MEM if memory can not be allocated
  89. * - ESP_FAIL if partition can not be mounted
  90. * - other error codes from SDMMC or SPI drivers, SDMMC protocol, or FATFS drivers
  91. */
  92. esp_err_t esp_vfs_fat_sdspi_mount_mh(const char* base_path, const sdmmc_host_t* host_config_input, const sdspi_device_config_t* slot_config, const esp_vfs_fat_mount_config_t* mount_config, sdmmc_card_t** out_card);
  93. #ifdef __cplusplus
  94. }
  95. #endif