spi_flash.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. // Copyright 2010-2016 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. #ifndef _ROM_SPI_FLASH_H_
  15. #define _ROM_SPI_FLASH_H_
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include "esp_attr.h"
  19. #include "sdkconfig.h"
  20. #ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS
  21. #include "soc/spi_reg.h"
  22. #endif
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /** \defgroup spi_flash_apis, spi flash operation related apis
  27. * @brief spi_flash apis
  28. */
  29. /** @addtogroup spi_flash_apis
  30. * @{
  31. */
  32. /*************************************************************
  33. * Note
  34. *************************************************************
  35. * 1. ESP32 chip have 4 SPI slave/master, however, SPI0 is
  36. * used as an SPI master to access Flash and ext-SRAM by
  37. * Cache module. It will support Decryto read for Flash,
  38. * read/write for ext-SRAM. And SPI1 is also used as an
  39. * SPI master for Flash read/write and ext-SRAM read/write.
  40. * It will support Encrypto write for Flash.
  41. * 2. As an SPI master, SPI support Highest clock to 80M,
  42. * however, Flash with 80M Clock should be configured
  43. * for different Flash chips. If you want to use 80M
  44. * clock We should use the SPI that is certified by
  45. * Espressif. However, the certification is not started
  46. * at the time, so please use 40M clock at the moment.
  47. * 3. SPI Flash can use 2 lines or 4 lines mode. If you
  48. * use 2 lines mode, you can save two pad SPIHD and
  49. * SPIWP for gpio. ESP32 support configured SPI pad for
  50. * Flash, the configuration is stored in efuse and flash.
  51. * However, the configurations of pads should be certified
  52. * by Espressif. If you use this function, please use 40M
  53. * clock at the moment.
  54. * 4. ESP32 support to use Common SPI command to configure
  55. * Flash to QIO mode, if you failed to configure with fix
  56. * command. With Common SPI Command, ESP32 can also provide
  57. * a way to use same Common SPI command groups on different
  58. * Flash chips.
  59. * 5. This functions are not protected by packeting, Please use the
  60. *************************************************************
  61. */
  62. #define PERIPHS_SPI_FLASH_CMD SPI_CMD_REG(1)
  63. #define PERIPHS_SPI_FLASH_ADDR SPI_ADDR_REG(1)
  64. #define PERIPHS_SPI_FLASH_CTRL SPI_CTRL_REG(1)
  65. #define PERIPHS_SPI_FLASH_CTRL1 SPI_CTRL1_REG(1)
  66. #define PERIPHS_SPI_FLASH_STATUS SPI_RD_STATUS_REG(1)
  67. #define PERIPHS_SPI_FLASH_USRREG SPI_USER_REG(1)
  68. #define PERIPHS_SPI_FLASH_USRREG1 SPI_USER1_REG(1)
  69. #define PERIPHS_SPI_FLASH_USRREG2 SPI_USER2_REG(1)
  70. #define PERIPHS_SPI_FLASH_C0 SPI_W0_REG(1)
  71. #define PERIPHS_SPI_FLASH_C1 SPI_W1_REG(1)
  72. #define PERIPHS_SPI_FLASH_C2 SPI_W2_REG(1)
  73. #define PERIPHS_SPI_FLASH_C3 SPI_W3_REG(1)
  74. #define PERIPHS_SPI_FLASH_C4 SPI_W4_REG(1)
  75. #define PERIPHS_SPI_FLASH_C5 SPI_W5_REG(1)
  76. #define PERIPHS_SPI_FLASH_C6 SPI_W6_REG(1)
  77. #define PERIPHS_SPI_FLASH_C7 SPI_W7_REG(1)
  78. #define PERIPHS_SPI_FLASH_TX_CRC SPI_TX_CRC_REG(1)
  79. #define SPI0_R_QIO_DUMMY_CYCLELEN 3
  80. #define SPI0_R_QIO_ADDR_BITSLEN 31
  81. #define SPI0_R_FAST_DUMMY_CYCLELEN 7
  82. #define SPI0_R_DIO_DUMMY_CYCLELEN 1
  83. #define SPI0_R_DIO_ADDR_BITSLEN 27
  84. #define SPI0_R_FAST_ADDR_BITSLEN 23
  85. #define SPI0_R_SIO_ADDR_BITSLEN 23
  86. #define SPI1_R_QIO_DUMMY_CYCLELEN 3
  87. #define SPI1_R_QIO_ADDR_BITSLEN 31
  88. #define SPI1_R_FAST_DUMMY_CYCLELEN 7
  89. #define SPI1_R_DIO_DUMMY_CYCLELEN 3
  90. #define SPI1_R_DIO_ADDR_BITSLEN 31
  91. #define SPI1_R_FAST_ADDR_BITSLEN 23
  92. #define SPI1_R_SIO_ADDR_BITSLEN 23
  93. #define ESP_ROM_SPIFLASH_W_SIO_ADDR_BITSLEN 23
  94. #define ESP_ROM_SPIFLASH_TWO_BYTE_STATUS_EN SPI_WRSR_2B
  95. //SPI address register
  96. #define ESP_ROM_SPIFLASH_BYTES_LEN 24
  97. #define ESP_ROM_SPIFLASH_BUFF_BYTE_WRITE_NUM 32
  98. #define ESP_ROM_SPIFLASH_BUFF_BYTE_READ_NUM 64
  99. #define ESP_ROM_SPIFLASH_BUFF_BYTE_READ_BITS 0x3f
  100. //SPI status register
  101. #define ESP_ROM_SPIFLASH_BUSY_FLAG BIT0
  102. #define ESP_ROM_SPIFLASH_WRENABLE_FLAG BIT1
  103. #define ESP_ROM_SPIFLASH_BP0 BIT2
  104. #define ESP_ROM_SPIFLASH_BP1 BIT3
  105. #define ESP_ROM_SPIFLASH_BP2 BIT4
  106. #define ESP_ROM_SPIFLASH_WR_PROTECT (ESP_ROM_SPIFLASH_BP0|ESP_ROM_SPIFLASH_BP1|ESP_ROM_SPIFLASH_BP2)
  107. #define ESP_ROM_SPIFLASH_QE BIT9
  108. #define ESP_ROM_SPIFLASH_BP_MASK_ISSI (BIT7 | BIT5 | BIT4 | BIT3 | BIT2)
  109. //Extra dummy for flash read
  110. #define ESP_ROM_SPIFLASH_DUMMY_LEN_PLUS_20M 0
  111. #define ESP_ROM_SPIFLASH_DUMMY_LEN_PLUS_26M 0
  112. #define ESP_ROM_SPIFLASH_DUMMY_LEN_PLUS_40M 1
  113. #define ESP_ROM_SPIFLASH_DUMMY_LEN_PLUS_80M 2
  114. #define FLASH_ID_GD25LQ32C 0xC86016
  115. typedef enum {
  116. ESP_ROM_SPIFLASH_QIO_MODE = 0,
  117. ESP_ROM_SPIFLASH_QOUT_MODE,
  118. ESP_ROM_SPIFLASH_DIO_MODE,
  119. ESP_ROM_SPIFLASH_DOUT_MODE,
  120. ESP_ROM_SPIFLASH_FASTRD_MODE,
  121. ESP_ROM_SPIFLASH_SLOWRD_MODE
  122. } esp_rom_spiflash_read_mode_t;
  123. typedef enum {
  124. ESP_ROM_SPIFLASH_RESULT_OK,
  125. ESP_ROM_SPIFLASH_RESULT_ERR,
  126. ESP_ROM_SPIFLASH_RESULT_TIMEOUT
  127. } esp_rom_spiflash_result_t;
  128. typedef struct {
  129. uint32_t device_id;
  130. uint32_t chip_size; // chip size in bytes
  131. uint32_t block_size;
  132. uint32_t sector_size;
  133. uint32_t page_size;
  134. uint32_t status_mask;
  135. } esp_rom_spiflash_chip_t;
  136. typedef struct {
  137. uint8_t data_length;
  138. uint8_t read_cmd0;
  139. uint8_t read_cmd1;
  140. uint8_t write_cmd;
  141. uint16_t data_mask;
  142. uint16_t data;
  143. } esp_rom_spiflash_common_cmd_t;
  144. /**
  145. * @brief Fix the bug in SPI hardware communication with Flash/Ext-SRAM in High Speed.
  146. * Please do not call this function in SDK.
  147. *
  148. * @param uint8_t spi: 0 for SPI0(Cache Access), 1 for SPI1(Flash read/write).
  149. *
  150. * @param uint8_t freqdiv: Pll is 80M, 4 for 20M, 3 for 26.7M, 2 for 40M, 1 for 80M.
  151. *
  152. * @return None
  153. */
  154. void esp_rom_spiflash_fix_dummylen(uint8_t spi, uint8_t freqdiv);
  155. /**
  156. * @brief Select SPI Flash to QIO mode when WP pad is read from Flash.
  157. * Please do not call this function in SDK.
  158. *
  159. * @param uint8_t wp_gpio_num: WP gpio number.
  160. *
  161. * @param uint32_t ishspi: 0 for spi, 1 for hspi, flash pad decided by strapping
  162. * else, bit[5:0] spiclk, bit[11:6] spiq, bit[17:12] spid, bit[23:18] spics0, bit[29:24] spihd
  163. *
  164. * @return None
  165. */
  166. void esp_rom_spiflash_select_qiomode(uint8_t wp_gpio_num, uint32_t ishspi);
  167. /**
  168. * @brief Set SPI Flash pad drivers.
  169. * Please do not call this function in SDK.
  170. *
  171. * @param uint8_t wp_gpio_num: WP gpio number.
  172. *
  173. * @param uint32_t ishspi: 0 for spi, 1 for hspi, flash pad decided by strapping
  174. * else, bit[5:0] spiclk, bit[11:6] spiq, bit[17:12] spid, bit[23:18] spics0, bit[29:24] spihd
  175. *
  176. * @param uint8_t *drvs: drvs[0]-bit[3:0] for cpiclk, bit[7:4] for spiq, drvs[1]-bit[3:0] for spid, drvs[1]-bit[7:4] for spid
  177. * drvs[2]-bit[3:0] for spihd, drvs[2]-bit[7:4] for spiwp.
  178. * Values usually read from falsh by rom code, function usually callde by rom code.
  179. * if value with bit(3) set, the value is valid, bit[2:0] is the real value.
  180. *
  181. * @return None
  182. */
  183. void esp_rom_spiflash_set_drvs(uint8_t wp_gpio_num, uint32_t ishspi, uint8_t *drvs);
  184. /**
  185. * @brief Select SPI Flash function for pads.
  186. * Please do not call this function in SDK.
  187. *
  188. * @param uint32_t ishspi: 0 for spi, 1 for hspi, flash pad decided by strapping
  189. * else, bit[5:0] spiclk, bit[11:6] spiq, bit[17:12] spid, bit[23:18] spics0, bit[29:24] spihd
  190. *
  191. * @return None
  192. */
  193. void esp_rom_spiflash_select_padsfunc(uint32_t ishspi);
  194. /**
  195. * @brief SPI Flash init, clock divisor is 4, use 1 line Slow read mode.
  196. * Please do not call this function in SDK.
  197. *
  198. * @param uint32_t ishspi: 0 for spi, 1 for hspi, flash pad decided by strapping
  199. * else, bit[5:0] spiclk, bit[11:6] spiq, bit[17:12] spid, bit[23:18] spics0, bit[29:24] spihd
  200. *
  201. * @param uint8_t legacy: In legacy mode, more SPI command is used in line.
  202. *
  203. * @return None
  204. */
  205. void esp_rom_spiflash_attach(uint32_t ishspi, bool legacy);
  206. /**
  207. * @brief SPI Read Flash status register. We use CMD 0x05 (RDSR).
  208. * Please do not call this function in SDK.
  209. *
  210. * @param esp_rom_spiflash_chip_t *spi : The information for Flash, which is exported from ld file.
  211. *
  212. * @param uint32_t *status : The pointer to which to return the Flash status value.
  213. *
  214. * @return ESP_ROM_SPIFLASH_RESULT_OK : read OK.
  215. * ESP_ROM_SPIFLASH_RESULT_ERR : read error.
  216. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : read timeout.
  217. */
  218. esp_rom_spiflash_result_t esp_rom_spiflash_read_status(esp_rom_spiflash_chip_t *spi, uint32_t *status);
  219. /**
  220. * @brief SPI Read Flash status register bits 8-15. We use CMD 0x35 (RDSR2).
  221. * Please do not call this function in SDK.
  222. *
  223. * @param esp_rom_spiflash_chip_t *spi : The information for Flash, which is exported from ld file.
  224. *
  225. * @param uint32_t *status : The pointer to which to return the Flash status value.
  226. *
  227. * @return ESP_ROM_SPIFLASH_RESULT_OK : read OK.
  228. * ESP_ROM_SPIFLASH_RESULT_ERR : read error.
  229. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : read timeout.
  230. */
  231. esp_rom_spiflash_result_t esp_rom_spiflash_read_statushigh(esp_rom_spiflash_chip_t *spi, uint32_t *status);
  232. /**
  233. * @brief Write status to Flash status register.
  234. * Please do not call this function in SDK.
  235. *
  236. * @param esp_rom_spiflash_chip_t *spi : The information for Flash, which is exported from ld file.
  237. *
  238. * @param uint32_t status_value : Value to .
  239. *
  240. * @return ESP_ROM_SPIFLASH_RESULT_OK : write OK.
  241. * ESP_ROM_SPIFLASH_RESULT_ERR : write error.
  242. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : write timeout.
  243. */
  244. esp_rom_spiflash_result_t esp_rom_spiflash_write_status(esp_rom_spiflash_chip_t *spi, uint32_t status_value);
  245. /**
  246. * @brief Use a command to Read Flash status register.
  247. * Please do not call this function in SDK.
  248. *
  249. * @param esp_rom_spiflash_chip_t *spi : The information for Flash, which is exported from ld file.
  250. *
  251. * @param uint32_t*status : The pointer to which to return the Flash status value.
  252. *
  253. * @return ESP_ROM_SPIFLASH_RESULT_OK : read OK.
  254. * ESP_ROM_SPIFLASH_RESULT_ERR : read error.
  255. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : read timeout.
  256. */
  257. esp_rom_spiflash_result_t esp_rom_spiflash_read_user_cmd(uint32_t *status, uint8_t cmd);
  258. /**
  259. * @brief Config SPI Flash read mode when init.
  260. * Please do not call this function in SDK.
  261. *
  262. * @param esp_rom_spiflash_read_mode_t mode : QIO/QOUT/DIO/DOUT/FastRD/SlowRD.
  263. *
  264. * This function does not try to set the QIO Enable bit in the status register, caller is responsible for this.
  265. *
  266. * @return ESP_ROM_SPIFLASH_RESULT_OK : config OK.
  267. * ESP_ROM_SPIFLASH_RESULT_ERR : config error.
  268. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : config timeout.
  269. */
  270. esp_rom_spiflash_result_t esp_rom_spiflash_config_readmode(esp_rom_spiflash_read_mode_t mode);
  271. /**
  272. * @brief Config SPI Flash clock divisor.
  273. * Please do not call this function in SDK.
  274. *
  275. * @param uint8_t freqdiv: clock divisor.
  276. *
  277. * @param uint8_t spi: 0 for SPI0, 1 for SPI1.
  278. *
  279. * @return ESP_ROM_SPIFLASH_RESULT_OK : config OK.
  280. * ESP_ROM_SPIFLASH_RESULT_ERR : config error.
  281. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : config timeout.
  282. */
  283. esp_rom_spiflash_result_t esp_rom_spiflash_config_clk(uint8_t freqdiv, uint8_t spi);
  284. /**
  285. * @brief Send CommonCmd to Flash so that is can go into QIO mode, some Flash use different CMD.
  286. * Please do not call this function in SDK.
  287. *
  288. * @param esp_rom_spiflash_common_cmd_t *cmd : A struct to show the action of a command.
  289. *
  290. * @return uint16_t 0 : do not send command any more.
  291. * 1 : go to the next command.
  292. * n > 1 : skip (n - 1) commands.
  293. */
  294. uint16_t esp_rom_spiflash_common_cmd(esp_rom_spiflash_common_cmd_t *cmd);
  295. /**
  296. * @brief Unlock SPI write protect.
  297. * Please do not call this function in SDK.
  298. *
  299. * @param None.
  300. *
  301. * @return ESP_ROM_SPIFLASH_RESULT_OK : Unlock OK.
  302. * ESP_ROM_SPIFLASH_RESULT_ERR : Unlock error.
  303. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Unlock timeout.
  304. */
  305. esp_rom_spiflash_result_t esp_rom_spiflash_unlock(void);
  306. /**
  307. * @brief SPI write protect.
  308. * Please do not call this function in SDK.
  309. *
  310. * @param None.
  311. *
  312. * @return ESP_ROM_SPIFLASH_RESULT_OK : Lock OK.
  313. * ESP_ROM_SPIFLASH_RESULT_ERR : Lock error.
  314. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Lock timeout.
  315. */
  316. esp_rom_spiflash_result_t esp_rom_spiflash_lock(void);
  317. /**
  318. * @brief Update SPI Flash parameter.
  319. * Please do not call this function in SDK.
  320. *
  321. * @param uint32_t deviceId : Device ID read from SPI, the low 32 bit.
  322. *
  323. * @param uint32_t chip_size : The Flash size.
  324. *
  325. * @param uint32_t block_size : The Flash block size.
  326. *
  327. * @param uint32_t sector_size : The Flash sector size.
  328. *
  329. * @param uint32_t page_size : The Flash page size.
  330. *
  331. * @param uint32_t status_mask : The Mask used when read status from Flash(use single CMD).
  332. *
  333. * @return ESP_ROM_SPIFLASH_RESULT_OK : Update OK.
  334. * ESP_ROM_SPIFLASH_RESULT_ERR : Update error.
  335. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Update timeout.
  336. */
  337. esp_rom_spiflash_result_t esp_rom_spiflash_config_param(uint32_t deviceId, uint32_t chip_size, uint32_t block_size,
  338. uint32_t sector_size, uint32_t page_size, uint32_t status_mask);
  339. /**
  340. * @brief Erase whole flash chip.
  341. * Please do not call this function in SDK.
  342. *
  343. * @param None
  344. *
  345. * @return ESP_ROM_SPIFLASH_RESULT_OK : Erase OK.
  346. * ESP_ROM_SPIFLASH_RESULT_ERR : Erase error.
  347. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Erase timeout.
  348. */
  349. esp_rom_spiflash_result_t esp_rom_spiflash_erase_chip(void);
  350. /**
  351. * @brief Erase a 64KB block of flash
  352. * Uses SPI flash command D8H.
  353. * Please do not call this function in SDK.
  354. *
  355. * @param uint32_t block_num : Which block to erase.
  356. *
  357. * @return ESP_ROM_SPIFLASH_RESULT_OK : Erase OK.
  358. * ESP_ROM_SPIFLASH_RESULT_ERR : Erase error.
  359. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Erase timeout.
  360. */
  361. esp_rom_spiflash_result_t esp_rom_spiflash_erase_block(uint32_t block_num);
  362. /**
  363. * @brief Erase a sector of flash.
  364. * Uses SPI flash command 20H.
  365. * Please do not call this function in SDK.
  366. *
  367. * @param uint32_t sector_num : Which sector to erase.
  368. *
  369. * @return ESP_ROM_SPIFLASH_RESULT_OK : Erase OK.
  370. * ESP_ROM_SPIFLASH_RESULT_ERR : Erase error.
  371. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Erase timeout.
  372. */
  373. esp_rom_spiflash_result_t esp_rom_spiflash_erase_sector(uint32_t sector_num);
  374. /**
  375. * @brief Erase some sectors.
  376. * Please do not call this function in SDK.
  377. *
  378. * @param uint32_t start_addr : Start addr to erase, should be sector aligned.
  379. *
  380. * @param uint32_t area_len : Length to erase, should be sector aligned.
  381. *
  382. * @return ESP_ROM_SPIFLASH_RESULT_OK : Erase OK.
  383. * ESP_ROM_SPIFLASH_RESULT_ERR : Erase error.
  384. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Erase timeout.
  385. */
  386. esp_rom_spiflash_result_t esp_rom_spiflash_erase_area(uint32_t start_addr, uint32_t area_len);
  387. /**
  388. * @brief Write Data to Flash, you should Erase it yourself if need.
  389. * Please do not call this function in SDK.
  390. *
  391. * @param uint32_t dest_addr : Address to write, should be 4 bytes aligned.
  392. *
  393. * @param const uint32_t *src : The pointer to data which is to write.
  394. *
  395. * @param uint32_t len : Length to write, should be 4 bytes aligned.
  396. *
  397. * @return ESP_ROM_SPIFLASH_RESULT_OK : Write OK.
  398. * ESP_ROM_SPIFLASH_RESULT_ERR : Write error.
  399. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Write timeout.
  400. */
  401. esp_rom_spiflash_result_t esp_rom_spiflash_write(uint32_t dest_addr, const uint32_t *src, int32_t len);
  402. /**
  403. * @brief Read Data from Flash, you should Erase it yourself if need.
  404. * Please do not call this function in SDK.
  405. *
  406. * @param uint32_t src_addr : Address to read, should be 4 bytes aligned.
  407. *
  408. * @param uint32_t *dest : The buf to read the data.
  409. *
  410. * @param uint32_t len : Length to read, should be 4 bytes aligned.
  411. *
  412. * @return ESP_ROM_SPIFLASH_RESULT_OK : Read OK.
  413. * ESP_ROM_SPIFLASH_RESULT_ERR : Read error.
  414. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Read timeout.
  415. */
  416. esp_rom_spiflash_result_t esp_rom_spiflash_read(uint32_t src_addr, uint32_t *dest, int32_t len);
  417. /**
  418. * @brief SPI1 go into encrypto mode.
  419. * Please do not call this function in SDK.
  420. *
  421. * @param None
  422. *
  423. * @return None
  424. */
  425. void esp_rom_spiflash_write_encrypted_enable(void);
  426. /**
  427. * @brief Prepare 32 Bytes data to encrpto writing, you should Erase it yourself if need.
  428. * Please do not call this function in SDK.
  429. *
  430. * @param uint32_t flash_addr : Address to write, should be 32 bytes aligned.
  431. *
  432. * @param uint32_t *data : The pointer to data which is to write.
  433. *
  434. * @return ESP_ROM_SPIFLASH_RESULT_OK : Prepare OK.
  435. * ESP_ROM_SPIFLASH_RESULT_ERR : Prepare error.
  436. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Prepare timeout.
  437. */
  438. esp_rom_spiflash_result_t esp_rom_spiflash_prepare_encrypted_data(uint32_t flash_addr, uint32_t *data);
  439. /**
  440. * @brief SPI1 go out of encrypto mode.
  441. * Please do not call this function in SDK.
  442. *
  443. * @param None
  444. *
  445. * @return None
  446. */
  447. void esp_rom_spiflash_write_encrypted_disable(void);
  448. /**
  449. * @brief Write data to flash with transparent encryption.
  450. * @note Sectors to be written should already be erased.
  451. *
  452. * @note Please do not call this function in SDK.
  453. *
  454. * @param uint32_t flash_addr : Address to write, should be 32 byte aligned.
  455. *
  456. * @param uint32_t *data : The pointer to data to write. Note, this pointer must
  457. * be 32 bit aligned and the content of the data will be
  458. * modified by the encryption function.
  459. *
  460. * @param uint32_t len : Length to write, should be 32 bytes aligned.
  461. *
  462. * @return ESP_ROM_SPIFLASH_RESULT_OK : Data written successfully.
  463. * ESP_ROM_SPIFLASH_RESULT_ERR : Encryption write error.
  464. * ESP_ROM_SPIFLASH_RESULT_TIMEOUT : Encrypto write timeout.
  465. */
  466. esp_rom_spiflash_result_t esp_rom_spiflash_write_encrypted(uint32_t flash_addr, uint32_t *data, uint32_t len);
  467. /** @brief Wait until SPI flash write operation is complete
  468. *
  469. * @note Please do not call this function in SDK.
  470. *
  471. * Reads the Write In Progress bit of the SPI flash status register,
  472. * repeats until this bit is zero (indicating write complete).
  473. *
  474. * @return ESP_ROM_SPIFLASH_RESULT_OK : Write is complete
  475. * ESP_ROM_SPIFLASH_RESULT_ERR : Error while reading status.
  476. */
  477. esp_rom_spiflash_result_t esp_rom_spiflash_wait_idle(esp_rom_spiflash_chip_t *spi);
  478. /** @brief Enable Quad I/O pin functions
  479. *
  480. * @note Please do not call this function in SDK.
  481. *
  482. * Sets the HD & WP pin functions for Quad I/O modes, based on the
  483. * efuse SPI pin configuration.
  484. *
  485. * @param wp_gpio_num - Number of the WP pin to reconfigure for quad I/O.
  486. *
  487. * @param spiconfig - Pin configuration, as returned from ets_efuse_get_spiconfig().
  488. * - If this parameter is 0, default SPI pins are used and wp_gpio_num parameter is ignored.
  489. * - If this parameter is 1, default HSPI pins are used and wp_gpio_num parameter is ignored.
  490. * - For other values, this parameter encodes the HD pin number and also the CLK pin number. CLK pin selection is used
  491. * to determine if HSPI or SPI peripheral will be used (use HSPI if CLK pin is the HSPI clock pin, otherwise use SPI).
  492. * Both HD & WP pins are configured via GPIO matrix to map to the selected peripheral.
  493. */
  494. void esp_rom_spiflash_select_qio_pins(uint8_t wp_gpio_num, uint32_t spiconfig);
  495. /**
  496. * @brief Clear WEL bit unconditionally.
  497. *
  498. * @return always ESP_ROM_SPIFLASH_RESULT_OK
  499. */
  500. esp_rom_spiflash_result_t esp_rom_spiflash_write_disable(void);
  501. /** @brief Global esp_rom_spiflash_chip_t structure used by ROM functions
  502. *
  503. */
  504. extern esp_rom_spiflash_chip_t g_rom_flashchip;
  505. extern uint8_t g_rom_spiflash_dummy_len_plus[];
  506. /**
  507. * @}
  508. */
  509. #ifdef __cplusplus
  510. }
  511. #endif
  512. #endif /* _ROM_SPI_FLASH_H_ */