spi_flash_chip_mxic.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /* Driver for MXIC flash chip */
  18. esp_err_t spi_flash_chip_mxic_probe(esp_flash_t *chip, uint32_t flash_id)
  19. {
  20. /* Check manufacturer and product IDs match our desired masks */
  21. const uint8_t MFG_ID = 0xC2;
  22. if (flash_id >> 16 != MFG_ID) {
  23. return ESP_ERR_NOT_FOUND;
  24. }
  25. return ESP_OK;
  26. }
  27. esp_err_t spi_flash_chip_issi_set_io_mode(esp_flash_t *chip);
  28. esp_err_t spi_flash_chip_issi_get_io_mode(esp_flash_t *chip, esp_flash_io_mode_t* out_io_mode);
  29. // Use the same implementation as ISSI chips
  30. #define spi_flash_chip_mxic_set_io_mode spi_flash_chip_issi_set_io_mode
  31. #define spi_flash_chip_mxic_get_io_mode spi_flash_chip_issi_get_io_mode
  32. static const char chip_name[] = "mxic";
  33. // The mxic chip can use the functions for generic chips except from set read mode and probe,
  34. // So we only replace these two functions.
  35. const spi_flash_chip_t esp_flash_chip_mxic = {
  36. .name = chip_name,
  37. .probe = spi_flash_chip_mxic_probe,
  38. .reset = spi_flash_chip_generic_reset,
  39. .detect_size = spi_flash_chip_generic_detect_size,
  40. .erase_chip = spi_flash_chip_generic_erase_chip,
  41. .erase_sector = spi_flash_chip_generic_erase_sector,
  42. .erase_block = spi_flash_chip_generic_erase_block,
  43. .sector_size = 4 * 1024,
  44. .block_erase_size = 64 * 1024,
  45. .get_chip_write_protect = spi_flash_chip_generic_get_write_protect,
  46. .set_chip_write_protect = spi_flash_chip_generic_set_write_protect,
  47. // TODO support protected regions on MXIC flash
  48. .num_protectable_regions = 0,
  49. .protectable_regions = NULL,
  50. .get_protected_regions = NULL,
  51. .set_protected_regions = NULL,
  52. .read = spi_flash_chip_generic_read,
  53. .write = spi_flash_chip_generic_write,
  54. .program_page = spi_flash_chip_generic_page_program,
  55. .page_size = 256,
  56. .write_encrypted = spi_flash_chip_generic_write_encrypted,
  57. .wait_idle = spi_flash_chip_generic_wait_idle,
  58. .set_io_mode = spi_flash_chip_mxic_set_io_mode,
  59. .get_io_mode = spi_flash_chip_mxic_get_io_mode,
  60. };