apm32f0xx_syscfg.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*!
  2. * @file apm32f0xx_syscfg.c
  3. *
  4. * @brief This file contains all the functions for the SYSCFG peripheral
  5. *
  6. * @version V1.0.3
  7. *
  8. * @date 2022-09-20
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. #include "apm32f0xx_syscfg.h"
  26. /** @addtogroup APM32F0xx_StdPeriphDriver
  27. @{
  28. */
  29. /** @addtogroup SYSCFG_Driver SYSCFG Driver
  30. @{
  31. */
  32. /** @defgroup SYSCFG_Macros Macros
  33. @{
  34. */
  35. /**@} end of group SYSCFG_Macros */
  36. /** @defgroup SYSCFG_Enumerations Enumerations
  37. @{
  38. */
  39. /**@} end of group SYSCFG_Enumerations */
  40. /** @defgroup SYSCFG_Structures Structures
  41. @{
  42. */
  43. /**@} end of group SYSCFG_Structures */
  44. /** @defgroup SYSCFG_Variables Variables
  45. @{
  46. */
  47. /**@} end of group SYSCFG_Variables */
  48. /** @defgroup SYSCFG_Functions Functions
  49. @{
  50. */
  51. /*!
  52. * @brief Set SYSCFG CFG0/1 EINTCFG1/2/3/4 register to reset value
  53. *
  54. * @param None
  55. *
  56. * @retval None
  57. */
  58. void SYSCFG_Reset(void)
  59. {
  60. SYSCFG->CFG1 &= (uint32_t) SYSCFG_CFG1_MEMMODE;
  61. SYSCFG->EINTCFG1 = 0;
  62. SYSCFG->EINTCFG2 = 0;
  63. SYSCFG->EINTCFG3 = 0;
  64. SYSCFG->EINTCFG4 = 0;
  65. SYSCFG->CFG2 |= (uint32_t) SYSCFG_CFG2_SRAMPEF;
  66. }
  67. /*!
  68. * @brief SYSCFG Memory Remap selects
  69. *
  70. * @param memory: selects the memory remapping
  71. * The parameter can be one of following values:
  72. * @arg SYSCFG_MEMORY_REMAP_FMC: SYSCFG MemoryRemap Flash
  73. * @arg SYSCFG_MEMORY_REMAP_SYSTEM: SYSCFG MemoryRemap SystemMemory
  74. * @arg SYSCFG_MEMORY_REMAP_SRAM: SYSCFG MemoryRemap SRAM
  75. *
  76. * @retval None
  77. */
  78. void SYSCFG_MemoryRemapSelect(uint8_t memory)
  79. {
  80. SYSCFG->CFG1_B.MMSEL = (uint8_t)memory;
  81. }
  82. /*!
  83. * @brief Enables SYSCFG DMA Channel Remap
  84. *
  85. * @param channel: selects the DMA channels remap.
  86. * The parameter can be any combination of following values:
  87. * @arg SYSCFG_DAM_REMAP_ADC: ADC DMA remap
  88. * @arg SYSCFG_DAM_REMAP_USART1TX: USART1 TX DMA remap
  89. * @arg SYSCFG_DAM_REMAP_USART1RX: USART1 RX DMA remap
  90. * @arg SYSCFG_DAM_REMAP_TMR16: Timer 16 DMA remap
  91. * @arg SYSCFG_DAM_REMAP_TMR17: Timer 17 DMA remap
  92. * @arg SYSCFG_DAM_REMAP_TMR16_2: Timer 16 DMA remap2(only for APM32F072)
  93. * @arg SYSCFG_DAM_REMAP_TMR17_2: Timer 17 DMA remap2(only for APM32F072)
  94. * @arg SYSCFG_DAM_REMAP_SPI2: SPI2 DMA remap(only for APM32F072)
  95. * @arg SYSCFG_DAM_REMAP_USART2: USART1 TX DMA remap(only for APM32F072)
  96. * @arg SYSCFG_DAM_REMAP_USART3: USART1 RX DMA remap(only for APM32F072)
  97. * @arg SYSCFG_DAM_REMAP_I2C1: I2C1 DMA remap(only for APM32F072)
  98. * @arg SYSCFG_DAM_REMAP_TMR1: Timer 1 DMA remap(only for APM32F072)
  99. * @arg SYSCFG_DAM_REMAP_TMR2: Timer 2 DMA remap(only for APM32F072)
  100. * @arg SYSCFG_DAM_REMAP_TMR3: Timer 3 DMA remap(only for APM32F072)
  101. *
  102. * @retval None
  103. */
  104. void SYSCFG_EnableDMAChannelRemap(uint32_t channel)
  105. {
  106. SYSCFG->CFG1 |= (uint32_t)channel;
  107. }
  108. /*!
  109. * @brief Disables SYSCFG DMA Channel Remap
  110. *
  111. * @param channel: selects the DMA channels remap.
  112. * The parameter can be any combination of following values:
  113. * @arg SYSCFG_DAM_REMAP_ADC: ADC DMA remap
  114. * @arg SYSCFG_DAM_REMAP_USART1TX: USART1 TX DMA remap
  115. * @arg SYSCFG_DAM_REMAP_USART1RX: USART1 RX DMA remap
  116. * @arg SYSCFG_DAM_REMAP_TMR16: Timer 16 DMA remap
  117. * @arg SYSCFG_DAM_REMAP_TMR17: Timer 17 DMA remap
  118. * @arg SYSCFG_DAM_REMAP_TMR16_2: Timer 16 DMA remap2(only for APM32F072)
  119. * @arg SYSCFG_DAM_REMAP_TMR17_2: Timer 17 DMA remap2(only for APM32F072)
  120. * @arg SYSCFG_DAM_REMAP_SPI2: SPI2 DMA remap(only for APM32F072)
  121. * @arg SYSCFG_DAM_REMAP_USART2: USART1 TX DMA remap(only for APM32F072)
  122. * @arg SYSCFG_DAM_REMAP_USART3: USART1 RX DMA remap(only for APM32F072)
  123. * @arg SYSCFG_DAM_REMAP_I2C1: I2C1 DMA remap(only for APM32F072)
  124. * @arg SYSCFG_DAM_REMAP_TMR1: Timer 1 DMA remap(only for APM32F072)
  125. * @arg SYSCFG_DAM_REMAP_TMR2: Timer 2 DMA remap(only for APM32F072)
  126. * @arg SYSCFG_DAM_REMAP_TMR3: Timer 3 DMA remap(only for APM32F072)
  127. *
  128. * @retval None
  129. */
  130. void SYSCFG_DisableDMAChannelRemap(uint32_t channel)
  131. {
  132. SYSCFG->CFG1 &= (uint32_t)~channel;
  133. }
  134. /*!
  135. * @brief Enables SYSCFG I2C Fast Mode Plus
  136. *
  137. * @param pin: selects the pin.
  138. * The parameter can be combination of following values:
  139. * @arg SYSCFG_I2C_FMP_PB6: I2C PB6 Fast mode plus
  140. * @arg SYSCFG_I2C_FMP_PB7: I2C PB7 Fast mode plus
  141. * @arg SYSCFG_I2C_FMP_PB8: I2C PB8 Fast mode plus
  142. * @arg SYSCFG_I2C_FMP_PB9: I2C PB9 Fast mode plus
  143. * @arg SYSCFG_I2C_FMP_PA9: I2C PA9 Fast mode plus(only for APM32F030 and APM32F091)
  144. * @arg SYSCFG_I2C_FMP_PA10: I2C PA10 Fast mode plus(only for APM32F030 and APM32F091)
  145. * @arg SYSCFG_I2C_FMP_I2C1: PB10, PB11, PF6 and PF7
  146. * @arg SYSCFG_I2C_FMP_I2C2: I2C2 Fast mode plus(only for APM32F072 and APM32F091)
  147. *
  148. * @retval None
  149. */
  150. void SYSCFG_EnableI2CFastModePlus(uint32_t pin)
  151. {
  152. SYSCFG->CFG1 |= (uint32_t)pin;
  153. }
  154. /*!
  155. * @brief Disables SYSCFG I2C Fast Mode Plus
  156. *
  157. * @param pin: selects the pin.
  158. * The parameter can be combination of following values:
  159. * @arg SYSCFG_I2C_FMP_PB6: I2C PB6 Fast mode plus
  160. * @arg SYSCFG_I2C_FMP_PB7: I2C PB7 Fast mode plus
  161. * @arg SYSCFG_I2C_FMP_PB8: I2C PB8 Fast mode plus
  162. * @arg SYSCFG_I2C_FMP_PB9: I2C PB9 Fast mode plus
  163. * @arg SYSCFG_I2C_FMP_PA9: I2C PA9 Fast mode plus(only for APM32F030 and APM32F091)
  164. * @arg SYSCFG_I2C_FMP_PA10: I2C PA10 Fast mode plus(only for APM32F030 and APM32F091)
  165. * @arg SYSCFG_I2C_FMP_I2C1: PB10, PB11, PF6 and PF7
  166. * @arg SYSCFG_I2C_FMP_I2C2: I2C2 Fast mode plus(only for APM32F072 and APM32F091)
  167. *
  168. * @retval None
  169. */
  170. void SYSCFG_DisableI2CFastModePlus(uint32_t pin)
  171. {
  172. SYSCFG->CFG1 &= (uint32_t)~pin;
  173. }
  174. /*!
  175. * @brief Select the modulation envelope source
  176. *
  177. * @param IRDAEnv: selects the envelope source
  178. * The parameter can be one of following values:
  179. * @arg SYSCFG_IRDA_ENV_TMR16: Timer16 as IRDA Modulation envelope source
  180. * @arg SYSCFG_IRDA_ENV_USART1: USART1 as IRDA Modulation envelope source
  181. * @arg SYSCFG_IRDA_ENV_USART2: USART4 as IRDA Modulation envelope source
  182. *
  183. * @retval None
  184. *
  185. * @note It's only for APM32F091 devices.
  186. */
  187. void SYSCFG_SelectIRDAEnv(SYSCFG_IRDA_ENV_T IRDAEnv)
  188. {
  189. SYSCFG->CFG1 &= ~(0x000000C0);
  190. SYSCFG->CFG1 |= (IRDAEnv);
  191. }
  192. /*!
  193. * @brief Selects the GPIO pin used as EINT Line.
  194. *
  195. * @param port: selects the port can be GPIOA/B/C/D/E/F
  196. *
  197. * @param pin: selects the pin can be SYSCFG_PIN_(0..15)
  198. *
  199. * @retval None
  200. *
  201. * @note GPIOE only for APM32F072 and APM32F091
  202. */
  203. void SYSCFG_EINTLine(SYSCFG_PORT_T port, SYSCFG_PIN_T pin)
  204. {
  205. uint32_t status;
  206. status = (((uint32_t)0x0F) & port) << (0x04 * (pin & (uint8_t)0x03));
  207. if (pin <= 0x03)
  208. {
  209. SYSCFG->EINTCFG1 |= status;
  210. }
  211. else if ((0x04 <= pin) & (pin <= 0x07))
  212. {
  213. SYSCFG->EINTCFG2 |= status;
  214. }
  215. else if ((0x08 <= pin) & (pin <= 0x0B))
  216. {
  217. SYSCFG->EINTCFG3 |= status;
  218. }
  219. else if ((0x0C <= pin) & (pin <= 0x0F))
  220. {
  221. SYSCFG->EINTCFG4 |= status;
  222. }
  223. }
  224. /*!
  225. * @brief Selected parameter to the break input of TMR1.
  226. *
  227. * @param lock: selects the configuration to break
  228. * The parameter can be one of following values:
  229. * @arg SYSCFG_LOCK_LOCKUP: Cortex-M0 LOCKUP bit
  230. * @arg SYSCFG_LOCK_SRAM: SRAM parity lock bit
  231. * @arg SYSCFG_LOCK_PVD: PVD lock enable bit
  232. *
  233. * @retval None
  234. */
  235. void SYSCFG_BreakLock(uint32_t lock)
  236. {
  237. SYSCFG->CFG2_B.LOCK = 0;
  238. SYSCFG->CFG2_B.SRAMLOCK = 0;
  239. SYSCFG->CFG2_B.PVDLOCK = 0;
  240. if (lock == SYSCFG_LOCK_LOCKUP)
  241. {
  242. SYSCFG->CFG2_B.LOCK = BIT_SET;
  243. }
  244. if (lock == SYSCFG_LOCK_SRAM)
  245. {
  246. SYSCFG->CFG2_B.SRAMLOCK = BIT_SET;
  247. }
  248. if (lock == SYSCFG_LOCK_PVD)
  249. {
  250. SYSCFG->CFG2_B.PVDLOCK = BIT_SET;
  251. }
  252. }
  253. /*!
  254. * @brief Read the specified SYSCFG flag
  255. *
  256. * @param flag: SRAM Parity error flag
  257. * @arg SYSCFG_CFG2_SRAMPEF
  258. *
  259. * @retval None
  260. */
  261. uint8_t SYSCFG_ReadStatusFlag(uint32_t flag)
  262. {
  263. uint32_t status;
  264. status = (uint32_t)(SYSCFG->CFG2 & flag);
  265. if (status == flag)
  266. {
  267. return SET;
  268. }
  269. return RESET;
  270. }
  271. /*!
  272. * @brief Clear the specified SYSCFG flag
  273. *
  274. * @param flag: SRAM Parity error flag
  275. * @arg SYSCFG_CFG2_SRAMPEF
  276. *
  277. * @retval None
  278. */
  279. void SYSCFG_ClearStatusFlag(uint8_t flag)
  280. {
  281. SYSCFG->CFG2 |= (uint32_t) flag;
  282. }
  283. /**@} end of group SYSCFG_Functions*/
  284. /**@} end of group SYSCFG_Driver*/
  285. /**@} end of group APM32F0xx_StdPeriphDriver*/