logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

flash_spi.h (3150B)


  1. /*
  2. Copyright (C) 2021 Westberry Technology (ChangZhou) Corp., Ltd
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include "flash.h"
  16. /* All the following default configurations are based on MX25L4006E Nor FLASH. */
  17. /*
  18. The slave select pin of the FLASH.
  19. This needs to be a normal GPIO pin_t value, such as B14.
  20. */
  21. #ifndef EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN
  22. # error "No chip select pin defined -- missing EXTERNAL_FLASH_SPI_SLAVE_SELECT_PIN"
  23. #endif
  24. /*
  25. The clock divisor for SPI to ensure that the MCU is within the
  26. specifications of the FLASH chip. Generally this will be PCLK divided by
  27. the intended divisor -- check your clock settings and the datasheet of
  28. your FLASH.
  29. */
  30. #ifndef EXTERNAL_FLASH_SPI_CLOCK_DIVISOR
  31. # ifdef __AVR__
  32. # define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 4
  33. # else
  34. # define EXTERNAL_FLASH_SPI_CLOCK_DIVISOR 8
  35. # endif
  36. #endif
  37. /*
  38. The SPI mode to communicate with the FLASH.
  39. */
  40. #ifndef EXTERNAL_FLASH_SPI_MODE
  41. # define EXTERNAL_FLASH_SPI_MODE 0
  42. #endif
  43. /*
  44. Whether or not the SPI communication between the MCU and FLASH should be
  45. LSB-first.
  46. */
  47. #ifndef EXTERNAL_FLASH_SPI_LSBFIRST
  48. # define EXTERNAL_FLASH_SPI_LSBFIRST false
  49. #endif
  50. /*
  51. The Flash address size in bytes, as specified in datasheet.
  52. */
  53. #ifndef EXTERNAL_FLASH_ADDRESS_SIZE
  54. # define EXTERNAL_FLASH_ADDRESS_SIZE 3
  55. #endif
  56. /*
  57. The page size of the FLASH in bytes, as specified in the datasheet.
  58. */
  59. #ifndef EXTERNAL_FLASH_PAGE_SIZE
  60. # define EXTERNAL_FLASH_PAGE_SIZE 256
  61. #endif
  62. /*
  63. The sector size of the FLASH in bytes, as specified in the datasheet.
  64. */
  65. #ifndef EXTERNAL_FLASH_SECTOR_SIZE
  66. # define EXTERNAL_FLASH_SECTOR_SIZE (4 * 1024L)
  67. #endif
  68. /*
  69. The block size of the FLASH in bytes, as specified in the datasheet.
  70. */
  71. #ifndef EXTERNAL_FLASH_BLOCK_SIZE
  72. # define EXTERNAL_FLASH_BLOCK_SIZE (64 * 1024L)
  73. #endif
  74. /*
  75. The total size of the FLASH in bytes, as specified in the datasheet.
  76. */
  77. #ifndef EXTERNAL_FLASH_SIZE
  78. # define EXTERNAL_FLASH_SIZE (512 * 1024L)
  79. #endif
  80. /*
  81. The block count of the FLASH, calculated by total FLASH size and block size.
  82. */
  83. #define EXTERNAL_FLASH_BLOCK_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_BLOCK_SIZE))
  84. /*
  85. The sector count of the FLASH, calculated by total FLASH size and sector size.
  86. */
  87. #define EXTERNAL_FLASH_SECTOR_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_SECTOR_SIZE))
  88. /*
  89. The page count of the FLASH, calculated by total FLASH size and page size.
  90. */
  91. #define EXTERNAL_FLASH_PAGE_COUNT ((EXTERNAL_FLASH_SIZE) / (EXTERNAL_FLASH_PAGE_SIZE))