stm32f0xx_syscfg.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_syscfg.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  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 2014 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. * @note MEM_MODE bits took the value from the user option bytes.
  80. * @note CFGR2 register is not affected by APB reset.
  81. * @note CLABBB configuration bits are locked when set.
  82. * @note 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 By default TIM17 DMA requests is mapped to channel 1,
  133. * use SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Enable) to remap
  134. * TIM17 DMA requests to channel 2 and use
  135. * SYSCFG_DMAChannelRemapConfig(SYSCFG_DMARemap_TIM17, Disable) to map
  136. * TIM17 DMA requests to channel 1 (default mapping)
  137. * @note This function is only used for STM32F030, STM32F031, STM32F042, STM32F072 and STM32F051 devices.
  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. * @arg SYSCFG_I2CFastModePlus_PA9: Configure fast mode plus driving capability for PA9 (only for STM32F031 and STM32F030 devices)
  165. * @arg SYSCFG_I2CFastModePlus_PA10: Configure fast mode plus driving capability for PA10 (only for STM32F031 and STM32F030 devices)
  166. * @arg SYSCFG_I2CFastModePlus_I2C1: Configure fast mode plus driving capability for PB10, PB11, PF6 and PF7(only for STM32F031 and STM32F030 devices)
  167. * @arg SYSCFG_I2CFastModePlus_I2C2: Configure fast mode plus driving capability for I2C2 pins, available only for STM32F072 devices
  168. *
  169. * @param NewState: new state of the DMA channel remapping.
  170. * This parameter can be: ENABLE or DISABLE.
  171. * @note ENABLE: Enable fast mode plus driving capability for selected I2C pin
  172. * @note DISABLE: Disable fast mode plus driving capability for selected I2C pin
  173. * @note For I2C1, fast mode plus driving capability can be enabled on all selected
  174. * I2C1 pins using SYSCFG_I2CFastModePlus_I2C1 parameter or independently
  175. * on each one of the following pins PB6, PB7, PB8 and PB9.
  176. * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability
  177. * can be enabled only by using SYSCFG_I2CFastModePlus_I2C1 parameter.
  178. * @note For all I2C2 pins fast mode plus driving capability can be enabled
  179. * only by using SYSCFG_I2CFastModePlus_I2C2 parameter.
  180. * @retval None
  181. */
  182. void SYSCFG_I2CFastModePlusConfig(uint32_t SYSCFG_I2CFastModePlus, FunctionalState NewState)
  183. {
  184. /* Check the parameters */
  185. assert_param(IS_SYSCFG_I2C_FMP(SYSCFG_I2CFastModePlus));
  186. assert_param(IS_FUNCTIONAL_STATE(NewState));
  187. if (NewState != DISABLE)
  188. {
  189. /* Enable fast mode plus driving capability for selected pin */
  190. SYSCFG->CFGR1 |= (uint32_t)SYSCFG_I2CFastModePlus;
  191. }
  192. else
  193. {
  194. /* Disable fast mode plus driving capability for selected pin */
  195. SYSCFG->CFGR1 &= (uint32_t)(~SYSCFG_I2CFastModePlus);
  196. }
  197. }
  198. /** @brief select the modulation envelope source
  199. * @param SYSCFG_IRDAEnv: select the envelope source.
  200. * This parameter can be a value
  201. * @arg SYSCFG_IRDA_ENV_SEL_TIM16
  202. * @arg SYSCFG_IRDA_ENV_SEL_USART1
  203. * @arg SYSCFG_IRDA_ENV_SEL_USART4
  204. * @retval None
  205. */
  206. void SYSCFG_IRDAEnvSelection(uint32_t SYSCFG_IRDAEnv)
  207. {
  208. /* Check the parameters */
  209. assert_param(IS_SYSCFG_IRDA_ENV(SYSCFG_IRDAEnv));
  210. SYSCFG->CFGR1 &= ~(SYSCFG_CFGR1_IRDA_ENV_SEL);
  211. SYSCFG->CFGR1 |= (SYSCFG_IRDAEnv);
  212. }
  213. /**
  214. * @brief Selects the GPIO pin used as EXTI Line.
  215. * @param EXTI_PortSourceGPIOx: selects the GPIO port to be used as source
  216. * for EXTI lines where x can be (A, B, C, D, E or F).
  217. * @note GPIOE is available only for STM32F072.
  218. * @note GPIOD is not available for STM32F031.
  219. * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
  220. * @note This parameter can be EXTI_PinSourcex where x can be:
  221. * For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
  222. * For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
  223. * For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF.
  224. * @retval None
  225. */
  226. void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
  227. {
  228. uint32_t tmp = 0x00;
  229. /* Check the parameters */
  230. assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
  231. assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
  232. tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
  233. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
  234. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
  235. }
  236. /**
  237. * @brief check ISR wrapper: Allow to determine interrupt source per line .
  238. * @param IT_Source: specifies the interrupt source to check.
  239. * This parameter can be one of the following values:
  240. * @arg ITLINE_EWDG EWDG has expired
  241. * @arg ITLINE_PVDOUT Power voltage detection Interrupt
  242. * @arg ITLINE_VDDIO2 VDDIO2 Interrupt
  243. * @arg ITLINE_RTC_WAKEUP RTC WAKEUP -> exti[20] Interrupt
  244. * @arg ITLINE_RTC_TSTAMP RTC Time Stamp -> exti[19] interrupt
  245. * @arg ITLINE_RTC_ALRA RTC Alarm -> exti[17] interrupt
  246. * @arg ITLINE_FLASH_ITF Flash ITF Interrupt
  247. * @arg ITLINE_CRS CRS Interrupt
  248. * @arg ITLINE_CLK_CTRL CLK Control Interrupt
  249. * @arg ITLINE_EXTI0 External Interrupt 0
  250. * @arg ITLINE_EXTI1 External Interrupt 1
  251. * @arg ITLINE_EXTI2 External Interrupt 2
  252. * @arg ITLINE_EXTI3 External Interrupt 3
  253. * @arg ITLINE_EXTI4 External Interrupt 4
  254. * @arg ITLINE_EXTI5 External Interrupt 5
  255. * @arg ITLINE_EXTI6 External Interrupt 6
  256. * @arg ITLINE_EXTI7 External Interrupt 7
  257. * @arg ITLINE_EXTI8 External Interrupt 8
  258. * @arg ITLINE_EXTI9 External Interrupt 9
  259. * @arg ITLINE_EXTI10 External Interrupt 10
  260. * @arg ITLINE_EXTI11 External Interrupt 11
  261. * @arg ITLINE_EXTI12 External Interrupt 12
  262. * @arg ITLINE_EXTI13 External Interrupt 13
  263. * @arg ITLINE_EXTI14 External Interrupt 14
  264. * @arg ITLINE_EXTI15 External Interrupt 15
  265. * @arg ITLINE_TSC_EOA Touch control EOA Interrupt
  266. * @arg ITLINE_TSC_MCE Touch control MCE Interrupt
  267. * @arg ITLINE_DMA1_CH1 DMA1 Channel 1 Interrupt
  268. * @arg ITLINE_DMA1_CH2 DMA1 Channel 2 Interrupt
  269. * @arg ITLINE_DMA1_CH3 DMA1 Channel 3 Interrupt
  270. * @arg ITLINE_DMA2_CH1 DMA2 Channel 1 Interrupt
  271. * @arg ITLINE_DMA2_CH2 DMA2 Channel 2 Interrupt
  272. * @arg ITLINE_DMA1_CH4 DMA1 Channel 4 Interrupt
  273. * @arg ITLINE_DMA1_CH5 DMA1 Channel 5 Interrupt
  274. * @arg ITLINE_DMA1_CH6 DMA1 Channel 6 Interrupt
  275. * @arg ITLINE_DMA1_CH7 DMA1 Channel 7 Interrupt
  276. * @arg ITLINE_DMA2_CH3 DMA2 Channel 3 Interrupt
  277. * @arg ITLINE_DMA2_CH4 DMA2 Channel 4 Interrupt
  278. * @arg ITLINE_DMA2_CH5 DMA2 Channel 5 Interrupt
  279. * @arg ITLINE_ADC ADC Interrupt
  280. * @arg ITLINE_COMP1 COMP1 Interrupt -> exti[21]
  281. * @arg ITLINE_COMP2 COMP2 Interrupt -> exti[21]
  282. * @arg ITLINE_TIM1_BRK TIM1 BRK Interrupt
  283. * @arg ITLINE_TIM1_UPD TIM1 UPD Interrupt
  284. * @arg ITLINE_TIM1_TRG TIM1 TRG Interrupt
  285. * @arg ITLINE_TIM1_CCU TIM1 CCU Interrupt
  286. * @arg ITLINE_TIM1_CC TIM1 CC Interrupt
  287. * @arg ITLINE_TIM2 TIM2 Interrupt
  288. * @arg ITLINE_TIM3 TIM3 Interrupt
  289. * @arg ITLINE_DAC DAC Interrupt
  290. * @arg ITLINE_TIM6 TIM6 Interrupt
  291. * @arg ITLINE_TIM7 TIM7 Interrupt
  292. * @arg ITLINE_TIM14 TIM14 Interrupt
  293. * @arg ITLINE_TIM15 TIM15 Interrupt
  294. * @arg ITLINE_TIM16 TIM16 Interrupt
  295. * @arg ITLINE_TIM17 TIM17 Interrupt
  296. * @arg ITLINE_I2C1 I2C1 Interrupt -> exti[23]
  297. * @arg ITLINE_I2C2 I2C2 Interrupt
  298. * @arg ITLINE_SPI1 I2C1 Interrupt -> exti[23]
  299. * @arg ITLINE_SPI2 SPI1 Interrupt
  300. * @arg ITLINE_USART1 USART1 GLB Interrupt -> exti[25]
  301. * @arg ITLINE_USART2 USART2 GLB Interrupt -> exti[26]
  302. * @arg ITLINE_USART3 USART3 Interrupt
  303. * @arg ITLINE_USART4 USART4 Interrupt
  304. * @arg ITLINE_USART5 USART5 Interrupt
  305. * @arg ITLINE_USART6 USART6 Interrupt
  306. * @arg ITLINE_USART7 USART7 Interrupt
  307. * @arg ITLINE_USART8 USART8 Interrupt
  308. * @arg ITLINE_CAN CAN Interrupt
  309. * @arg ITLINE_CEC CEC Interrupt
  310. * @retval The new state of IT_LINE_SR.
  311. */
  312. uint32_t SYSCFG_GetPendingIT(uint32_t ITSourceLine)
  313. {
  314. assert_param(IS_SYSCFG_ITLINE(ITSourceLine));
  315. return(SYSCFG->IT_LINE_SR[(ITSourceLine >> 0x18)] & (ITSourceLine & 0x00FFFFFF));
  316. }
  317. /**
  318. * @brief Connect the selected parameter to the break input of TIM1.
  319. * @note The selected configuration is locked and can be unlocked by system reset
  320. * @param SYSCFG_Break: selects the configuration to be connected to break
  321. * input of TIM1
  322. * This parameter can be any combination of the following values:
  323. * @arg SYSCFG_Break_PVD: Connects the PVD event to the Break Input of TIM1,, not available for STM32F030 devices.
  324. * @arg SYSCFG_Break_SRAMParity: Connects the SRAM_PARITY error signal to the Break Input of TIM1 .
  325. * @arg SYSCFG_Break_Lockup: Connects Lockup output of CortexM0 to the break input of TIM1.
  326. * @retval None
  327. */
  328. void SYSCFG_BreakConfig(uint32_t SYSCFG_Break)
  329. {
  330. /* Check the parameter */
  331. assert_param(IS_SYSCFG_LOCK_CONFIG(SYSCFG_Break));
  332. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_Break;
  333. }
  334. /**
  335. * @brief Checks whether the specified SYSCFG flag is set or not.
  336. * @param SYSCFG_Flag: specifies the SYSCFG flag to check.
  337. * This parameter can be one of the following values:
  338. * @arg SYSCFG_FLAG_PE: SRAM parity error flag.
  339. * @retval The new state of SYSCFG_Flag (SET or RESET).
  340. */
  341. FlagStatus SYSCFG_GetFlagStatus(uint32_t SYSCFG_Flag)
  342. {
  343. FlagStatus bitstatus = RESET;
  344. /* Check the parameter */
  345. assert_param(IS_SYSCFG_FLAG(SYSCFG_Flag));
  346. /* Check the status of the specified SPI flag */
  347. if ((SYSCFG->CFGR2 & SYSCFG_CFGR2_SRAM_PE) != (uint32_t)RESET)
  348. {
  349. /* SYSCFG_Flag is set */
  350. bitstatus = SET;
  351. }
  352. else
  353. {
  354. /* SYSCFG_Flag is reset */
  355. bitstatus = RESET;
  356. }
  357. /* Return the SYSCFG_Flag status */
  358. return bitstatus;
  359. }
  360. /**
  361. * @brief Clear the selected SYSCFG flag.
  362. * @param SYSCFG_Flag: selects the flag to be cleared.
  363. * This parameter can be any combination of the following values:
  364. * @arg SYSCFG_FLAG_PE: SRAM parity error flag.
  365. * @retval None
  366. */
  367. void SYSCFG_ClearFlag(uint32_t SYSCFG_Flag)
  368. {
  369. /* Check the parameter */
  370. assert_param(IS_SYSCFG_FLAG(SYSCFG_Flag));
  371. SYSCFG->CFGR2 |= (uint32_t) SYSCFG_Flag;
  372. }
  373. /**
  374. * @}
  375. */
  376. /**
  377. * @}
  378. */
  379. /**
  380. * @}
  381. */
  382. /**
  383. * @}
  384. */
  385. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/