stm32f0xx_syscfg.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_syscfg.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the SYSCFG peripheral:
  9. * + Remapping the memory mapped at 0x00000000
  10. * + Remapping the DMA channels
  11. * + Enabling I2C fast mode plus driving capability for I2C pins
  12. * + Configuring the EXTI lines connection to the GPIO port
  13. * + Configuring the CFGR2 features (Connecting some internal signal
  14. * to the break input of TIM1)
  15. *
  16. * @verbatim
  17. ===============================================================================
  18. ##### How to use this driver #####
  19. ===============================================================================
  20. [..]
  21. The SYSCFG registers can be accessed only when the SYSCFG
  22. interface APB clock is enabled.
  23. To enable SYSCFG APB clock use:
  24. RCC_APBPeriphClockCmd(RCC_APBPeriph_SYSCFG, ENABLE).
  25. * @endverbatim
  26. *
  27. ******************************************************************************
  28. * @attention
  29. *
  30. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  31. *
  32. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  33. * You may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at:
  35. *
  36. * http://www.st.com/software_license_agreement_liberty_v2
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. *
  44. ******************************************************************************
  45. */
  46. /* Includes ------------------------------------------------------------------*/
  47. #include "stm32f0xx_syscfg.h"
  48. /** @addtogroup STM32F0xx_StdPeriph_Driver
  49. * @{
  50. */
  51. /** @defgroup SYSCFG
  52. * @brief SYSCFG driver modules
  53. * @{
  54. */
  55. /* Private typedef -----------------------------------------------------------*/
  56. /* Private define ------------------------------------------------------------*/
  57. /* Private macro -------------------------------------------------------------*/
  58. /* Private variables ---------------------------------------------------------*/
  59. /* Private function prototypes -----------------------------------------------*/
  60. /* Private functions ---------------------------------------------------------*/
  61. /** @defgroup SYSCFG_Private_Functions
  62. * @{
  63. */
  64. /** @defgroup SYSCFG_Group1 SYSCFG Initialization and Configuration functions
  65. * @brief SYSCFG Initialization and Configuration functions
  66. *
  67. @verbatim
  68. ===============================================================================
  69. ##### SYSCFG Initialization and Configuration functions #####
  70. ===============================================================================
  71. @endverbatim
  72. * @{
  73. */
  74. /**
  75. * @brief Deinitializes the SYSCFG registers to their default reset values.
  76. * @param None
  77. * @retval None
  78. * @note MEM_MODE bits are not affected by APB reset.
  79. * MEM_MODE bits took the value from the user option bytes.
  80. * @note CFGR2 register is not affected by APB reset.
  81. * CLABBB configuration bits are locked when set.
  82. * To unlock the configuration, perform a system reset.
  83. */
  84. void SYSCFG_DeInit(void)
  85. {
  86. /* Set SYSCFG_CFGR1 register to reset value without affecting MEM_MODE bits */
  87. SYSCFG->CFGR1 &= SYSCFG_CFGR1_MEM_MODE;
  88. /* Set EXTICRx registers to reset value */
  89. SYSCFG->EXTICR[0] = 0;
  90. SYSCFG->EXTICR[1] = 0;
  91. SYSCFG->EXTICR[2] = 0;
  92. SYSCFG->EXTICR[3] = 0;
  93. /* Set CFGR2 register to reset value: clear SRAM parity error flag */
  94. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_CFGR2_SRAM_PE;
  95. }
  96. /**
  97. * @brief Configures the memory mapping at address 0x00000000.
  98. * @param SYSCFG_MemoryRemap: selects the memory remapping.
  99. * This parameter can be one of the following values:
  100. * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000
  101. * @arg SYSCFG_MemoryRemap_SystemMemory: System Flash memory mapped at 0x00000000
  102. * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM mapped at 0x00000000
  103. * @retval None
  104. */
  105. void SYSCFG_MemoryRemapConfig(uint32_t SYSCFG_MemoryRemap)
  106. {
  107. uint32_t tmpctrl = 0;
  108. /* Check the parameter */
  109. assert_param(IS_SYSCFG_MEMORY_REMAP(SYSCFG_MemoryRemap));
  110. /* Get CFGR1 register value */
  111. tmpctrl = SYSCFG->CFGR1;
  112. /* Clear MEM_MODE bits */
  113. tmpctrl &= (uint32_t) (~SYSCFG_CFGR1_MEM_MODE);
  114. /* Set the new MEM_MODE bits value */
  115. tmpctrl |= (uint32_t) SYSCFG_MemoryRemap;
  116. /* Set CFGR1 register with the new memory remap configuration */
  117. SYSCFG->CFGR1 = tmpctrl;
  118. }
  119. /**
  120. * @brief Configure the DMA channels remapping.
  121. * @param SYSCFG_DMARemap: selects the DMA channels remap.
  122. * This parameter can be one of the following values:
  123. * @arg SYSCFG_DMARemap_TIM17: Remap TIM17 DMA requests from channel1 to channel2
  124. * @arg SYSCFG_DMARemap_TIM16: Remap TIM16 DMA requests from channel3 to channel4
  125. * @arg SYSCFG_DMARemap_USART1Rx: Remap USART1 Rx DMA requests from channel3 to channel5
  126. * @arg SYSCFG_DMARemap_USART1Tx: Remap USART1 Tx DMA requests from channel2 to channel4
  127. * @arg SYSCFG_DMARemap_ADC1: Remap ADC1 DMA requests from channel1 to channel2
  128. * @param NewState: new state of the DMA channel remapping.
  129. * This parameter can be: ENABLE or DISABLE.
  130. * @note When enabled, DMA channel of the selected peripheral is remapped
  131. * @note When disabled, Default DMA channel is mapped to the selected peripheral
  132. * @note
  133. * By default TIM17 DMA requests is mapped to channel 1
  134. * use SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Enable)
  135. * to remap TIM17 DMA requests to channel 2
  136. * use SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Disable)
  137. * to map TIM17 DMA requests to channel 1 (default mapping)
  138. * @retval None
  139. */
  140. void SYSCFG_DMAChannelRemapConfig(uint32_t SYSCFG_DMARemap, FunctionalState NewState)
  141. {
  142. /* Check the parameters */
  143. assert_param(IS_SYSCFG_DMA_REMAP(SYSCFG_DMARemap));
  144. assert_param(IS_FUNCTIONAL_STATE(NewState));
  145. if (NewState != DISABLE)
  146. {
  147. /* Remap the DMA channel */
  148. SYSCFG->CFGR1 |= (uint32_t)SYSCFG_DMARemap;
  149. }
  150. else
  151. {
  152. /* use the default DMA channel mapping */
  153. SYSCFG->CFGR1 &= (uint32_t)(~SYSCFG_DMARemap);
  154. }
  155. }
  156. /**
  157. * @brief Configure the I2C fast mode plus driving capability.
  158. * @param SYSCFG_I2CFastModePlus: selects the pin.
  159. * This parameter can be one of the following values:
  160. * @arg SYSCFG_I2CFastModePlus_PB6: Configure fast mode plus driving capability for PB6
  161. * @arg SYSCFG_I2CFastModePlus_PB7: Configure fast mode plus driving capability for PB7
  162. * @arg SYSCFG_I2CFastModePlus_PB8: Configure fast mode plus driving capability for PB8
  163. * @arg SYSCFG_I2CFastModePlus_PB9: Configure fast mode plus driving capability for PB9
  164. * @param NewState: new state of the DMA channel remapping.
  165. * This parameter can be: ENABLE or DISABLE.
  166. * @note ENABLE: Enable fast mode plus driving capability for selected pin
  167. * @note DISABLE: Disable fast mode plus driving capability for selected pin
  168. * @retval None
  169. */
  170. void SYSCFG_I2CFastModePlusConfig(uint32_t SYSCFG_I2CFastModePlus, FunctionalState NewState)
  171. {
  172. /* Check the parameters */
  173. assert_param(IS_SYSCFG_I2C_FMP(SYSCFG_I2CFastModePlus));
  174. assert_param(IS_FUNCTIONAL_STATE(NewState));
  175. if (NewState != DISABLE)
  176. {
  177. /* Enable fast mode plus driving capability for selected pin */
  178. SYSCFG->CFGR1 |= (uint32_t)SYSCFG_I2CFastModePlus;
  179. }
  180. else
  181. {
  182. /* Disable fast mode plus driving capability for selected pin */
  183. SYSCFG->CFGR1 &= (uint32_t)(~SYSCFG_I2CFastModePlus);
  184. }
  185. }
  186. /**
  187. * @brief Selects the GPIO pin used as EXTI Line.
  188. * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source
  189. * for EXTI lines where x can be (A, B, C, D or F).
  190. * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
  191. * This parameter can be EXTI_PinSourcex where x can be (0..15)
  192. * @retval None
  193. */
  194. void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
  195. {
  196. uint32_t tmp = 0x00;
  197. /* Check the parameters */
  198. assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
  199. assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
  200. tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
  201. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
  202. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
  203. }
  204. /**
  205. * @brief Connect the selected parameter to the break input of TIM1.
  206. * @note The selected configuration is locked and can be unlocked by system reset
  207. * @param SYSCFG_Break: selects the configuration to be connected to break
  208. * input of TIM1
  209. * This parameter can be any combination of the following values:
  210. * @arg SYSCFG_Break_PVD: Connects the PVD event to the Break Input of TIM1.
  211. * @arg SYSCFG_Break_SRAMParity: Connects the SRAM_PARITY error signal to the Break Input of TIM1 .
  212. * @arg SYSCFG_Break_Lockup: Connects Lockup output of CortexM0 to the break input of TIM1.
  213. * @retval None
  214. */
  215. void SYSCFG_BreakConfig(uint32_t SYSCFG_Break)
  216. {
  217. /* Check the parameter */
  218. assert_param(IS_SYSCFG_LOCK_CONFIG(SYSCFG_Break));
  219. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_Break;
  220. }
  221. /**
  222. * @brief Checks whether the specified SYSCFG flag is set or not.
  223. * @param SYSCFG_Flag: specifies the SYSCFG flag to check.
  224. * This parameter can be one of the following values:
  225. * @arg SYSCFG_FLAG_PE: SRAM parity error flag.
  226. * @retval The new state of SYSCFG_Flag (SET or RESET).
  227. */
  228. FlagStatus SYSCFG_GetFlagStatus(uint32_t SYSCFG_Flag)
  229. {
  230. FlagStatus bitstatus = RESET;
  231. /* Check the parameter */
  232. assert_param(IS_SYSCFG_FLAG(SYSCFG_Flag));
  233. /* Check the status of the specified SPI flag */
  234. if ((SYSCFG->CFGR2 & SYSCFG_CFGR2_SRAM_PE) != (uint32_t)RESET)
  235. {
  236. /* SYSCFG_Flag is set */
  237. bitstatus = SET;
  238. }
  239. else
  240. {
  241. /* SYSCFG_Flag is reset */
  242. bitstatus = RESET;
  243. }
  244. /* Return the SYSCFG_Flag status */
  245. return bitstatus;
  246. }
  247. /**
  248. * @brief Clear the selected SYSCFG flag.
  249. * @param SYSCFG_Flag: selects the flag to be cleared.
  250. * This parameter can be any combination of the following values:
  251. * @arg SYSCFG_FLAG_PE: SRAM parity error flag.
  252. * @retval None
  253. */
  254. void SYSCFG_ClearFlag(uint32_t SYSCFG_Flag)
  255. {
  256. /* Check the parameter */
  257. assert_param(IS_SYSCFG_FLAG(SYSCFG_Flag));
  258. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_Flag;
  259. }
  260. /**
  261. * @}
  262. */
  263. /**
  264. * @}
  265. */
  266. /**
  267. * @}
  268. */
  269. /**
  270. * @}
  271. */
  272. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/