ql_api_spi_nand_flash.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /** @file
  2. ql_api_spi_nand_flash.h
  3. @brief
  4. This file is used to define bt api for different Quectel Project.
  5. */
  6. /*================================================================
  7. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  8. Quectel Wireless Solution Proprietary and Confidential.
  9. =================================================================*/
  10. /*=================================================================
  11. EDIT HISTORY FOR MODULE
  12. This section contains comments describing changes made to the module.
  13. Notice that changes are listed in reverse chronological order.
  14. WHEN WHO WHAT, WHERE, WHY
  15. ------------ ------- -------------------------------------------------------------------------------
  16. =================================================================*/
  17. #ifndef QL_API_SPI_NAND_FLASH_H
  18. #define QL_API_SPI_NAND_FLASH_H
  19. #include "ql_api_common.h"
  20. #include "ql_api_spi.h"
  21. #include "ql_api_spi_flash.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /*========================================================================
  26. * Variable Definition
  27. *========================================================================*/
  28. #define QL_SPI_NAND_PAGE_SIZE 2048
  29. #define QL_SPI_NAND_SPARE_SIZE 64
  30. #define QL_SPI_NAND_PAGE_SPARE_SIZE (QL_SPI_NAND_PAGE_SIZE+QL_SPI_NAND_SPARE_SIZE)
  31. /**************************** error code about ql spi flash ***************************/
  32. typedef ql_errcode_spi_flash_e ql_errcode_spi_nand_e ;
  33. typedef ql_spi_flash_config_s ql_spi_nand_config_s ;
  34. typedef enum
  35. {
  36. QL_NAND_FLASH_STATUS_1 = 0, //Status Register-1
  37. QL_NAND_FLASH_STATUS_2, //Status Register-2
  38. QL_NAND_FLASH_STATUS_3, //Status Register-3
  39. QL_NAND_FLASH_STATUS_4, //Status Register-4
  40. }ql_spi_nand_status_reg_e;
  41. typedef enum
  42. {
  43. QL_NAND_FLASH_ID_16BIT = 0, //Manufacturer ID(8bit) + device ID(8bit)
  44. QL_NAND_FLASH_ID_24BIT, //Manufacturer ID(8bit) + device ID(16bit)
  45. }ql_spi_nand_id_type_e;
  46. typedef enum
  47. {
  48. QL_NAND_TYPE_STANDARD_SPI = 0, //Standard SPI: SCLK, CS#, SI, SO
  49. QL_NAND_TYPE_QUAD_SPI, //Quad SPI: SCLK, CS#, SIO0, SIO1, SIO2, SIO3
  50. QL_NAND_TYPE_DUAL_SPI, //Dual SPI: SCLK, CS#, SIO0, SIO1
  51. }ql_nand_spi_type_e;
  52. typedef struct
  53. {
  54. ql_nand_spi_type_e (*nand_type)(void);
  55. ql_errcode_spi_nand_e (*nand_init)(void* nand_config);
  56. ql_errcode_spi_nand_e (*read_devid)(ql_spi_port_e port, unsigned char *mid,ql_spi_nand_id_type_e mid_type);
  57. ql_errcode_spi_nand_e (*read_status)(ql_spi_port_e port, ql_spi_nand_status_reg_e reg, unsigned char *status);
  58. ql_errcode_spi_nand_e (*write_page_spare)(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  59. ql_errcode_spi_nand_e (*read_page_spare)(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  60. ql_errcode_spi_nand_e (*erase_block)(ql_spi_port_e port, unsigned int page_addr);
  61. ql_errcode_spi_nand_e (*reset)(ql_spi_port_e port);
  62. } ql_nand_ops_t;
  63. /*========================================================================
  64. * function Definition
  65. *========================================================================*/
  66. /*****************************************************************
  67. * Function: ql_spi_nand_init
  68. *
  69. * Description:
  70. * 初始化NAND FLASH
  71. *
  72. * Parameters:
  73. * port [in] SPI总线选择
  74. * spiclk [in] SPI时钟选择
  75. *
  76. * Return:ql_errcode_spi_nand_e
  77. *
  78. *****************************************************************/
  79. ql_errcode_spi_nand_e ql_spi_nand_init(ql_spi_port_e port, ql_spi_clk_e spiclk);
  80. /*****************************************************************
  81. * Function: ql_spi_nand_init_ext
  82. *
  83. * Description:
  84. * 扩展初始化NAND FLASH,与ql_spi_nand_init有更多的设置选项
  85. *
  86. * Parameters:
  87. * nand_config [in] SPI配置参数
  88. *
  89. * Return:ql_errcode_spi_nand_e
  90. *
  91. *****************************************************************/
  92. ql_errcode_spi_nand_e ql_spi_nand_init_ext(ql_spi_nand_config_s nand_config);
  93. /*****************************************************************
  94. * Function: ql_spi_nand_read_devid_ex
  95. *
  96. * Description:
  97. * read flash devie id
  98. *
  99. * Parameters:
  100. * port [in] SPI bus select
  101. * mid [out] manufacturer id
  102. * mid_type [in] manufacturer id type
  103. *
  104. * Return:ql_errcode_spi_nand_e
  105. *
  106. *****************************************************************/
  107. ql_errcode_spi_nand_e ql_spi_nand_read_devid_ex(ql_spi_port_e port, unsigned char *mid,ql_spi_nand_id_type_e mid_type);
  108. /*****************************************************************
  109. * Function: ql_spi_nand_read_devid
  110. *
  111. * Description:
  112. * read flash devie id
  113. *
  114. * Parameters:
  115. * port [in] SPI bus select
  116. * mid [out] manufacturer id
  117. *
  118. * Return:ql_errcode_spi_nand_e
  119. *
  120. *****************************************************************/
  121. ql_errcode_spi_nand_e ql_spi_nand_read_devid(ql_spi_port_e port, unsigned char *mid);
  122. /*****************************************************************
  123. * Function: ql_spi_nand_read_page_spare
  124. *
  125. * Description:
  126. * read page(2048 byte)+spare area(64 byte)
  127. *
  128. * Parameters:
  129. * port [in] SPI bus select
  130. * page_addr [in] page address
  131. * column_addr [in] column address
  132. * data [out] data read buffer
  133. * len [in] data read length
  134. *
  135. * Return:ql_errcode_spi_nand_e
  136. *
  137. *****************************************************************/
  138. ql_errcode_spi_nand_e ql_spi_nand_read_page_spare(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  139. /*****************************************************************
  140. * Function: ql_spi_nand_write_page_spare
  141. *
  142. * Description:
  143. * write page(2048 byte)+spare area(64 byte)
  144. *
  145. * Parameters:
  146. * port [in] SPI bus select
  147. * page_addr [in] page address
  148. * column_addr [in] column address
  149. * data [in] data read buffer
  150. * len [in] data read length
  151. *
  152. * Return:ql_errcode_spi_nand_e
  153. *
  154. *****************************************************************/
  155. ql_errcode_spi_nand_e ql_spi_nand_write_page_spare(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  156. /*****************************************************************
  157. * Function: ql_spi_nand_write_spare
  158. *
  159. * Description:
  160. * write spare area(64 byte)
  161. *
  162. * Parameters:
  163. * port [in] SPI bus select
  164. * page_addr [in] page address
  165. * data [out] data read buffer
  166. * len [in] data read length
  167. *
  168. * Return:ql_errcode_spi_nand_e
  169. *
  170. *****************************************************************/
  171. ql_errcode_spi_nand_e ql_spi_nand_write_spare(ql_spi_port_e port, unsigned int page_addr, unsigned char *data, int len);
  172. /*****************************************************************
  173. * Function: ql_spi_nand_read_status
  174. *
  175. * Description:
  176. * read status register value
  177. *
  178. * Parameters:
  179. * port [in] SPI bus select
  180. * reg [in] FLASH status register
  181. * status [out] status register value
  182. *
  183. * Return:ql_errcode_spi_nand_e
  184. *
  185. *****************************************************************/
  186. ql_errcode_spi_nand_e ql_spi_nand_read_status(ql_spi_port_e port, ql_spi_nand_status_reg_e reg, unsigned char *status);
  187. /*****************************************************************
  188. * Function: ql_spi_nand_write_status
  189. *
  190. * Description:
  191. * read status register value
  192. *
  193. * Parameters:
  194. * port [in] SPI bus select
  195. * reg [in] FLASH status register
  196. * status [in] status register value
  197. *
  198. * Return:ql_errcode_spi_nand_e
  199. *
  200. *****************************************************************/
  201. ql_errcode_spi_nand_e ql_spi_nand_write_status(ql_spi_port_e port, ql_spi_nand_status_reg_e reg, unsigned char status);
  202. /*****************************************************************
  203. * Function: ql_spi_nand_erase_block
  204. *
  205. * Description:
  206. * erase block(128k):D8H
  207. *
  208. * Parameters:
  209. * port [in] SPI bus selelct
  210. * page_addr [in] page address
  211. *
  212. * Return:ql_errcode_spi_nand_e
  213. *
  214. *****************************************************************/
  215. ql_errcode_spi_nand_e ql_spi_nand_erase_block(ql_spi_port_e port, unsigned int page_addr);
  216. /*****************************************************************
  217. * Function: ql_spi_nand_reset
  218. *
  219. * Description:
  220. * reset flash device:FFH
  221. *
  222. * Parameters:
  223. * port [in] SPI bus selelct
  224. *
  225. * Return:ql_errcode_spi_nand_e
  226. *
  227. *****************************************************************/
  228. ql_errcode_spi_nand_e ql_spi_nand_reset(ql_spi_port_e port);
  229. typedef enum
  230. {
  231. //SPI6_NAND_FLASH_CLK_31MHZ = 0x0, //8850上不支持该频率,与8910有差异
  232. //SPI6_NAND_FLASH_CLK_41MHZ = 0x0, //8850上不支持该频率,与8910有差异
  233. SPI6_NAND_FLASH_CLK_62MHZ = 0x1,
  234. SPI6_NAND_FLASH_CLK_71MHZ = 0x3,
  235. SPI6_NAND_FLASH_CLK_83MHZ = 0x5,
  236. SPI6_NAND_FLASH_CLK_91MHZ = 0x6,
  237. SPI6_NAND_FLASH_CLK_100MHZ = 0x7,
  238. SPI6_NAND_FLASH_CLK_111MHZ = 0x8,
  239. SPI6_NAND_FLASH_CLK_125MHZ = 0x9,
  240. //以下为8850支持,但8910不支持的
  241. SPI6_NAND_FLASH_CLK_142MHZ = 0xa,
  242. SPI6_NAND_FLASH_CLK_166MHZ = 0xb,
  243. SPI6_NAND_FLASH_CLK_200MHZ = 0xc, //8850默认为该频率
  244. //8850内置flash不支持以下时钟频率
  245. //SPI6_NAND_FLASH_CLK_250MHZ = 0xd,
  246. //SPI6_NAND_FLASH_CLK_333MHZ = 0xe,
  247. SPI6_NAND_FLASH_CLK_500MHZ = 0xf,
  248. SPI6_NAND_FLASH_CLK_INVALID = 0x10,
  249. }ql_spi6_nand_flash_clk_e;
  250. /*
  251. 目前建议使用的值:如果需要使用其他的freq需要抓波形调整参数,尤其是sample_delay参数,
  252. 如果设置不对会导致读/写数据不正确。
  253. ----------------------------------------------------------------------------
  254. | 复用的pin脚--GPIO number:GPIO18-23 |
  255. ----------------------------------------------------------------------------
  256. | freq | clk | clk_div | drv | sample_delay |
  257. | 40M | SPI6_NAND_FLASH_CLK_200MHZ | 5 | 0x2 | 2/3 |
  258. | 50M | SPI6_NAND_FLASH_CLK_200MHZ | 4 | 0x2 | 2/3 |
  259. | 83.3M | SPI6_NAND_FLASH_CLK_500MHZ | 6 | 0x2 | 4/6 |
  260. ----------------------------------------------------------------------------
  261. ----------------------------------------------------------------------------
  262. | 复用的pin脚--SPI_LCD |
  263. ----------------------------------------------------------------------------
  264. | freq | clk | clk_div | drv | sample_delay |
  265. | 40M | SPI6_NAND_FLASH_CLK_200MHZ | 5 | 0x7 | 2/3 |
  266. | 50M | SPI6_NAND_FLASH_CLK_200MHZ | 4 | 0x7 | 2/3 |
  267. | 83.3M | SPI6_NAND_FLASH_CLK_500MHZ | 6 | 0x7 | 4/5 |
  268. ----------------------------------------------------------------------------
  269. ----------------------------------------------------------------------------
  270. | 复用的pin脚--SDMMC |
  271. ----------------------------------------------------------------------------
  272. | freq | clk | clk_div | drv | sample_delay |
  273. | 40M | SPI6_NAND_FLASH_CLK_200MHZ | 5 | 0x7 | 2/3 |
  274. | 50M | SPI6_NAND_FLASH_CLK_200MHZ | 4 | 0x7 | 2/3 |
  275. | 83.3M | SPI6_NAND_FLASH_CLK_500MHZ | 6 | 0x7 | 4/6 |
  276. ----------------------------------------------------------------------------
  277. */
  278. typedef struct
  279. {
  280. ql_spi_port_e port; //SPI6总线选择,此参数无意义
  281. ql_spi6_nand_flash_clk_e clk; //SPI6时钟源配置,默认SPI6_NAND_FLASH_CLK_200MHZ
  282. uint8_t clk_div; //时钟分频,默认5,freq =200M/5=40M
  283. uint8_t quad_mode; //1--Quad SPII: SCLK, CS#, SIO0, SIO1, SIO2, SIO3 0--Dual SPI: SCLK, CS#, SIO0, SIO1
  284. uint8_t sample_delay; //延时采样,此值与clk和驱动能力相关,需要配置波形设置(主要用于调节数据的采样点在时钟的有效位置,尽可能的在中间),一般频率越高此值越大
  285. uint8_t isslow; //是否使用低速率时钟,1--low 0--fast;仅8910有效
  286. } ql_spi6_nand_config_s;
  287. /*========================================================================
  288. * function Definition
  289. *========================================================================*/
  290. /*****************************************************************
  291. * Function: ql_spi6_nand_init
  292. *
  293. * Description:
  294. * 初始化NAND FLASH
  295. *
  296. * Parameters:
  297. * port [in] SPI6总线选择,此参数预留,目前没有实际意义
  298. * clk [in] SPI6时钟源选择
  299. * clk_div [in] SPI6时钟分频
  300. *
  301. * Return:ql_errcode_spi_nand_e
  302. *
  303. *****************************************************************/
  304. ql_errcode_spi_nand_e ql_spi6_nand_init(ql_spi_port_e port, ql_spi6_nand_flash_clk_e clk, uint8_t clk_div);
  305. /*****************************************************************
  306. * Function: ql_spi6_nand_init_ext
  307. *
  308. * Description:
  309. * 扩展初始化NAND FLASH,与ql_spi_nand_init有更多的设置选项
  310. *
  311. * Parameters:
  312. * config [in] SPI6配置参数
  313. *
  314. * Return:ql_errcode_spi_nand_e
  315. *
  316. *****************************************************************/
  317. ql_errcode_spi_nand_e ql_spi6_nand_init_ext(ql_spi6_nand_config_s config);
  318. /*****************************************************************
  319. * Function: ql_spi6_nand_read_devid_ex
  320. *
  321. * Description:
  322. * read flash devie id
  323. *
  324. * Parameters:
  325. * port [in] SPI6 bus select,this parameter is reserved
  326. * mid [out] manufacturer id
  327. * mid_type [in] manufacturer id type
  328. *
  329. * Return:ql_errcode_spi_nand_e
  330. *
  331. *****************************************************************/
  332. ql_errcode_spi_nand_e ql_spi6_nand_read_devid_ex(ql_spi_port_e port, unsigned char *mid,ql_spi_nand_id_type_e mid_type);
  333. /*****************************************************************
  334. * Function: ql_spi6_nand_read_devid
  335. *
  336. * Description:
  337. * read flash devie id
  338. *
  339. * Parameters:
  340. * port [in] SPI6 bus select,this parameter is reserved
  341. * mid [out] manufacturer id
  342. *
  343. * Return:ql_errcode_spi_nand_e
  344. *
  345. *****************************************************************/
  346. ql_errcode_spi_nand_e ql_spi6_nand_read_devid(ql_spi_port_e port, unsigned char *mid);
  347. /*****************************************************************
  348. * Function: ql_spi6_nand_read_page_spare
  349. *
  350. * Description:
  351. * read page(2048 byte)+spare area(64 byte)
  352. *
  353. * Parameters:
  354. * port [in] SPI6 bus select,this parameter is reserved
  355. * page_addr [in] page address
  356. * column_addr [in] column address
  357. * data [out] data read buffer
  358. * len [in] data read length
  359. *
  360. * Return:ql_errcode_spi_nand_e
  361. *
  362. *****************************************************************/
  363. ql_errcode_spi_nand_e ql_spi6_nand_read_page_spare(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  364. /*****************************************************************
  365. * Function: ql_spi6_nand_write_page_spare
  366. *
  367. * Description:
  368. * write page(2048 byte)+spare area(64 byte)
  369. *
  370. * Parameters:
  371. * port [in] SPI6 bus select,this parameter is reserved
  372. * page_addr [in] page address
  373. * column_addr [in] column address
  374. * data [in] data read buffer
  375. * len [in] data read length
  376. *
  377. * Return:ql_errcode_spi_nand_e
  378. *
  379. *****************************************************************/
  380. ql_errcode_spi_nand_e ql_spi6_nand_write_page_spare(ql_spi_port_e port, unsigned int page_addr, unsigned short column_addr, unsigned char *data, int len);
  381. /*****************************************************************
  382. * Function: ql_spi6_nand_write_spare
  383. *
  384. * Description:
  385. * write spare area(64 byte)
  386. *
  387. * Parameters:
  388. * port [in] SPI6 bus select,this parameter is reserved
  389. * page_addr [in] page address
  390. * data [out] data read buffer
  391. * len [in] data read length
  392. *
  393. * Return:ql_errcode_spi_nand_e
  394. *
  395. *****************************************************************/
  396. ql_errcode_spi_nand_e ql_spi6_nand_write_spare(ql_spi_port_e port, unsigned int page_addr, unsigned char *data, int len);
  397. /*****************************************************************
  398. * Function: ql_spi6_nand_read_status
  399. *
  400. * Description:
  401. * read status register value
  402. *
  403. * Parameters:
  404. * port [in] SPI6 bus select,this parameter is reserved
  405. * reg [in] FLASH status register
  406. * status [out] status register value
  407. *
  408. * Return:ql_errcode_spi_nand_e
  409. *
  410. *****************************************************************/
  411. ql_errcode_spi_nand_e ql_spi6_nand_read_status(ql_spi_port_e port, ql_spi_nand_status_reg_e reg, unsigned char *status);
  412. /*****************************************************************
  413. * Function: ql_spi6_nand_write_status
  414. *
  415. * Description:
  416. * read status register value
  417. *
  418. * Parameters:
  419. * port [in] SPI6 bus select,this parameter is reserved
  420. * reg [in] FLASH status register
  421. * status [in] status register value
  422. *
  423. * Return:ql_errcode_spi_nand_e
  424. *
  425. *****************************************************************/
  426. ql_errcode_spi_nand_e ql_spi6_nand_write_status(ql_spi_port_e port, ql_spi_nand_status_reg_e reg, unsigned char status);
  427. /*****************************************************************
  428. * Function: ql_spi6_nand_erase_block
  429. *
  430. * Description:
  431. * erase block(128k):D8H
  432. *
  433. * Parameters:
  434. * port [in] SPI6 bus select,this parameter is reserved
  435. * page_addr [in] page address
  436. *
  437. * Return:ql_errcode_spi_nand_e
  438. *
  439. *****************************************************************/
  440. ql_errcode_spi_nand_e ql_spi6_nand_erase_block(ql_spi_port_e port, unsigned int page_addr);
  441. /*****************************************************************
  442. * Function: ql_spi6_nand_reset
  443. *
  444. * Description:
  445. * reset flash device:FFH
  446. *
  447. * Parameters:
  448. * port [in] SPI6 bus select,this parameter is reserved
  449. *
  450. * Return:ql_errcode_spi_nand_e
  451. *
  452. *****************************************************************/
  453. ql_errcode_spi_nand_e ql_spi6_nand_reset(ql_spi_port_e port);
  454. #ifdef __cplusplus
  455. } /*"C" */
  456. #endif
  457. #endif /* QL_API_SPI_NAND_FLASH_H */