gd32f3x0_syscfg.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*!
  2. \file gd32f3x0_syscfg.c
  3. \brief SYSCFG driver
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-06-06, V1.0.0, firmware for GD32F3x0
  8. */
  9. #include "gd32f3x0_syscfg.h"
  10. /*!
  11. \brief reset the SYSCFG registers
  12. \param[in] none
  13. \param[out] none
  14. \retval none
  15. */
  16. void syscfg_deinit(void)
  17. {
  18. rcu_periph_reset_enable(RCU_CFGCMPRST);
  19. rcu_periph_reset_disable(RCU_CFGCMPRST);
  20. }
  21. /*!
  22. \brief enable the DMA channels remapping
  23. \param[in] syscfg_dma_remap: specify the DMA channels to remap
  24. \arg SYSCFG_DMA_REMAP_TIMER16: remap TIMER16 channel0 and UP DMA requests to channel1(defaut channel0)
  25. \arg SYSCFG_DMA_REMAP_TIMER15: remap TIMER15 channel2 and UP DMA requests to channel3(defaut channel2)
  26. \arg SYSCFG_DMA_REMAP_USART0RX: remap USART0 Rx DMA request to channel4(default channel2)
  27. \arg SYSCFG_DMA_REMAP_USART0TX: remap USART0 Tx DMA request to channel3(default channel1)
  28. \arg SYSCFG_DMA_REMAP_ADC: remap ADC DMA requests from channel0 to channel1
  29. \param[out] none
  30. \retval none
  31. */
  32. void syscfg_dma_remap_enable(uint32_t syscfg_dma_remap)
  33. {
  34. SYSCFG_CFG0 |= syscfg_dma_remap;
  35. }
  36. /*!
  37. \brief disable the DMA channels remapping
  38. \param[in] syscfg_dma_remap: specify the DMA channels to remap
  39. \arg SYSCFG_DMA_REMAP_TIMER16: remap TIMER16 channel0 and UP DMA requests to channel1(defaut channel0)
  40. \arg SYSCFG_DMA_REMAP_TIMER15: remap TIMER15 channel2 and UP DMA requests to channel3(defaut channel2)
  41. \arg SYSCFG_DMA_REMAP_USART0RX: remap USART0 Rx DMA request to channel4(default channel2)
  42. \arg SYSCFG_DMA_REMAP_USART0TX: remap USART0 Tx DMA request to channel3(default channel1)
  43. \arg SYSCFG_DMA_REMAP_ADC: remap ADC DMA requests from channel0 to channel1
  44. \param[out] none
  45. \retval none
  46. */
  47. void syscfg_dma_remap_disable(uint32_t syscfg_dma_remap)
  48. {
  49. SYSCFG_CFG0 &= ~syscfg_dma_remap;
  50. }
  51. /*!
  52. \brief enable PB9 high current capability
  53. \param[in] none
  54. \param[out] none
  55. \retval none
  56. */
  57. void syscfg_high_current_enable(void)
  58. {
  59. SYSCFG_CFG0 |= SYSCFG_HIGH_CURRENT_ENABLE;
  60. }
  61. /*!
  62. \brief disable PB9 high current capability
  63. \param[in] none
  64. \param[out] none
  65. \retval none
  66. */
  67. void syscfg_high_current_disable(void)
  68. {
  69. SYSCFG_CFG0 &= SYSCFG_HIGH_CURRENT_DISABLE;
  70. }
  71. /*!
  72. \brief configure the GPIO pin as EXTI Line
  73. \param[in] exti_port: specify the GPIO port used in EXTI
  74. \arg EXTI_SOURCE_GPIOx(x = A,B,C,D,F): EXTI GPIO port
  75. \param[in] exti_pin: specify the EXTI line
  76. \arg EXTI_SOURCE_PINx(x = 0..15): EXTI GPIO pin
  77. \param[out] none
  78. \retval none
  79. */
  80. void syscfg_exti_line_config(uint8_t exti_port, uint8_t exti_pin)
  81. {
  82. uint32_t clear_exti_mask = ~((uint32_t)EXTI_SS_MASK << (EXTI_SS_MSTEP(exti_pin)));
  83. uint32_t config_exti_mask = ((uint32_t)exti_port) << (EXTI_SS_MSTEP(exti_pin));
  84. switch(exti_pin / EXTI_SS_JSTEP){
  85. case EXTISS0:
  86. /* clear EXTI source line(0..3) */
  87. SYSCFG_EXTISS0 &= clear_exti_mask;
  88. /* configure EXTI soure line(0..3) */
  89. SYSCFG_EXTISS0 |= config_exti_mask;
  90. break;
  91. case EXTISS1:
  92. /* clear EXTI soure line(4..7) */
  93. SYSCFG_EXTISS1 &= clear_exti_mask;
  94. /* configure EXTI soure line(4..7) */
  95. SYSCFG_EXTISS1 |= config_exti_mask;
  96. break;
  97. case EXTISS2:
  98. /* clear EXTI soure line(8..11) */
  99. SYSCFG_EXTISS2 &= clear_exti_mask;
  100. /* configure EXTI soure line(8..11) */
  101. SYSCFG_EXTISS2 |= config_exti_mask;
  102. break;
  103. case EXTISS3:
  104. /* clear EXTI soure line(12..15) */
  105. SYSCFG_EXTISS3 &= clear_exti_mask;
  106. /* configure EXTI soure line(12..15) */
  107. SYSCFG_EXTISS3 |= config_exti_mask;
  108. break;
  109. default:
  110. break;
  111. }
  112. }
  113. /*!
  114. \brief connect TIMER0/14/15/16 break input to the selected parameter
  115. \param[in] syscfg_lock: Specify the parameter to be connected
  116. \arg SYSCFG_LOCK_LOCKUP: Cortex-M4 lockup output connected to the break input
  117. \arg SYSCFG_LOCK_SRAM_PARITY_ERROR: SRAM_PARITY check error connected to the break input
  118. \arg SYSCFG_LOCK_LVD: LVD interrupt connected to the break input
  119. \param[out] none
  120. \retval none
  121. */
  122. void syscfg_lock_config(uint32_t syscfg_lock)
  123. {
  124. SYSCFG_CFG2 |= syscfg_lock;
  125. }
  126. /*!
  127. \brief check if the specified flag in SYSCFG_CFG2 is set or not.
  128. \param[in] syscfg_flag: specify the flag in SYSCFG_CFG2 to check.
  129. \arg SYSCFG_SRAM_PCEF: SRAM parity check error flag.
  130. \param[out] none
  131. \retval the syscfg_flag state returned (SET or RESET).
  132. */
  133. FlagStatus syscfg_flag_get(uint32_t syscfg_flag)
  134. {
  135. if((SYSCFG_CFG2 & syscfg_flag) != (uint32_t)RESET){
  136. return SET;
  137. }else{
  138. return RESET;
  139. }
  140. }
  141. /*!
  142. \brief clear the flag in SYSCFG_CFG2 by writing 1.
  143. \param[in] syscfg_flag: Specify the flag in SYSCFG_CFG2 to clear.
  144. \arg SYSCFG_SRAM_PCEF: SRAM parity check error flag.
  145. \param[out] none
  146. \retval none
  147. */
  148. void syscfg_flag_clear(uint32_t syscfg_flag)
  149. {
  150. SYSCFG_CFG2 |= (uint32_t) syscfg_flag;
  151. }
  152. /*!
  153. \brief configure the I/O compensation cell
  154. \param[in] syscfg_compensation: specifies the I/O compensation cell mode
  155. \arg SYSCFG_COMPENSATION_ENABLE: I/O compensation cell is enabled
  156. \arg SYSCFG_COMPENSATION_DISABLE: I/O compensation cell is disabled
  157. \param[out] none
  158. \retval none
  159. */
  160. void syscfg_compensation_config(uint32_t syscfg_compensation)
  161. {
  162. uint32_t reg;
  163. reg = SYSCFG_CPSCTL;
  164. /* reset the SYSCFG_CPSCTL_CPS_EN bit and set according to syscfg_compensation */
  165. reg &= ~SYSCFG_CPSCTL_CPS_EN;
  166. SYSCFG_CPSCTL = (reg | syscfg_compensation);
  167. }
  168. /*!
  169. \brief check if the I/O compensation cell ready flag is set or not
  170. \param[in] none
  171. \param[out] none
  172. \retval FlagStatus: SET or RESET
  173. */
  174. FlagStatus syscfg_cps_rdy_flag_get(void)
  175. {
  176. if(((uint32_t)RESET) != (SYSCFG_CPSCTL & SYSCFG_CPSCTL_CPS_RDY)){
  177. return SET;
  178. }else{
  179. return RESET;
  180. }
  181. }