reg_flash.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file reg_flash.h
  3. /// @author AE TEAM
  4. /// @brief THIS FILE CONTAINS ALL THE FUNCTIONS PROTOTYPES FOR THE SERIES OF
  5. /// MM32 FIRMWARE LIBRARY.
  6. ////////////////////////////////////////////////////////////////////////////////
  7. /// @attention
  8. ///
  9. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  10. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  11. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  12. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  13. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  14. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  15. ///
  16. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  17. ////////////////////////////////////////////////////////////////////////////////
  18. // Define to prevent recursive inclusion
  19. #ifndef __REG_FLASH_H
  20. #define __REG_FLASH_H
  21. // Files includes
  22. #include <stdint.h>
  23. #include <stdbool.h>
  24. #include "types.h"
  25. #if defined ( __CC_ARM )
  26. #pragma anon_unions
  27. #endif
  28. ////////////////////////////////////////////////////////////////////////////////
  29. /// @brief MM32 MCU Memory/Peripherals mapping
  30. ////////////////////////////////////////////////////////////////////////////////
  31. #define FLASH_BASE (0x08000000U) ///< FLASH base address in the alias region
  32. #define SRAM_BASE (0x20000000U) ///< SRAM base address in the alias region
  33. #define CACHE_BASE (APB2PERIPH_BASE + 0x6000) ///< Base Address: 0x40016000
  34. ////////////////////////////////////////////////////////////////////////////////
  35. /// @brief FLASH Base Address Definition
  36. ////////////////////////////////////////////////////////////////////////////////
  37. #define FLASH_REG_BASE (AHBPERIPH_BASE + 0x2000) ///< Base Address: 0x40022000
  38. ////////////////////////////////////////////////////////////////////////////////
  39. /// @brief OPTB Base Address Definition
  40. ////////////////////////////////////////////////////////////////////////////////
  41. #define OB_BASE (0x1FFFF800U) ///< Flash Option Bytes base address
  42. #define PROTECT_BASE (0x1FFE0000U) ///< Flash Protect Bytes base address
  43. ////////////////////////////////////////////////////////////////////////////////
  44. /// @brief FLASH Registers Structure Definition
  45. ////////////////////////////////////////////////////////////////////////////////
  46. typedef struct {
  47. __IO u32 ACR; ///< Access control Register offset: 0x00
  48. __IO u32 KEYR; ///< Key Register offset: 0x04
  49. __IO u32 OPTKEYR; ///< Option byte key Register offset: 0x08
  50. __IO u32 SR; ///< State Register offset: 0x0C
  51. __IO u32 CR; ///< Control Register offset: 0x10
  52. __IO u32 AR; ///< Address Register offset: 0x14
  53. __IO u32 RESERVED;
  54. __IO u32 OBR; ///< Option bytes Register offset: 0x1C
  55. __IO u32 WRPR; ///< Write protect Register offset: 0x20
  56. } FLASH_TypeDef;
  57. ////////////////////////////////////////////////////////////////////////////////
  58. /// @brief OPT Structure Definition
  59. ////////////////////////////////////////////////////////////////////////////////
  60. typedef struct {
  61. __IO u16 RDP; ///< Read Protect, offset: 0x00
  62. __IO u16 USER; ///< User option byte, offset: 0x02
  63. __IO u16 Data0; ///< User data 0, offset: 0x04
  64. __IO u16 Data1; ///< User data 1, offset: 0x06
  65. __IO u16 WRP0; ///< Flash write protection option byte 0, offset: 0x08
  66. __IO u16 WRP1; ///< Flash write protection option byte 1, offset: 0x0A
  67. __IO u16 WRP2; ///< Flash write protection option byte 2, offset: 0x0C
  68. __IO u16 WRP3; ///< Flash write protection option byte 3, offset: 0x0E
  69. } OB_TypeDef;
  70. ////////////////////////////////////////////////////////////////////////////////
  71. /// @brief PROTECT BYTES Structure Definition
  72. ////////////////////////////////////////////////////////////////////////////////
  73. typedef struct {
  74. __IO u16 PROTECT_LEN0; ///< The length of Protect byte 0, offset: 0x00
  75. __IO u16 PROTECT_ADDR0; ///< Data of Protect byte 0, offset: 0x02
  76. __IO u16 PROTECT_LEN1; ///< The length of Protect byte 1, offset: 0x04
  77. __IO u16 PROTECT_ADDR1; ///< Data of Protect byte 1, offset: 0x06
  78. __IO u16 PROTECT_LEN2; ///< The length of Protect byte 2, offset: 0x08
  79. __IO u16 PROTECT_ADDR2; ///< Data of Protect byte 2, offset: 0x0A
  80. __IO u16 PROTECT_LEN3; ///< The length of Protect byte 3, offset: 0x0C
  81. __IO u16 PROTECT_ADDR3; ///< Data of Protect byte 3, offset: 0x0E
  82. } PROTECT_TypeDef;
  83. ////////////////////////////////////////////////////////////////////////////////
  84. /// @brief CACHE BYTES Structure Definition
  85. ////////////////////////////////////////////////////////////////////////////////
  86. typedef struct {
  87. __IO u32 CCR; ///< Configuration and control register offset: 0x00
  88. __IO u32 SR; ///< Status register offset: 0x04
  89. __IO u32 IMR; ///< Interrupt mask register offset: 0x08
  90. __IO u32 ISR; ///< Interrupt status register offset: 0x0C
  91. __IO u32 RESERVED0; ///< offset: 0x10
  92. __IO u32 CSHR; ///< Hit Statistics Register offset: 0x14
  93. __IO u32 CSMR; ///< Lost Statistics Register offset: 0x18
  94. } CACHE_TypeDef;
  95. ////////////////////////////////////////////////////////////////////////////////
  96. /// @brief FLASH type pointer Definition
  97. ////////////////////////////////////////////////////////////////////////////////
  98. #define FLASH ((FLASH_TypeDef*) FLASH_REG_BASE)
  99. ////////////////////////////////////////////////////////////////////////////////
  100. /// @brief OPTB type pointer Definition
  101. ////////////////////////////////////////////////////////////////////////////////
  102. #define OB ((OB_TypeDef*) OB_BASE)
  103. #define PROTECT ((PROTECT_TypeDef*) PROTECT_BASE)
  104. ////////////////////////////////////////////////////////////////////////////////
  105. /// @brief CACHE pointer Definition
  106. ////////////////////////////////////////////////////////////////////////////////
  107. #define CACHE ((CACHE_TypeDef*) CACHE_BASE)
  108. ////////////////////////////////////////////////////////////////////////////////
  109. /// @brief FLASH_ACR Register Bit Definition
  110. ////////////////////////////////////////////////////////////////////////////////
  111. #define FLASH_ACR_LATENCY_Pos (0)
  112. #define FLASH_ACR_LATENCY (0x07U << FLASH_ACR_LATENCY_Pos) ///< LATENCY[2:0] bits (Latency)
  113. #define FLASH_ACR_LATENCY_0 (0x00U << FLASH_ACR_LATENCY_Pos) ///< 0 waiting state
  114. #define FLASH_ACR_LATENCY_1 (0x01U << FLASH_ACR_LATENCY_Pos) ///< 1 waiting state
  115. #define FLASH_ACR_LATENCY_2 (0x02U << FLASH_ACR_LATENCY_Pos) ///< 2 waiting state
  116. #define FLASH_ACR_LATENCY_3 (0x03U << FLASH_ACR_LATENCY_Pos) ///< 3 waiting state
  117. #define FLASH_ACR_HLFCYA_Pos (3)
  118. #define FLASH_ACR_HLFCYA (0x01U << FLASH_ACR_HLFCYA_Pos) ///< Flash Half Cycle Access Enable
  119. #define FLASH_ACR_PRFTBE_Pos (4)
  120. #define FLASH_ACR_PRFTBE (0x01U << FLASH_ACR_PRFTBE_Pos) ///< Prefetch Buffer Enable
  121. #define FLASH_ACR_PRFTBS_Pos (5)
  122. #define FLASH_ACR_PRFTBS (0x01U << FLASH_ACR_PRFTBS_Pos) ///< Prefetch Buffer Status
  123. ////////////////////////////////////////////////////////////////////////////////
  124. /// @brief FLASH_KEYR Register Bit Definition
  125. ////////////////////////////////////////////////////////////////////////////////
  126. #define FLASH_KEYR_FKEY_Pos (0)
  127. #define FLASH_KEYR_FKEY (0xFFFFFFFFU << FLASH_KEYR_FKEY_Pos) ///< FLASH Key
  128. ////////////////////////////////////////////////////////////////////////////////
  129. /// @brief FLASH_OPTKEYR Register Bit Definition
  130. ////////////////////////////////////////////////////////////////////////////////
  131. #define FLASH_OPTKEYR_OPTKEY_Pos (0)
  132. #define FLASH_OPTKEYR_OPTKEY (0xFFFFFFFFU << FLASH_OPTKEYR_OPTKEY_Pos) ///< Option Byte Key
  133. ////////////////////////////////////////////////////////////////////////////////
  134. /// @brief FLASH_SR Register Bit Definition
  135. ////////////////////////////////////////////////////////////////////////////////
  136. #define FLASH_SR_BUSY_Pos (0)
  137. #define FLASH_SR_BUSY (0x01U << FLASH_SR_BUSY_Pos) ///< Busy
  138. #define FLASH_SR_PGERR_Pos (2)
  139. #define FLASH_SR_PGERR (0x01U << FLASH_SR_PGERR_Pos) ///< Programming Error
  140. #define FLASH_SR_WRPRTERR_Pos (4)
  141. #define FLASH_SR_WRPRTERR (0x01U << FLASH_SR_WRPRTERR_Pos) ///< Write Protection Error
  142. #define FLASH_SR_EOP_Pos (5)
  143. #define FLASH_SR_EOP (0x01U << FLASH_SR_EOP_Pos) ///< End of operation
  144. ////////////////////////////////////////////////////////////////////////////////
  145. /// @brief FLASH_CR Register Bit Definition
  146. ////////////////////////////////////////////////////////////////////////////////
  147. #define FLASH_CR_PG_Pos (0)
  148. #define FLASH_CR_PG (0x01U << FLASH_CR_PG_Pos) ///< Programming
  149. #define FLASH_CR_PER_Pos (1)
  150. #define FLASH_CR_PER (0x01U << FLASH_CR_PER_Pos) ///< Page Erase
  151. #define FLASH_CR_MER_Pos (2)
  152. #define FLASH_CR_MER (0x01U << FLASH_CR_MER_Pos) ///< Mass Erase
  153. #define FLASH_CR_OPTPG_Pos (4)
  154. #define FLASH_CR_OPTPG (0x01U << FLASH_CR_OPTPG_Pos) ///< Option Byte Programming
  155. #define FLASH_CR_OPTER_Pos (5)
  156. #define FLASH_CR_OPTER (0x01U << FLASH_CR_OPTER_Pos) ///< Option Byte Erase
  157. #define FLASH_CR_STRT_Pos (6)
  158. #define FLASH_CR_STRT (0x01U << FLASH_CR_STRT_Pos) ///< Start
  159. #define FLASH_CR_LOCK_Pos (7)
  160. #define FLASH_CR_LOCK (0x01U << FLASH_CR_LOCK_Pos) ///< Lock
  161. #define FLASH_CR_OPTWRE_Pos (9)
  162. #define FLASH_CR_OPTWRE (0x01U << FLASH_CR_OPTWRE_Pos) ///< Option Bytes Write Enable
  163. #define FLASH_CR_ERRIE_Pos (10)
  164. #define FLASH_CR_ERRIE (0x01U << FLASH_CR_ERRIE_Pos) ///< Error Interrupt Enable
  165. #define FLASH_CR_EOPIE_Pos (12)
  166. #define FLASH_CR_EOPIE (0x01U << FLASH_CR_EOPIE_Pos) ///< End of operation interrupt enable
  167. ////////////////////////////////////////////////////////////////////////////////
  168. /// @brief FLASH_AR Register Bit Definition
  169. ////////////////////////////////////////////////////////////////////////////////
  170. #define FLASH_AR_FAR_Pos (0)
  171. #define FLASH_AR_FAR (0xFFFFFFFFU << FLASH_AR_FAR_Pos) ///< Flash Address
  172. ////////////////////////////////////////////////////////////////////////////////
  173. /// @brief FLASH_OBR Register Bit Definition
  174. ////////////////////////////////////////////////////////////////////////////////
  175. #define FLASH_OBR_OPTERR_Pos (0)
  176. #define FLASH_OBR_OPTERR (0x01U << FLASH_OBR_OPTERR_Pos) ///< Option Byte Error
  177. #define FLASH_OBR_RDPRT_Pos (1)
  178. #define FLASH_OBR_RDPRT (0x01U << FLASH_OBR_RDPRT_Pos) ///< Read protection level status
  179. #define FLASH_OBR_USER_Pos (2)
  180. #define FLASH_OBR_USER (0xFFU << FLASH_OBR_USER_Pos) ///< User Option Bytes
  181. #define FLASH_OBR_WDG_SW (0x01U << FLASH_OBR_USER_Pos) ///< WDG_SW
  182. #define FLASH_OBR_RST_STOP (0x02U << FLASH_OBR_USER_Pos) ///< nRST_STOP
  183. #define FLASH_OBR_RST_STDBY (0x04U << FLASH_OBR_USER_Pos) ///< nRST_STDBY
  184. #define FLASH_OBR_Data0_Pos (10)
  185. #define FLASH_OBR_Data0 (0xFFU << FLASH_OBR_Data0_Pos) ///< User data storage option byte
  186. #define FLASH_OBR_Data1_Pos (18)
  187. #define FLASH_OBR_Data1 (0xFFU << FLASH_OBR_Data1_Pos) ///< User data storage option byte
  188. ////////////////////////////////////////////////////////////////////////////////
  189. /// @brief FLASH_WRPR Register Bit Definition
  190. ////////////////////////////////////////////////////////////////////////////////
  191. #define FLASH_WRPR_WRP_Pos (0)
  192. #define FLASH_WRPR_WRP (0xFFFFFFFFU << FLASH_WRPR_WRP_Pos) ///< Write Protect
  193. ////////////////////////////////////////////////////////////////////////////////
  194. /// @brief CACHE_CCR Register Bit Definition
  195. ////////////////////////////////////////////////////////////////////////////////
  196. #define CACHE_CCR_EN_Pos (0)
  197. #define CACHE_CCR_EN (0x01U << CACHE_CCR_EN_Pos) ///< Cache Enable
  198. #define CACHE_CCR_INV_Pos (1)
  199. #define CACHE_CCR_INV (0x01U << CACHE_CCR_INV_REQ_Pos) ///< Manually invalidate the request
  200. #define CACHE_CCR_POW_Pos (2)
  201. #define CACHE_CCR_POW (0x01U << CACHE_CCR_POW_REQ_Pos) ///< Manual SRAM power request
  202. #define CACHE_CCR_MAN_POW_Pos (3)
  203. #define CACHE_CCR_MAN_POW (0x01U << CACHE_CCR_MAN_POW_Pos) ///< Set manual or automatic SRAM power request
  204. #define CACHE_CCR_MAN_INV_Pos (4)
  205. #define CACHE_CCR_MAN_INV (0x01U << CACHE_CCR_MAN_INV_Pos) ///< Manually or automatically disable it
  206. #define CACHE_CCR_PREFETCH_Pos (5)
  207. #define CACHE_CCR_PREFETCH (0x01U << CACHE_CCR_PREFETCH_Pos) ///< Prefetch function
  208. #define CACHE_CCR_STATISTIC_Pos (6)
  209. #define CACHE_CCR_STATISTIC (0x01U << CACHE_CCR_STATISTIC_Pos) ///< Statistics enable
  210. ////////////////////////////////////////////////////////////////////////////////
  211. /// @brief CACHE_SR Register Bit Definition
  212. ////////////////////////////////////////////////////////////////////////////////
  213. #define CACHE_SR_CS_Pos (0)
  214. #define CACHE_SR_CS0 (0x00U << CACHE_CCR_CS_Pos) ///< Cache is disabled
  215. #define CACHE_SR_CS1 (0x01U << CACHE_CCR_CS_Pos) ///< Cache is being enabled
  216. #define CACHE_SR_CS2 (0x02U << CACHE_CCR_CS_Pos) ///< Cache is enabled
  217. #define CACHE_SR_CS3 (0x03U << CACHE_CCR_CS_Pos) ///< Cache is being disabled
  218. #define CACHE_SR_INV_Pos (2)
  219. #define CACHE_SR_INV (0x01U << CACHE_CCR_INV_REQ_Pos) ///< Invalidation status
  220. #define CACHE_SR_POW_Pos (4)
  221. #define CACHE_SR_POW (0x01U << CACHE_CCR_POW_REQ_Pos) ///< SRAM power response
  222. ////////////////////////////////////////////////////////////////////////////////
  223. /// @brief CACHE_IMR Register Bit Definition
  224. ////////////////////////////////////////////////////////////////////////////////
  225. #define CACHE_IMR_MAN_INV_Pos (0)
  226. #define CACHE_IMR_MAN_INV (0x01U << CACHE_IMR_MAN_INV_Pos) ///< Mask the interrupt request of manual invalidation error
  227. #define CACHE_IMR_POW_Pos (1)
  228. #define CACHE_IMR_POW (0x01U << CACHE_IMR_POW_Pos) ///< Mask the interrupt request of power supply error
  229. ////////////////////////////////////////////////////////////////////////////////
  230. /// @brief CACHE_ISR Register Bit Definition
  231. ////////////////////////////////////////////////////////////////////////////////
  232. #define CACHE_ISR_MAN_INV_Pos (0)
  233. #define CACHE_ISR_MAN_INV (0x01U << CACHE_ISR_MAN_INV_Pos) ///< Manual invalidation of error flags
  234. #define CACHE_ISR_POW_Pos (1)
  235. #define CACHE_ISR_POW (0x01U << CACHE_ISR_POW_Pos) ///< SRAM power error flags
  236. ////////////////////////////////////////////////////////////////////////////////
  237. /// @brief CACHE_CSHR Register Bit Definition
  238. ////////////////////////////////////////////////////////////////////////////////
  239. #define CACHE_CSHR (0xFFFFU ) ///< Cache Hits
  240. ////////////////////////////////////////////////////////////////////////////////
  241. /// @brief CACHE_CSHR Register Bit Definition
  242. ////////////////////////////////////////////////////////////////////////////////
  243. #define CACHE_CSMR (0xFFFFU ) ///< Cache Lost times
  244. /// @}
  245. /// @}
  246. /// @}
  247. ////////////////////////////////////////////////////////////////////////////////
  248. #endif
  249. ////////////////////////////////////////////////////////////////////////////////