spi_flash_override.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include "sdkconfig.h"
  8. #include "esp_err.h"
  9. #pragma once
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @brief Structure for flash dummy bits.
  15. * For some flash chips, dummy bits are configurable under different conditions.
  16. */
  17. typedef struct {
  18. uint8_t dio_dummy;
  19. uint8_t dout_dummy;
  20. uint8_t qio_dummy;
  21. uint8_t qout_dummy;
  22. uint8_t fastrd_dummy;
  23. } spi_flash_hpm_dummy_conf_t;
  24. typedef enum {
  25. SPI_FLASH_HPM_CMD_NEEDED, // Means that in the certain condition, flash needs to enter the high performance mode by command.
  26. SPI_FLASH_HPM_DUMMY_NEEDED, // Means that in the certain condition, flash needs to enter the high performance mode by adjusting dummy.
  27. SPI_FLASH_HPM_WRITE_SR_NEEDED, // Means that in the certain condition, flash needs to enter the high performance mode by writing status register.
  28. SPI_FLASH_HPM_UNNEEDED, // Means that flash doesn't need to enter the high performance mode.
  29. SPI_FLASH_HPM_BEYOND_LIMIT, // Means that flash has no capability to meet that condition.
  30. } spi_flash_requirement_t;
  31. typedef void (*spi_flash_hpm_enable_fn_t)(void);
  32. typedef esp_err_t (*spi_flash_hpf_check_fn_t)(void);
  33. typedef void (*spi_flash_get_chip_dummy_fn_t)(spi_flash_hpm_dummy_conf_t *dummy_conf);
  34. typedef esp_err_t (*spi_flash_hpm_probe_fn_t)(uint32_t flash_id);
  35. typedef spi_flash_requirement_t (*spi_flash_hpm_chip_requirement_check_t)(uint32_t flash_id, uint32_t freq_mhz, int voltage_mv, int temperature);
  36. typedef struct __attribute__((packed))
  37. {
  38. const char *method; /* Flash HPM method */
  39. spi_flash_hpm_probe_fn_t probe;
  40. spi_flash_hpm_chip_requirement_check_t chip_hpm_requirement_check;
  41. spi_flash_hpm_enable_fn_t flash_hpm_enable;
  42. spi_flash_hpf_check_fn_t flash_hpf_check;
  43. spi_flash_get_chip_dummy_fn_t flash_get_dummy;
  44. } spi_flash_hpm_info_t;
  45. /**
  46. * @brief Enum for user to select valid wrap size.
  47. */
  48. typedef enum {
  49. FLASH_WRAP_SIZE_8B = 8,
  50. FLASH_WRAP_SIZE_16B = 16,
  51. FLASH_WRAP_SIZE_32B = 32,
  52. FLASH_WRAP_SIZE_64B = 64,
  53. } spi_flash_wrap_size_t;
  54. /**
  55. * @brief Probe flash wrap method
  56. *
  57. * @param flash_id Flash chip ID
  58. *
  59. * @return ESP_OK: If succeed
  60. */
  61. typedef esp_err_t (*spi_flash_wrap_probe_fn_t)(uint32_t flash_id);
  62. /**
  63. * @brief Set flash wrap
  64. *
  65. * @param wrap_size: wrap_size
  66. *
  67. * @return ESP_OK: If succeed
  68. */
  69. typedef esp_err_t (*spi_flash_wrap_set_fn_t)(spi_flash_wrap_size_t wrap_size);
  70. /**
  71. * @brief Clear flash wrap.
  72. *
  73. * @return ESP_OK: If succeed
  74. */
  75. typedef esp_err_t (*spi_flash_wrap_clr_fn_t)(void);
  76. typedef struct __attribute__((packed))
  77. {
  78. const char *method;
  79. spi_flash_wrap_probe_fn_t probe;
  80. spi_flash_wrap_set_fn_t chip_wrap_set;
  81. spi_flash_wrap_clr_fn_t chip_wrap_clr;
  82. } spi_flash_wrap_info_t;
  83. /**
  84. * Array of known flash chips and method to enable flash high performance mode.
  85. *
  86. * Users can override this array.
  87. */
  88. extern const spi_flash_hpm_info_t __attribute__((weak)) spi_flash_hpm_enable_list[];
  89. #ifdef __cplusplus
  90. }
  91. #endif