ft32f0xx_syscfg.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_syscfg.c
  4. * @author FMD AE
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the SYSCFG peripheral:
  7. * + Remapping the memory mapped at 0x00000000
  8. * + Remapping the DMA channels
  9. * + Enabling I2C fast mode plus driving capability for I2C pins
  10. * + Configuring the EXTI lines connection to the GPIO port
  11. * + Configuring the CFGR2 features (Connecting some internal signal
  12. * to the break input of TIM1)
  13. * @version V1.0.0
  14. * @data 2021-07-01
  15. ******************************************************************************
  16. */
  17. /* Includes ------------------------------------------------------------------*/
  18. #include "ft32f0xx_syscfg.h"
  19. /**
  20. * @brief Deinitializes the SYSCFG registers to their default reset values.
  21. * @param None
  22. * @retval None
  23. * @note MEM_MODE bits are not affected by APB reset.
  24. * @note MEM_MODE bits took the value from the user option bytes.
  25. * @note CFGR2 register is not affected by APB reset.
  26. * @note CLABBB configuration bits are locked when set.
  27. * @note To unlock the configuration, perform a system reset.
  28. */
  29. void SYSCFG_DeInit(void)
  30. {
  31. /* Set SYSCFG_CFGR1 register to reset value without affecting MEM_MODE bits */
  32. SYSCFG->CFGR1 &= SYSCFG_CFGR1_MEM_MODE;
  33. /* Set EXTICRx registers to reset value */
  34. SYSCFG->EXTICR[0] = 0;
  35. SYSCFG->EXTICR[1] = 0;
  36. SYSCFG->EXTICR[2] = 0;
  37. SYSCFG->EXTICR[3] = 0;
  38. /* Set CFGR2 register to reset value: clear SRAM parity error flag */
  39. SYSCFG->CFGR2 |= 0;
  40. }
  41. /**
  42. * @brief Configures the memory mapping at address 0x00000000.
  43. * @param SYSCFG_MemoryRemap: selects the memory remapping.
  44. * This parameter can be one of the following values:
  45. * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000
  46. * @arg SYSCFG_MemoryRemap_SystemMemory: System Flash memory mapped at 0x00000000
  47. * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM mapped at 0x00000000
  48. * @retval None
  49. */
  50. void SYSCFG_MemoryRemapConfig(uint32_t SYSCFG_MemoryRemap)
  51. {
  52. uint32_t tmpctrl = 0;
  53. /* Check the parameter */
  54. assert_param(IS_SYSCFG_MEMORY_REMAP(SYSCFG_MemoryRemap));
  55. /* Get CFGR1 register value */
  56. tmpctrl = SYSCFG->CFGR1;
  57. /* Clear MEM_MODE bits */
  58. tmpctrl &= (uint32_t) (~SYSCFG_CFGR1_MEM_MODE);
  59. /* Set the new MEM_MODE bits value */
  60. tmpctrl |= (uint32_t) SYSCFG_MemoryRemap;
  61. /* Set CFGR1 register with the new memory remap configuration */
  62. SYSCFG->CFGR1 = tmpctrl;
  63. }
  64. /**
  65. * @brief Configure the DMA channels remapping.
  66. * @param SYSCFG_DMARemap: selects the DMA channels remap.
  67. * This parameter can be one of the following values:
  68. * @arg SYSCFG_DMARemap_TIM17: Remap TIM17 DMA requests from channel1 to channel2
  69. * @arg SYSCFG_DMARemap_TIM16: Remap TIM16 DMA requests from channel3 to channel4
  70. * @arg SYSCFG_DMARemap_USART1Rx: Remap USART1 Rx DMA requests from channel3 to channel5
  71. * @arg SYSCFG_DMARemap_USART1Tx: Remap USART1 Tx DMA requests from channel2 to channel4
  72. * @arg SYSCFG_DMARemap_ADC1: Remap ADC1 DMA requests from channel1 to channel2
  73. * @param NewState: new state of the DMA channel remapping.
  74. * This parameter can be: ENABLE or DISABLE.
  75. * @note When enabled, DMA channel of the selected peripheral is remapped
  76. * @note When disabled, Default DMA channel is mapped to the selected peripheral
  77. * @note By default TIM17 DMA requests is mapped to channel 1,
  78. * use SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Enable) to remap
  79. * TIM17 DMA requests to channel 2 and use
  80. * SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Disable) to map
  81. * TIM17 DMA requests to channel 1 (default mapping)
  82. * @retval None
  83. */
  84. void SYSCFG_DMAChannelRemapConfig(uint32_t SYSCFG_DMARemap, FunctionalState NewState)
  85. {
  86. /* Check the parameters */
  87. assert_param(IS_SYSCFG_DMA_REMAP(SYSCFG_DMARemap));
  88. assert_param(IS_FUNCTIONAL_STATE(NewState));
  89. if (NewState != DISABLE)
  90. {
  91. /* Remap the DMA channel */
  92. SYSCFG->CFGR1 |= (uint32_t)SYSCFG_DMARemap;
  93. }
  94. else
  95. {
  96. /* use the default DMA channel mapping */
  97. SYSCFG->CFGR1 &= (uint32_t)(~SYSCFG_DMARemap);
  98. }
  99. }
  100. /**
  101. * @brief Configure the I2C fast mode plus driving capability.
  102. * @param SYSCFG_I2CFastModePlus: selects the pin.
  103. * This parameter can be one of the following values:
  104. * @arg SYSCFG_I2CFastModePlus_PB6: Configure fast mode plus driving capability for PB6
  105. * @arg SYSCFG_I2CFastModePlus_PB7: Configure fast mode plus driving capability for PB7
  106. * @arg SYSCFG_I2CFastModePlus_PB8: Configure fast mode plus driving capability for PB8
  107. * @arg SYSCFG_I2CFastModePlus_PB9: Configure fast mode plus driving capability for PB9
  108. * @arg SYSCFG_I2CFastModePlus_PA9: Configure fast mode plus driving capability for PA9
  109. * @arg SYSCFG_I2CFastModePlus_PA10: Configure fast mode plus driving capability for PA10
  110. * @arg SYSCFG_I2CFastModePlus_I2C1: Configure fast mode plus driving capability for PB10, PB11, PF6 and PF7
  111. * @arg SYSCFG_I2CFastModePlus_I2C2: Configure fast mode plus driving capability for I2C2 pins
  112. *
  113. * @param NewState: new state of the DMA channel remapping.
  114. * This parameter can be: ENABLE or DISABLE.
  115. * @note ENABLE: Enable fast mode plus driving capability for selected I2C pin
  116. * @note DISABLE: Disable fast mode plus driving capability for selected I2C pin
  117. * @note For I2C1, fast mode plus driving capability can be enabled on all selected
  118. * I2C1 pins using SYSCFG_I2CFastModePlus_I2C1 parameter or independently
  119. * on each one of the following pins PB6, PB7, PB8 and PB9.
  120. * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
  121. * can be enabled only by using SYSCFG_I2CFastModePlus_I2C1 parameter.
  122. * @note For all I2C2 pins fast mode plus driving capability can be enabled
  123. * only by using SYSCFG_I2CFastModePlus_I2C2 parameter.
  124. * @retval None
  125. */
  126. void SYSCFG_I2CFastModePlusConfig(uint32_t SYSCFG_I2CFastModePlus, FunctionalState NewState)
  127. {
  128. /* Check the parameters */
  129. assert_param(IS_SYSCFG_I2C_FMP(SYSCFG_I2CFastModePlus));
  130. assert_param(IS_FUNCTIONAL_STATE(NewState));
  131. if (NewState != DISABLE)
  132. {
  133. /* Enable fast mode plus driving capability for selected pin */
  134. SYSCFG->CFGR1 |= (uint32_t)SYSCFG_I2CFastModePlus;
  135. }
  136. else
  137. {
  138. /* Disable fast mode plus driving capability for selected pin */
  139. SYSCFG->CFGR1 &= (uint32_t)(~SYSCFG_I2CFastModePlus);
  140. }
  141. }
  142. /** @brief select the modulation envelope source
  143. * @param SYSCFG_IRDAEnv: select the envelope source.
  144. * This parameter can be a value
  145. * @arg SYSCFG_IRDA_ENV_SEL_TIM16
  146. * @arg SYSCFG_IRDA_ENV_SEL_USART1
  147. * @arg SYSCFG_IRDA_ENV_SEL_USART2
  148. * @retval None
  149. */
  150. void SYSCFG_IRDAEnvSelection(uint32_t SYSCFG_IRDAEnv)
  151. {
  152. /* Check the parameters */
  153. assert_param(IS_SYSCFG_IRDA_ENV(SYSCFG_IRDAEnv));
  154. SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_IRDA_ENV_SEL);
  155. SYSCFG->CFGR1 |= (SYSCFG_IRDAEnv);
  156. }
  157. /**
  158. * @brief Selects the GPIO pin used as EXTI Line.
  159. * @param EXTI_PortSourceGPIOx: selects the GPIO port to be used as source
  160. * for EXTI lines where x can be (A, B, C, D, E or F).
  161. * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
  162. * @note This parameter can be EXTI_PinSourcex where x can be:
  163. * (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
  164. * @retval None
  165. */
  166. void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
  167. {
  168. uint32_t tmp = 0x00;
  169. /* Check the parameters */
  170. assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
  171. assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
  172. tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
  173. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
  174. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
  175. }
  176. /**
  177. * @brief Connect the selected parameter to the break input of TIM1.
  178. * @note The selected configuration is locked and can be unlocked by system reset
  179. * @param SYSCFG_Break: selects the configuration to be connected to break
  180. * input of TIM1
  181. * This parameter can be any combination of the following values:
  182. * @arg SYSCFG_Break_PVD: Connects the PVD event to the Break Input of TIM1
  183. * @arg SYSCFG_Break_SRAMParity: Connects the SRAM_PARITY error signal to the Break Input of TIM1 .
  184. * @arg SYSCFG_Break_Lockup: Connects Lockup output of CortexM0 to the break input of TIM1.
  185. * @retval None
  186. */
  187. void SYSCFG_BreakConfig(uint32_t SYSCFG_Break)
  188. {
  189. /* Check the parameter */
  190. assert_param(IS_SYSCFG_LOCK_CONFIG(SYSCFG_Break));
  191. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_Break;
  192. }
  193. /**
  194. * @}
  195. */
  196. /**
  197. * @}
  198. */
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. /************************ (C) COPYRIGHT FMD *****END OF FILE****/