at32f403a_407_flash.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_flash.h
  4. * @brief at32f403a_407 flash header file
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. /* Define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F403A_407_FLASH_H
  26. #define __AT32F403A_407_FLASH_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "at32f403a_407.h"
  32. /** @addtogroup AT32F403A_407_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup FLASH
  36. * @{
  37. */
  38. /** @defgroup FLASH_unlock_keys
  39. * @brief flash unlock keys
  40. * @{
  41. */
  42. #define FLASH_UNLOCK_KEY1 ((uint32_t)0x45670123) /*!< flash operation unlock order key1 */
  43. #define FLASH_UNLOCK_KEY2 ((uint32_t)0xCDEF89AB) /*!< flash operation unlock order key2 */
  44. #define FAP_RELIEVE_KEY ((uint16_t)0x00A5) /*!< flash fap relieve key val */
  45. #define SLIB_UNLOCK_KEY ((uint32_t)0xA35F6D24) /*!< flash slib operation unlock order key */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup FLASH_bank_address
  50. * @brief flash bank address
  51. * @{
  52. */
  53. #define FLASH_BANK1_START_ADDR ((uint32_t)0x08000000) /*!< flash start address of bank1 */
  54. #define FLASH_BANK1_END_ADDR ((uint32_t)0x0807FFFF) /*!< flash end address of bank1 */
  55. #define FLASH_BANK2_START_ADDR ((uint32_t)0x08080000) /*!< flash start address of bank2 */
  56. #define FLASH_BANK2_END_ADDR ((uint32_t)0x080FFFFF) /*!< flash end address of bank2 */
  57. #define FLASH_SPIM_START_ADDR ((uint32_t)0x08400000) /*!< flash start address of spim */
  58. /**
  59. * @}
  60. */
  61. /** @defgroup FLASH_flags
  62. * @brief flash flag
  63. * @{
  64. */
  65. #define FLASH_OBF_FLAG FLASH_BANK1_OBF_FLAG /*!< flash operate busy flag */
  66. #define FLASH_ODF_FLAG FLASH_BANK1_ODF_FLAG /*!< flash operate done flag */
  67. #define FLASH_PRGMERR_FLAG FLASH_BANK1_PRGMERR_FLAG /*!< flash program error flag */
  68. #define FLASH_EPPERR_FLAG FLASH_BANK1_EPPERR_FLAG /*!< flash erase/program protection error flag */
  69. #define FLASH_BANK1_OBF_FLAG ((uint32_t)0x00000001) /*!< flash bank1 operate busy flag */
  70. #define FLASH_BANK1_ODF_FLAG ((uint32_t)0x00000020) /*!< flash bank1 operate done flag */
  71. #define FLASH_BANK1_PRGMERR_FLAG ((uint32_t)0x00000004) /*!< flash bank1 program error flag */
  72. #define FLASH_BANK1_EPPERR_FLAG ((uint32_t)0x00000010) /*!< flash bank1 erase/program protection error flag */
  73. #define FLASH_BANK2_OBF_FLAG ((uint32_t)0x10000001) /*!< flash bank2 operate busy flag */
  74. #define FLASH_BANK2_ODF_FLAG ((uint32_t)0x10000020) /*!< flash bank2 operate done flag */
  75. #define FLASH_BANK2_PRGMERR_FLAG ((uint32_t)0x10000004) /*!< flash bank2 program error flag */
  76. #define FLASH_BANK2_EPPERR_FLAG ((uint32_t)0x10000010) /*!< flash bank2 erase/program protection error flag */
  77. #define FLASH_SPIM_OBF_FLAG ((uint32_t)0x20000001) /*!< flash spim operate busy flag */
  78. #define FLASH_SPIM_ODF_FLAG ((uint32_t)0x20000020) /*!< flash spim operate done flag */
  79. #define FLASH_SPIM_PRGMERR_FLAG ((uint32_t)0x20000004) /*!< flash spim program error flag */
  80. #define FLASH_SPIM_EPPERR_FLAG ((uint32_t)0x20000010) /*!< flash spim erase/program protection error flag */
  81. #define FLASH_USDERR_FLAG ((uint32_t)0x40000001) /*!< flash user system data error flag */
  82. /**
  83. * @}
  84. */
  85. /** @defgroup FLASH_interrupts
  86. * @brief flash interrupts
  87. * @{
  88. */
  89. #define FLASH_ERR_INT FLASH_BANK1_ERR_INT /*!< flash error interrupt */
  90. #define FLASH_ODF_INT FLASH_BANK1_ODF_INT /*!< flash operate done interrupt */
  91. #define FLASH_BANK1_ERR_INT ((uint32_t)0x00000001) /*!< flash bank1 error interrupt */
  92. #define FLASH_BANK1_ODF_INT ((uint32_t)0x00000002) /*!< flash bank1 operate done interrupt */
  93. #define FLASH_BANK2_ERR_INT ((uint32_t)0x00000004) /*!< flash bank2 error interrupt */
  94. #define FLASH_BANK2_ODF_INT ((uint32_t)0x00000008) /*!< flash bank2 operate done interrupt */
  95. #define FLASH_SPIM_ERR_INT ((uint32_t)0x00000010) /*!< flash spim error interrupt */
  96. #define FLASH_SPIM_ODF_INT ((uint32_t)0x00000020) /*!< flash spim operate done interrupt */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup FLASH_slib_mask
  101. * @brief flash slib mask
  102. * @{
  103. */
  104. #define FLASH_SLIB_START_SECTOR ((uint32_t)0x000007FF) /*!< flash slib start sector */
  105. #define FLASH_SLIB_DATA_START_SECTOR ((uint32_t)0x003FF800) /*!< flash slib d-bus area start sector */
  106. #define FLASH_SLIB_END_SECTOR ((uint32_t)0xFFC00000) /*!< flash slib end sector */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup FLASH_user_system_data
  111. * @brief flash user system data
  112. * @{
  113. */
  114. #define USD_WDT_ATO_DISABLE ((uint16_t)0x0001) /*!< wdt auto start disabled */
  115. #define USD_WDT_ATO_ENABLE ((uint16_t)0x0000) /*!< wdt auto start enabled */
  116. #define USD_DEPSLP_NO_RST ((uint16_t)0x0002) /*!< no reset generated when entering in deepsleep */
  117. #define USD_DEPSLP_RST ((uint16_t)0x0000) /*!< reset generated when entering in deepsleep */
  118. #define USD_STDBY_NO_RST ((uint16_t)0x0004) /*!< no reset generated when entering in standby */
  119. #define USD_STDBY_RST ((uint16_t)0x0000) /*!< reset generated when entering in standby */
  120. #define FLASH_BOOT_FROM_BANK1 ((uint16_t)0x0008) /*!< boot from bank1 */
  121. #define FLASH_BOOT_FROM_BANK2 ((uint16_t)0x0000) /*!< boot from bank 2 or bank 1,depending on the activation of the bank */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup FLASH_timeout_definition
  126. * @brief flash timeout definition
  127. * @{
  128. */
  129. #define ERASE_TIMEOUT ((uint32_t)0x40000000) /*!< internal flash erase operation timeout */
  130. #define PROGRAMMING_TIMEOUT ((uint32_t)0x00100000) /*!< internal flash program operation timeout */
  131. #define SPIM_ERASE_TIMEOUT ((uint32_t)0xFFFFFFFF) /*!< spim erase operation timeout */
  132. #define SPIM_PROGRAMMING_TIMEOUT ((uint32_t)0x00100000) /*!< spim program operation timeout */
  133. #define OPERATION_TIMEOUT ((uint32_t)0x10000000) /*!< flash common operation timeout */
  134. /**
  135. * @}
  136. */
  137. /** @defgroup FLASH_exported_types
  138. * @{
  139. */
  140. /**
  141. * @brief flash status type
  142. */
  143. typedef enum
  144. {
  145. FLASH_OPERATE_BUSY = 0x00, /*!< flash status is operate busy */
  146. FLASH_PROGRAM_ERROR = 0x01, /*!< flash status is program error */
  147. FLASH_EPP_ERROR = 0x02, /*!< flash status is epp error */
  148. FLASH_OPERATE_DONE = 0x03, /*!< flash status is operate done */
  149. FLASH_OPERATE_TIMEOUT = 0x04 /*!< flash status is operate timeout */
  150. } flash_status_type;
  151. /**
  152. * @brief flash spim model type
  153. */
  154. typedef enum
  155. {
  156. FLASH_SPIM_MODEL1 = 0x01, /*!< spim model 1 */
  157. FLASH_SPIM_MODEL2 = 0x02, /*!< spim model 2 */
  158. } flash_spim_model_type;
  159. /**
  160. * @brief type define flash register all
  161. */
  162. typedef struct
  163. {
  164. /**
  165. * @brief flash psr register, offset:0x00
  166. */
  167. union
  168. {
  169. __IO uint32_t psr;
  170. struct
  171. {
  172. __IO uint32_t reserved1 : 32; /* [31:0] */
  173. } psr_bit;
  174. };
  175. /**
  176. * @brief flash unlock register, offset:0x04
  177. */
  178. union
  179. {
  180. __IO uint32_t unlock;
  181. struct
  182. {
  183. __IO uint32_t ukval : 32;/* [31:0] */
  184. } unlock_bit;
  185. };
  186. /**
  187. * @brief flash usd unlock register, offset:0x08
  188. */
  189. union
  190. {
  191. __IO uint32_t usd_unlock;
  192. struct
  193. {
  194. __IO uint32_t usd_ukval : 32;/* [31:0] */
  195. } usd_unlock_bit;
  196. };
  197. /**
  198. * @brief flash sts register, offset:0x0C
  199. */
  200. union
  201. {
  202. __IO uint32_t sts;
  203. struct
  204. {
  205. __IO uint32_t obf : 1; /* [0] */
  206. __IO uint32_t reserved1 : 1; /* [1] */
  207. __IO uint32_t prgmerr : 1; /* [2] */
  208. __IO uint32_t reserved2 : 1; /* [3] */
  209. __IO uint32_t epperr : 1; /* [4] */
  210. __IO uint32_t odf : 1; /* [5] */
  211. __IO uint32_t reserved3 : 26;/* [31:6] */
  212. } sts_bit;
  213. };
  214. /**
  215. * @brief flash ctrl register, offset:0x10
  216. */
  217. union
  218. {
  219. __IO uint32_t ctrl;
  220. struct
  221. {
  222. __IO uint32_t fprgm : 1; /* [0] */
  223. __IO uint32_t secers : 1; /* [1] */
  224. __IO uint32_t bankers : 1; /* [2] */
  225. __IO uint32_t reserved1 : 1; /* [3] */
  226. __IO uint32_t usdprgm : 1; /* [4] */
  227. __IO uint32_t usders : 1; /* [5] */
  228. __IO uint32_t erstr : 1; /* [6] */
  229. __IO uint32_t oplk : 1; /* [7] */
  230. __IO uint32_t reserved2 : 1; /* [8] */
  231. __IO uint32_t usdulks : 1; /* [9] */
  232. __IO uint32_t errie : 1; /* [10] */
  233. __IO uint32_t reserved3 : 1; /* [11] */
  234. __IO uint32_t odfie : 1; /* [12] */
  235. __IO uint32_t reserved4 : 19;/* [31:13] */
  236. } ctrl_bit;
  237. };
  238. /**
  239. * @brief flash addr register, offset:0x14
  240. */
  241. union
  242. {
  243. __IO uint32_t addr;
  244. struct
  245. {
  246. __IO uint32_t fa : 32;/* [31:0] */
  247. } addr_bit;
  248. };
  249. /**
  250. * @brief flash reserved1 register, offset:0x18
  251. */
  252. __IO uint32_t reserved1;
  253. /**
  254. * @brief flash usd register, offset:0x1C
  255. */
  256. union
  257. {
  258. __IO uint32_t usd;
  259. struct
  260. {
  261. __IO uint32_t usderr : 1; /* [0] */
  262. __IO uint32_t fap : 1; /* [1] */
  263. __IO uint32_t wdt_ato_en : 1; /* [2] */
  264. __IO uint32_t depslp_rst : 1; /* [3] */
  265. __IO uint32_t stdby_rst : 1; /* [4] */
  266. __IO uint32_t btopt : 1; /* [5] */
  267. __IO uint32_t reserved1 : 4; /* [9:6] */
  268. __IO uint32_t user_d0 : 8; /* [17:10] */
  269. __IO uint32_t user_d1 : 8; /* [25:18] */
  270. __IO uint32_t reserved2 : 6; /* [31:26] */
  271. } usd_bit;
  272. };
  273. /**
  274. * @brief flash epps register, offset:0x20
  275. */
  276. union
  277. {
  278. __IO uint32_t epps;
  279. struct
  280. {
  281. __IO uint32_t epps : 32;/* [31:0] */
  282. } epps_bit;
  283. };
  284. /**
  285. * @brief flash reserved2 register, offset:0x40~0x24
  286. */
  287. __IO uint32_t reserved2[8];
  288. /**
  289. * @brief flash unlock2 register, offset:0x44
  290. */
  291. union
  292. {
  293. __IO uint32_t unlock2;
  294. struct
  295. {
  296. __IO uint32_t ukval : 32;/* [31:0] */
  297. } unlock2_bit;
  298. };
  299. /**
  300. * @brief flash reserved3 register, offset:0x48
  301. */
  302. __IO uint32_t reserved3;
  303. /**
  304. * @brief flash sts2 register, offset:0x4C
  305. */
  306. union
  307. {
  308. __IO uint32_t sts2;
  309. struct
  310. {
  311. __IO uint32_t obf : 1; /* [0] */
  312. __IO uint32_t reserved1 : 1; /* [1] */
  313. __IO uint32_t prgmerr : 1; /* [2] */
  314. __IO uint32_t reserved2 : 1; /* [3] */
  315. __IO uint32_t epperr : 1; /* [4] */
  316. __IO uint32_t odf : 1; /* [5] */
  317. __IO uint32_t reserved3 : 26;/* [31:6] */
  318. } sts2_bit;
  319. };
  320. /**
  321. * @brief flash ctrl2 register, offset:0x50
  322. */
  323. union
  324. {
  325. __IO uint32_t ctrl2;
  326. struct
  327. {
  328. __IO uint32_t fprgm : 1; /* [0] */
  329. __IO uint32_t secers : 1; /* [1] */
  330. __IO uint32_t bankers : 1; /* [2] */
  331. __IO uint32_t reserved1 : 3; /* [5:3] */
  332. __IO uint32_t erstr : 1; /* [6] */
  333. __IO uint32_t oplk : 1; /* [7] */
  334. __IO uint32_t reserved2 : 2; /* [9:8] */
  335. __IO uint32_t errie : 1; /* [10] */
  336. __IO uint32_t reserved3 : 1; /* [11] */
  337. __IO uint32_t odfie : 1; /* [12] */
  338. __IO uint32_t reserved4 : 19;/* [31:13] */
  339. } ctrl2_bit;
  340. };
  341. /**
  342. * @brief flash addr2 register, offset:0x54
  343. */
  344. union
  345. {
  346. __IO uint32_t addr2;
  347. struct
  348. {
  349. __IO uint32_t fa : 32;/* [31:0] */
  350. } addr2_bit;
  351. };
  352. /**
  353. * @brief flash reserved4 register, offset:0x80~0x58
  354. */
  355. __IO uint32_t reserved4[11];
  356. /**
  357. * @brief flash unlock3 register, offset:0x84
  358. */
  359. union
  360. {
  361. __IO uint32_t unlock3;
  362. struct
  363. {
  364. __IO uint32_t ukval : 32;/* [31:0] */
  365. } unlock3_bit;
  366. };
  367. /**
  368. * @brief flash select register, offset:0x88
  369. */
  370. union
  371. {
  372. __IO uint32_t select;
  373. struct
  374. {
  375. __IO uint32_t select : 32;/* [31:0] */
  376. } select_bit;
  377. };
  378. /**
  379. * @brief flash sts3 register, offset:0x8C
  380. */
  381. union
  382. {
  383. __IO uint32_t sts3;
  384. struct
  385. {
  386. __IO uint32_t obf : 1; /* [0] */
  387. __IO uint32_t reserved1 : 1; /* [1] */
  388. __IO uint32_t prgmerr : 1; /* [2] */
  389. __IO uint32_t reserved2 : 1; /* [3] */
  390. __IO uint32_t epperr : 1; /* [4] */
  391. __IO uint32_t odf : 1; /* [5] */
  392. __IO uint32_t reserved3 : 26;/* [31:6] */
  393. } sts3_bit;
  394. };
  395. /**
  396. * @brief flash ctrl3 register, offset:0x90
  397. */
  398. union
  399. {
  400. __IO uint32_t ctrl3;
  401. struct
  402. {
  403. __IO uint32_t fprgm : 1; /* [0] */
  404. __IO uint32_t secers : 1; /* [1] */
  405. __IO uint32_t chpers : 1; /* [2] */
  406. __IO uint32_t reserved1 : 3; /* [5:3] */
  407. __IO uint32_t erstr : 1; /* [6] */
  408. __IO uint32_t oplk : 1; /* [7] */
  409. __IO uint32_t reserved2 : 2; /* [9:8] */
  410. __IO uint32_t errie : 1; /* [10] */
  411. __IO uint32_t reserved3 : 1; /* [11] */
  412. __IO uint32_t odfie : 1; /* [12] */
  413. __IO uint32_t reserved4 : 19;/* [31:13] */
  414. } ctrl3_bit;
  415. };
  416. /**
  417. * @brief flash addr3 register, offset:0x94
  418. */
  419. union
  420. {
  421. __IO uint32_t addr3;
  422. struct
  423. {
  424. __IO uint32_t fa : 32;/* [31:0] */
  425. } addr3_bit;
  426. };
  427. /**
  428. * @brief flash da register, offset:0x98
  429. */
  430. union
  431. {
  432. __IO uint32_t da;
  433. struct
  434. {
  435. __IO uint32_t fda : 32;/* [31:0] */
  436. } da_bit;
  437. };
  438. /**
  439. * @brief flash reserved5 register, offset:0xC8~0x9C
  440. */
  441. __IO uint32_t reserved5[12];
  442. /**
  443. * @brief flash slib_sts0 register, offset:0xCC
  444. */
  445. union
  446. {
  447. __IO uint32_t slib_sts0;
  448. struct
  449. {
  450. __IO uint32_t reserved1 : 3; /* [2:0] */
  451. __IO uint32_t slib_enf : 1; /* [3] */
  452. __IO uint32_t reserved2 : 28;/* [31:4] */
  453. } slib_sts0_bit;
  454. };
  455. /**
  456. * @brief flash slib_sts1 register, offset:0xD0
  457. */
  458. union
  459. {
  460. __IO uint32_t slib_sts1;
  461. struct
  462. {
  463. __IO uint32_t slib_ss : 11;/* [10:0] */
  464. __IO uint32_t slib_dat_ss : 11;/* [21:11] */
  465. __IO uint32_t slib_es : 10;/* [31:22] */
  466. } slib_sts1_bit;
  467. };
  468. /**
  469. * @brief flash slib_pwd_clr register, offset:0xD4
  470. */
  471. union
  472. {
  473. __IO uint32_t slib_pwd_clr;
  474. struct
  475. {
  476. __IO uint32_t slib_pclr_val : 32;/* [31:0] */
  477. } slib_pwd_clr_bit;
  478. };
  479. /**
  480. * @brief flash slib_misc_sts register, offset:0xD8
  481. */
  482. union
  483. {
  484. __IO uint32_t slib_misc_sts;
  485. struct
  486. {
  487. __IO uint32_t slib_pwd_err : 1; /* [0] */
  488. __IO uint32_t slib_pwd_ok : 1; /* [1] */
  489. __IO uint32_t slib_ulkf : 1; /* [2] */
  490. __IO uint32_t reserved1 : 13;/* [15:3] */
  491. __IO uint32_t slib_rcnt : 9; /* [24:16] */
  492. __IO uint32_t reserved2 : 7; /* [31:25] */
  493. } slib_misc_sts_bit;
  494. };
  495. /**
  496. * @brief flash slib_set_pwd register, offset:0xDC
  497. */
  498. union
  499. {
  500. __IO uint32_t slib_set_pwd;
  501. struct
  502. {
  503. __IO uint32_t slib_pset_val : 32;/* [31:0] */
  504. } slib_set_pwd_bit;
  505. };
  506. /**
  507. * @brief flash slib_set_range register, offset:0xE0
  508. */
  509. union
  510. {
  511. __IO uint32_t slib_set_range;
  512. struct
  513. {
  514. __IO uint32_t slib_ss_set : 11;/* [10:0] */
  515. __IO uint32_t slib_dss_set : 11;/* [21:11] */
  516. __IO uint32_t slib_es_set : 10;/* [31:22] */
  517. } slib_set_range_bit;
  518. };
  519. /**
  520. * @brief flash reserved6 register, offset:0xEC~0xE4
  521. */
  522. __IO uint32_t reserved6[3];
  523. /**
  524. * @brief flash slib_unlock register, offset:0xF0
  525. */
  526. union
  527. {
  528. __IO uint32_t slib_unlock;
  529. struct
  530. {
  531. __IO uint32_t slib_ukval : 32;/* [31:0] */
  532. } slib_unlock_bit;
  533. };
  534. /**
  535. * @brief flash crc_ctrl register, offset:0xF4
  536. */
  537. union
  538. {
  539. __IO uint32_t crc_ctrl;
  540. struct
  541. {
  542. __IO uint32_t crc_ss : 12;/* [11:0] */
  543. __IO uint32_t crc_sn : 12;/* [23:12] */
  544. __IO uint32_t reserved1 : 7; /* [30:24] */
  545. __IO uint32_t crc_strt : 1; /* [31] */
  546. } crc_ctrl_bit;
  547. };
  548. /**
  549. * @brief flash crc_chkr register, offset:0xF8
  550. */
  551. union
  552. {
  553. __IO uint32_t crc_chkr;
  554. struct
  555. {
  556. __IO uint32_t crc_chkr : 32;/* [31:0] */
  557. } crc_chkr_bit;
  558. };
  559. } flash_type;
  560. /**
  561. * @brief user system data
  562. */
  563. typedef struct
  564. {
  565. __IO uint16_t fap;
  566. __IO uint16_t ssb;
  567. __IO uint16_t data0;
  568. __IO uint16_t data1;
  569. __IO uint16_t epp0;
  570. __IO uint16_t epp1;
  571. __IO uint16_t epp2;
  572. __IO uint16_t epp3;
  573. __IO uint16_t eopb0;
  574. __IO uint16_t reserved;
  575. __IO uint16_t data2;
  576. __IO uint16_t data3;
  577. __IO uint16_t data4;
  578. __IO uint16_t data5;
  579. __IO uint16_t data6;
  580. __IO uint16_t data7;
  581. __IO uint16_t ext_flash_key[8];
  582. } usd_type;
  583. /**
  584. * @}
  585. */
  586. #define FLASH ((flash_type *) FLASH_REG_BASE)
  587. #define USD ((usd_type *) USD_BASE)
  588. /** @defgroup FLASH_exported_functions
  589. * @{
  590. */
  591. flag_status flash_flag_get(uint32_t flash_flag);
  592. void flash_flag_clear(uint32_t flash_flag);
  593. flash_status_type flash_operation_status_get(void);
  594. flash_status_type flash_bank1_operation_status_get(void);
  595. flash_status_type flash_bank2_operation_status_get(void);
  596. flash_status_type flash_spim_operation_status_get(void);
  597. flash_status_type flash_operation_wait_for(uint32_t time_out);
  598. flash_status_type flash_bank1_operation_wait_for(uint32_t time_out);
  599. flash_status_type flash_bank2_operation_wait_for(uint32_t time_out);
  600. flash_status_type flash_spim_operation_wait_for(uint32_t time_out);
  601. void flash_unlock(void);
  602. void flash_bank1_unlock(void);
  603. void flash_bank2_unlock(void);
  604. void flash_spim_unlock(void);
  605. void flash_lock(void);
  606. void flash_bank1_lock(void);
  607. void flash_bank2_lock(void);
  608. void flash_spim_lock(void);
  609. flash_status_type flash_sector_erase(uint32_t sector_address);
  610. flash_status_type flash_internal_all_erase(void);
  611. flash_status_type flash_bank1_erase(void);
  612. flash_status_type flash_bank2_erase(void);
  613. flash_status_type flash_spim_all_erase(void);
  614. flash_status_type flash_user_system_data_erase(void);
  615. flash_status_type flash_word_program(uint32_t address, uint32_t data);
  616. flash_status_type flash_halfword_program(uint32_t address, uint16_t data);
  617. flash_status_type flash_byte_program(uint32_t address, uint8_t data);
  618. flash_status_type flash_user_system_data_program(uint32_t address, uint8_t data);
  619. flash_status_type flash_epp_set(uint32_t *sector_bits);
  620. void flash_epp_status_get(uint32_t *sector_bits);
  621. flash_status_type flash_fap_enable(confirm_state new_state);
  622. flag_status flash_fap_status_get(void);
  623. flash_status_type flash_ssb_set(uint8_t usd_ssb);
  624. uint8_t flash_ssb_status_get(void);
  625. void flash_interrupt_enable(uint32_t flash_int, confirm_state new_state);
  626. void flash_spim_model_select(flash_spim_model_type mode);
  627. void flash_spim_encryption_range_set(uint32_t decode_address);
  628. void flash_spim_dummy_read(void);
  629. flash_status_type flash_spim_mass_program(uint32_t address, uint8_t *buf, uint32_t cnt);
  630. flash_status_type flash_slib_enable(uint32_t pwd, uint16_t start_sector, uint16_t data_start_sector, uint16_t end_sector);
  631. error_status flash_slib_disable(uint32_t pwd);
  632. uint32_t flash_slib_remaining_count_get(void);
  633. flag_status flash_slib_state_get(void);
  634. uint16_t flash_slib_start_sector_get(void);
  635. uint16_t flash_slib_datastart_sector_get(void);
  636. uint16_t flash_slib_end_sector_get(void);
  637. uint32_t flash_crc_calibrate(uint32_t start_sector, uint32_t sector_cnt);
  638. /**
  639. * @}
  640. */
  641. /**
  642. * @}
  643. */
  644. /**
  645. * @}
  646. */
  647. #ifdef __cplusplus
  648. }
  649. #endif
  650. #endif