spi_flash_chip_mxic.c 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <stdlib.h>
  15. #include "spi_flash_chip_generic.h"
  16. #include "spi_flash_defs.h"
  17. #include "esp_log.h"
  18. #include "hal/spi_flash_hal.h"
  19. /* Driver for MXIC flash chip */
  20. esp_err_t spi_flash_chip_mxic_probe(esp_flash_t *chip, uint32_t flash_id)
  21. {
  22. /* Check manufacturer and product IDs match our desired masks */
  23. const uint8_t MFG_ID = 0xC2;
  24. if (flash_id >> 16 != MFG_ID) {
  25. return ESP_ERR_NOT_FOUND;
  26. }
  27. if (chip->read_mode >= SPI_FLASH_OPI_FLAG) {
  28. // The code here serve for ordinary mxic chip. If opi mode has been selected, go `spi_flash_chip_mxic_opi.c`
  29. return ESP_ERR_NOT_FOUND;
  30. }
  31. return ESP_OK;
  32. }
  33. esp_err_t spi_flash_chip_issi_set_io_mode(esp_flash_t *chip);
  34. esp_err_t spi_flash_chip_issi_get_io_mode(esp_flash_t *chip, esp_flash_io_mode_t* out_io_mode);
  35. // Use the same implementation as ISSI chips
  36. #define spi_flash_chip_mxic_set_io_mode spi_flash_chip_issi_set_io_mode
  37. #define spi_flash_chip_mxic_get_io_mode spi_flash_chip_issi_get_io_mode
  38. #define spi_flash_chip_mxic_read_reg spi_flash_chip_generic_read_reg
  39. static const char chip_name[] = "mxic";
  40. spi_flash_caps_t spi_flash_chip_mxic_get_caps(esp_flash_t *chip)
  41. {
  42. spi_flash_caps_t caps_flags = 0;
  43. // 32-bit-address flash is not supported
  44. // flash-suspend is not supported
  45. // reading unique id is not supported.
  46. return caps_flags;
  47. }
  48. // The mxic chip can use the functions for generic chips except from set read mode and probe,
  49. // So we only replace these two functions.
  50. const spi_flash_chip_t esp_flash_chip_mxic = {
  51. .name = chip_name,
  52. .timeout = &spi_flash_chip_generic_timeout,
  53. .probe = spi_flash_chip_mxic_probe,
  54. .reset = spi_flash_chip_generic_reset,
  55. .detect_size = spi_flash_chip_generic_detect_size,
  56. .erase_chip = spi_flash_chip_generic_erase_chip,
  57. .erase_sector = spi_flash_chip_generic_erase_sector,
  58. .erase_block = spi_flash_chip_generic_erase_block,
  59. .sector_size = 4 * 1024,
  60. .block_erase_size = 64 * 1024,
  61. .get_chip_write_protect = spi_flash_chip_generic_get_write_protect,
  62. .set_chip_write_protect = spi_flash_chip_generic_set_write_protect,
  63. .num_protectable_regions = 0,
  64. .protectable_regions = NULL,
  65. .get_protected_regions = NULL,
  66. .set_protected_regions = NULL,
  67. .read = spi_flash_chip_generic_read,
  68. .write = spi_flash_chip_generic_write,
  69. .program_page = spi_flash_chip_generic_page_program,
  70. .page_size = 256,
  71. .write_encrypted = spi_flash_chip_generic_write_encrypted,
  72. .wait_idle = spi_flash_chip_generic_wait_idle,
  73. .set_io_mode = spi_flash_chip_mxic_set_io_mode,
  74. .get_io_mode = spi_flash_chip_mxic_get_io_mode,
  75. .read_reg = spi_flash_chip_mxic_read_reg,
  76. .yield = spi_flash_chip_generic_yield,
  77. .sus_setup = spi_flash_chip_generic_suspend_cmd_conf,
  78. .read_unique_id = spi_flash_chip_generic_read_unique_id_none,
  79. .get_chip_caps = spi_flash_chip_mxic_get_caps,
  80. .config_host_io_mode = spi_flash_chip_generic_config_host_io_mode,
  81. };