gd32e23x_syscfg.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*!
  2. \file gd32e23x_syscfg.c
  3. \brief SYSCFG driver
  4. \version 2019-02-19, V1.0.0, firmware for GD32E23x
  5. \version 2020-12-12, V1.1.0, firmware for GD32E23x
  6. */
  7. /*
  8. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holder nor the names of its contributors
  17. may be used to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. OF SUCH DAMAGE.
  29. */
  30. #include "gd32e23x_syscfg.h"
  31. /*!
  32. \brief reset the SYSCFG registers
  33. \param[in] none
  34. \param[out] none
  35. \retval none
  36. */
  37. void syscfg_deinit(void)
  38. {
  39. rcu_periph_reset_enable(RCU_CFGCMPRST);
  40. rcu_periph_reset_disable(RCU_CFGCMPRST);
  41. }
  42. /*!
  43. \brief enable the DMA channels remapping
  44. \param[in] syscfg_dma_remap: specify the DMA channels to remap
  45. \arg SYSCFG_DMA_REMAP_TIMER16: remap TIMER16 channel0 and UP DMA requests to channel1(defaut channel0)
  46. \arg SYSCFG_DMA_REMAP_TIMER15: remap TIMER15 channel2 and UP DMA requests to channel3(defaut channel2)
  47. \arg SYSCFG_DMA_REMAP_USART0RX: remap USART0 Rx DMA request to channel4(default channel2)
  48. \arg SYSCFG_DMA_REMAP_USART0TX: remap USART0 Tx DMA request to channel3(default channel1)
  49. \arg SYSCFG_DMA_REMAP_ADC: remap ADC DMA requests from channel0 to channel1
  50. \arg SYSCFG_PA11_REMAP_PA12: remap PA11 PA12
  51. \param[out] none
  52. \retval none
  53. */
  54. void syscfg_dma_remap_enable(uint32_t syscfg_dma_remap)
  55. {
  56. SYSCFG_CFG0 |= syscfg_dma_remap;
  57. }
  58. /*!
  59. \brief disable the DMA channels remapping
  60. \param[in] syscfg_dma_remap: specify the DMA channels to remap
  61. \arg SYSCFG_DMA_REMAP_TIMER16: remap TIMER16 channel0 and UP DMA requests to channel1(defaut channel0)
  62. \arg SYSCFG_DMA_REMAP_TIMER15: remap TIMER15 channel2 and UP DMA requests to channel3(defaut channel2)
  63. \arg SYSCFG_DMA_REMAP_USART0RX: remap USART0 Rx DMA request to channel4(default channel2)
  64. \arg SYSCFG_DMA_REMAP_USART0TX: remap USART0 Tx DMA request to channel3(default channel1)
  65. \arg SYSCFG_DMA_REMAP_ADC: remap ADC DMA requests from channel0 to channel1
  66. \arg SYSCFG_PA11_REMAP_PA12: remap PA11 PA12
  67. \param[out] none
  68. \retval none
  69. */
  70. void syscfg_dma_remap_disable(uint32_t syscfg_dma_remap)
  71. {
  72. SYSCFG_CFG0 &= ~syscfg_dma_remap;
  73. }
  74. #if defined(GD32E230)
  75. /*!
  76. \brief enable PB9 high current capability
  77. \param[in] none
  78. \param[out] none
  79. \retval none
  80. */
  81. void syscfg_high_current_enable(void)
  82. {
  83. SYSCFG_CFG0 |= SYSCFG_HIGH_CURRENT_ENABLE;
  84. }
  85. /*!
  86. \brief disable PB9 high current capability
  87. \param[in] none
  88. \param[out] none
  89. \retval none
  90. */
  91. void syscfg_high_current_disable(void)
  92. {
  93. SYSCFG_CFG0 &= SYSCFG_HIGH_CURRENT_DISABLE;
  94. }
  95. #endif
  96. /*!
  97. \brief configure the GPIO pin as EXTI Line
  98. \param[in] exti_port: specify the GPIO port used in EXTI
  99. \arg EXTI_SOURCE_GPIOx(x = A,B,C,F): EXTI GPIO port
  100. \param[in] exti_pin: specify the EXTI line
  101. \arg EXTI_SOURCE_PINx(GPIOA x = 0..15,GPIOB x = 0..15,GPIOC x = 13..15,GPIOF x = 0.1.6.7): EXTI GPIO pin
  102. \param[out] none
  103. \retval none
  104. */
  105. void syscfg_exti_line_config(uint8_t exti_port, uint8_t exti_pin)
  106. {
  107. uint32_t clear_exti_mask = ~((uint32_t)EXTI_SS_MASK << (EXTI_SS_MSTEP(exti_pin)));
  108. uint32_t config_exti_mask = ((uint32_t)exti_port) << (EXTI_SS_MSTEP(exti_pin));
  109. switch(exti_pin / EXTI_SS_JSTEP){
  110. case EXTISS0:
  111. /* clear EXTI source line(0..3) */
  112. SYSCFG_EXTISS0 &= clear_exti_mask;
  113. /* configure EXTI soure line(0..3) */
  114. SYSCFG_EXTISS0 |= config_exti_mask;
  115. break;
  116. case EXTISS1:
  117. /* clear EXTI soure line(4..7) */
  118. SYSCFG_EXTISS1 &= clear_exti_mask;
  119. /* configure EXTI soure line(4..7) */
  120. SYSCFG_EXTISS1 |= config_exti_mask;
  121. break;
  122. case EXTISS2:
  123. /* clear EXTI soure line(8..11) */
  124. SYSCFG_EXTISS2 &= clear_exti_mask;
  125. /* configure EXTI soure line(8..11) */
  126. SYSCFG_EXTISS2 |= config_exti_mask;
  127. break;
  128. case EXTISS3:
  129. /* clear EXTI soure line(12..15) */
  130. SYSCFG_EXTISS3 &= clear_exti_mask;
  131. /* configure EXTI soure line(12..15) */
  132. SYSCFG_EXTISS3 |= config_exti_mask;
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. /*!
  139. \brief connect TIMER0/14/15/16 break input to the selected parameter
  140. \param[in] syscfg_lock: Specify the parameter to be connected
  141. \arg SYSCFG_LOCK_LOCKUP: Cortex-M23 lockup output connected to the break input
  142. \arg SYSCFG_LOCK_SRAM_PARITY_ERROR: SRAM_PARITY check error connected to the break input
  143. \arg SYSCFG_LOCK_LVD: LVD interrupt connected to the break input
  144. \param[out] none
  145. \retval none
  146. */
  147. void syscfg_lock_config(uint32_t syscfg_lock)
  148. {
  149. SYSCFG_CFG2 |= syscfg_lock;
  150. }
  151. /*!
  152. \brief set the wait state counter value
  153. \param[in] irq_latency: IRQ_LATENCY value (0x00 - 0xFF)
  154. \param[out] none
  155. \retval none
  156. */
  157. void irq_latency_set(uint8_t irq_latency)
  158. {
  159. uint32_t reg;
  160. reg = SYSCFG_CPU_IRQ_LAT &(~(uint32_t)SYSCFG_CPU_IRQ_LAT_IRQ_LATENCY);
  161. reg |= (uint32_t)(IRQ_LATENCY(irq_latency));
  162. SYSCFG_CPU_IRQ_LAT = (uint32_t)reg;
  163. }
  164. /*!
  165. \brief check if the specified flag in SYSCFG_CFG2 is set or not.
  166. \param[in] syscfg_flag: specify the flag in SYSCFG_CFG2 to check.
  167. \arg SYSCFG_SRAM_PCEF: SRAM parity check error flag.
  168. \param[out] none
  169. \retval the syscfg_flag state returned (SET or RESET).
  170. */
  171. FlagStatus syscfg_flag_get(uint32_t syscfg_flag)
  172. {
  173. if((SYSCFG_CFG2 & syscfg_flag) != (uint32_t)RESET){
  174. return SET;
  175. }else{
  176. return RESET;
  177. }
  178. }
  179. /*!
  180. \brief clear the flag in SYSCFG_CFG2 by writing 1.
  181. \param[in] syscfg_flag: Specify the flag in SYSCFG_CFG2 to clear.
  182. \arg SYSCFG_SRAM_PCEF: SRAM parity check error flag.
  183. \param[out] none
  184. \retval none
  185. */
  186. void syscfg_flag_clear(uint32_t syscfg_flag)
  187. {
  188. SYSCFG_CFG2 |= (uint32_t) syscfg_flag;
  189. }