py32f0xx.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx.h
  4. * @brief CMSIS PY32F0xx Device Peripheral Access Layer Header File.
  5. * @version v1.0.0
  6. *
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by Puya under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. * @attention
  20. *
  21. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  22. * All rights reserved.</center></h2>
  23. *
  24. * This software component is licensed by ST under BSD 3-Clause license,
  25. * the "License"; You may not use this file except in compliance with the
  26. * License. You may obtain a copy of the License at:
  27. * opensource.org/licenses/BSD-3-Clause
  28. *
  29. ******************************************************************************
  30. */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif /* __cplusplus */
  34. /** @addtogroup py32f0xx
  35. * @{
  36. */
  37. #ifndef __PY32F0XX_H
  38. #define __PY32F0XX_H
  39. /**
  40. * @brief PY32F0 Family
  41. */
  42. #if !defined (PY32F0)
  43. #define PY32F0
  44. #endif /* PY32F0 */
  45. /** Uncomment the line below according to the target PY32 device used in your
  46. * application.
  47. */
  48. #if !defined (PY32F002Ax5) && !defined (PY32F002Bx5) && \
  49. !defined (PY32F003x4) && !defined (PY32F003x6) && !defined (PY32F003x8) && \
  50. !defined (PY32F030x3) && !defined (PY32F030x4) && !defined (PY32F030x6) && !defined (PY32F030x7) && !defined (PY32F030x8) && !defined (PY32F030xx) && \
  51. !defined (PY32F031x3) && !defined (PY32F031x4) && !defined (PY32F031x6) && !defined (PY32F031x7) && !defined (PY32F031x8) && \
  52. !defined (PY32F071x6) && !defined (PY32F071x8) && !defined (PY32F071x9) && !defined (PY32F071xB) && \
  53. !defined (PY32F072x6) && !defined (PY32F072x8) && !defined (PY32F072x9) && !defined (PY32F072xB)
  54. /* #define PY32F002Ax5 */ /*!< PY32F002Ax5 Devices (PY32F002Ax5 microcontrollers where the Flash memory is 20 Kbytes) */
  55. /* #define PY32F002Bx5 */ /*!< PY32F002Bx5 Devices (PY32F002Bx5 microcontrollers where the Flash memory is 24 Kbytes) */
  56. /* #define PY32F003x4 */ /*!< PY32F003x4 Devices (PY32F003x4 microcontrollers where the Flash memory is 16 Kbytes) */
  57. /* #define PY32F003x6 */ /*!< PY32F003x6 Devices (PY32F003x6 microcontrollers where the Flash memory is 32 Kbytes) */
  58. /* #define PY32F003x8 */ /*!< PY32F003x8 Devices (PY32F003x8 microcontrollers where the Flash memory is 64 Kbytes) */
  59. /* #define PY32F030x3 */ /*!< PY32F030x3 Devices (PY32F030x3 microcontrollers where the Flash memory is 8 Kbytes) */
  60. /* #define PY32F030x4 */ /*!< PY32F030x4 Devices (PY32F030x4 microcontrollers where the Flash memory is 16 Kbytes) */
  61. /* #define PY32F030x6 */ /*!< PY32F030x6 Devices (PY32F030x6 microcontrollers where the Flash memory is 32 Kbytes) */
  62. /* #define PY32F030x7 */ /*!< PY32F030x7 Devices (PY32F030x7 microcontrollers where the Flash memory is 48 Kbytes) */
  63. /* #define PY32F030x8 */ /*!< PY32F030x8 Devices (PY32F030x8 microcontrollers where the Flash memory is 64 Kbytes) */
  64. /* #define PY32F031x3 */ /*!< PY32F031x3 Devices (PY32F031x3 microcontrollers where the Flash memory is 8 Kbytes) */
  65. /* #define PY32F031x4 */ /*!< PY32F031x4 Devices (PY32F031x4 microcontrollers where the Flash memory is 16 Kbytes) */
  66. /* #define PY32F031x6 */ /*!< PY32F031x6 Devices (PY32F031x6 microcontrollers where the Flash memory is 32 Kbytes) */
  67. /* #define PY32F031x7 */ /*!< PY32F031x7 Devices (PY32F031x7 microcontrollers where the Flash memory is 48 Kbytes) */
  68. /* #define PY32F031x8 */ /*!< PY32F031x8 Devices (PY32F031x8 microcontrollers where the Flash memory is 64 Kbytes) */
  69. /* #define PY32F071x6 */ /*!< PY32F071x6 Devices (PY32F071x6 microcontrollers where the Flash memory is 32 Kbytes) */
  70. /* #define PY32F071x8 */ /*!< PY32F071x8 Devices (PY32F071x8 microcontrollers where the Flash memory is 64 Kbytes) */
  71. /* #define PY32F071x9 */ /*!< PY32F071x9 Devices (PY32F071x9 microcontrollers where the Flash memory is 96 Kbytes) */
  72. /* #define PY32F071xB */ /*!< PY32F071xB Devices (PY32F071xB microcontrollers where the Flash memory is 128 Kbytes) */
  73. /* #define PY32F072x6 */ /*!< PY32F072x6 Devices (PY32F072x6 microcontrollers where the Flash memory is 32 Kbytes) */
  74. /* #define PY32F072x8 */ /*!< PY32F072x8 Devices (PY32F072x8 microcontrollers where the Flash memory is 64 Kbytes) */
  75. /* #define PY32F072x9 */ /*!< PY32F072x9 Devices (PY32F072x9 microcontrollers where the Flash memory is 96 Kbytes) */
  76. /* #define PY32F072xB */ /*!< PY32F072xB Devices (PY32F072xB microcontrollers where the Flash memory is 128 Kbytes) */
  77. #endif
  78. /** Tip: To avoid modifying this file each time you need to switch between these
  79. * devices, you can define the device in your toolchain compiler preprocessor.
  80. */
  81. #if (defined(PY32F002Ax5))
  82. #define PY32F002APRE
  83. #elif (defined(PY32F002Bx5))
  84. #define PY32F002BPRE
  85. #elif (defined(PY32F030x3) || defined(PY32F030x4) || defined(PY32F030x6) || defined(PY32F030x7) || defined(PY32F030x8))
  86. #define PY32F030PRE
  87. #elif (defined(PY32F031x3) || defined(PY32F031x4) || defined(PY32F031x6) || defined(PY32F031x7) || defined(PY32F031x8))
  88. #define PY32F031PRE
  89. #elif (defined(PY32F003x4) || defined(PY32F003x6) || defined(PY32F003x8))
  90. #define PY32F003PRE
  91. #elif (defined(PY32F071x6) || defined(PY32F071x8) || defined(PY32F071x9) || defined(PY32F071xB))
  92. #define PY32F071PRE
  93. #elif (defined(PY32F072x6) || defined(PY32F072x8) || defined(PY32F072x9) || defined(PY32F072xB))
  94. #define PY32F072PRE
  95. #endif
  96. /**
  97. * @brief CMSIS Device version number V1.0.0
  98. */
  99. #define __PY32F0_DEVICE_VERSION_MAIN (0x01) /*!< [31:24] main version */
  100. #define __PY32F0_DEVICE_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
  101. #define __PY32F0_DEVICE_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
  102. #define __PY32F0_DEVICE_VERSION_RC (0x00) /*!< [7:0] release candidate */
  103. #define __PY32F0_DEVICE_VERSION ((__PY32F0_DEVICE_VERSION_MAIN << 24)\
  104. |(__PY32F0_DEVICE_VERSION_SUB1 << 16)\
  105. |(__PY32F0_DEVICE_VERSION_SUB2 << 8 )\
  106. |(__PY32F0_DEVICE_VERSION_RC))
  107. /**
  108. * @brief Device_Included
  109. */
  110. #if defined(PY32F002Ax5)
  111. #include "py32f002ax5.h"
  112. #elif defined(PY32F002Bx5)
  113. #include "py32f002bx5.h"
  114. #elif defined(PY32F003x4)
  115. #include "py32f003x4.h"
  116. #elif defined(PY32F003x6)
  117. #include "py32f003x6.h"
  118. #elif defined(PY32F003x8)
  119. #include "py32f003x8.h"
  120. #elif defined(PY32F030x3)
  121. #include "py32f030x3.h"
  122. #elif defined(PY32F030x4)
  123. #include "py32f030x4.h"
  124. #elif defined(PY32F030x6)
  125. #include "py32f030x6.h"
  126. #elif defined(PY32F030x7)
  127. #include "py32f030x7.h"
  128. #elif defined(PY32F030x8)
  129. #include "py32f030x8.h"
  130. #elif defined(PY32F031x3)
  131. #include "py32f031x3.h"
  132. #elif defined(PY32F031x4)
  133. #include "py32f031x4.h"
  134. #elif defined(PY32F031x6)
  135. #include "py32f031x6.h"
  136. #elif defined(PY32F031x7)
  137. #include "py32f031x7.h"
  138. #elif defined(PY32F031x8)
  139. #include "py32f031x8.h"
  140. #elif defined(PY32F071x6)
  141. #include "py32f071x6.h"
  142. #elif defined(PY32F071x8)
  143. #include "py32f071x8.h"
  144. #elif defined(PY32F071x9)
  145. #include "py32f071x9.h"
  146. #elif defined(PY32F071xB)
  147. #include "py32f071xB.h"
  148. #elif defined(PY32F072x6)
  149. #include "py32f072x6.h"
  150. #elif defined(PY32F072x8)
  151. #include "py32f072x8.h"
  152. #elif defined(PY32F072x9)
  153. #include "py32f072x9.h"
  154. #elif defined(PY32F072xB)
  155. #include "py32f072xB.h"
  156. #else
  157. #error "Please select first the target PY32F0xx device used in your application (in py32f0xx.h file)"
  158. #endif /* Device_Included */
  159. /**
  160. * @brief Exported_types
  161. */
  162. typedef enum
  163. {
  164. RESET = 0,
  165. SET = !RESET
  166. } FlagStatus, ITStatus;
  167. typedef enum
  168. {
  169. DISABLE = 0,
  170. ENABLE = !DISABLE
  171. } FunctionalState;
  172. #define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
  173. typedef enum
  174. {
  175. SUCCESS = 0U,
  176. ERROR = !SUCCESS
  177. } ErrorStatus;
  178. /**
  179. * @brief Exported_macros
  180. */
  181. #define SET_BIT(REG, BIT) ((REG) |= (BIT))
  182. #define CLEAR_BIT(REG, BIT) ((REG) &= ~(BIT))
  183. #define READ_BIT(REG, BIT) ((REG) & (BIT))
  184. #define CLEAR_REG(REG) ((REG) = (0x0))
  185. #define WRITE_REG(REG, VAL) ((REG) = (VAL))
  186. #define READ_REG(REG) ((REG))
  187. #define MODIFY_REG(REG, CLEARMASK, SETMASK) WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
  188. /* Use of interrupt control for register exclusive access */
  189. /* Atomic 32-bit register access macro to set one or several bits */
  190. #define ATOMIC_SET_BIT(REG, BIT) \
  191. do { \
  192. uint32_t primask; \
  193. primask = __get_PRIMASK(); \
  194. __set_PRIMASK(1); \
  195. SET_BIT((REG), (BIT)); \
  196. __set_PRIMASK(primask); \
  197. } while(0)
  198. /* Atomic 32-bit register access macro to clear one or several bits */
  199. #define ATOMIC_CLEAR_BIT(REG, BIT) \
  200. do { \
  201. uint32_t primask; \
  202. primask = __get_PRIMASK(); \
  203. __set_PRIMASK(1); \
  204. CLEAR_BIT((REG), (BIT)); \
  205. __set_PRIMASK(primask); \
  206. } while(0)
  207. /* Atomic 32-bit register access macro to clear and set one or several bits */
  208. #define ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  209. do { \
  210. uint32_t primask; \
  211. primask = __get_PRIMASK(); \
  212. __set_PRIMASK(1); \
  213. MODIFY_REG((REG), (CLEARMSK), (SETMASK)); \
  214. __set_PRIMASK(primask); \
  215. } while(0)
  216. /* Atomic 16-bit register access macro to set one or several bits */
  217. #define ATOMIC_SETH_BIT(REG, BIT) ATOMIC_SET_BIT(REG, BIT) \
  218. /* Atomic 16-bit register access macro to clear one or several bits */
  219. #define ATOMIC_CLEARH_BIT(REG, BIT) ATOMIC_CLEAR_BIT(REG, BIT) \
  220. /* Atomic 16-bit register access macro to clear and set one or several bits */
  221. #define ATOMIC_MODIFYH_REG(REG, CLEARMSK, SETMASK) ATOMIC_MODIFY_REG(REG, CLEARMSK, SETMASK) \
  222. #define HW32_REG(ADDRESS) ( * ((volatile unsigned int * )(ADDRESS)))
  223. #define HW16_REG(ADDRESS) ( * ((volatile unsigned short int * )(ADDRESS)))
  224. #define HW8_REG(ADDRESS) ( * ((volatile unsigned char * )(ADDRESS)))
  225. #define M32(ADDRESS) HW32_REG(ADDRESS)
  226. #define M16(ADDRESS) HW16_REG(ADDRESS)
  227. #define M8(ADDRESS) HW8_REG(ADDRESS)
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @brief Comment the line below if you will not use the peripherals drivers.
  233. * In this case, these drivers will not be included and the application code will
  234. * be based on direct access to peripherals registers
  235. */
  236. #if !defined (USE_HAL_DRIVER)
  237. /*#define USE_HAL_DRIVER */
  238. #endif /* USE_HAL_DRIVER */
  239. #if defined (USE_HAL_DRIVER)
  240. #if (defined(PY32F071PRE) || defined(PY32F072PRE))
  241. #include "py32f07x_hal.h"
  242. #else
  243. #include "py32f0xx_hal.h"
  244. #endif /* Device_Included */
  245. #endif /* USE_HAL_DRIVER */
  246. #endif /* __PY32F0xx_H */
  247. #ifdef __cplusplus
  248. }
  249. #endif /* __cplusplus */
  250. /************************ (C) COPYRIGHT Puya *****END OF FILE******************/