spi_flash.h 19 KB

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