stm32f2xx_syscfg.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_syscfg.c
  4. * @author MCD Application Team
  5. * @version V1.1.3
  6. * @date 31-December-2021
  7. * @brief This file provides firmware functions to manage the SYSCFG peripheral.
  8. *
  9. * @verbatim
  10. *
  11. * ===================================================================
  12. * How to use this driver
  13. * ===================================================================
  14. *
  15. * This driver provides functions for:
  16. *
  17. * 1. Remapping the memory accessible in the code area using SYSCFG_MemoryRemapConfig()
  18. *
  19. * 2. Manage the EXTI lines connection to the GPIOs using SYSCFG_EXTILineConfig()
  20. *
  21. * 3. Select the ETHERNET media interface (RMII/RII) using SYSCFG_ETH_MediaInterfaceConfig()
  22. *
  23. * @note SYSCFG APB clock must be enabled to get write access to SYSCFG registers,
  24. * using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  25. *
  26. * @endverbatim
  27. *
  28. ******************************************************************************
  29. * @attention
  30. *
  31. * Copyright (c) 2012 STMicroelectronics.
  32. * All rights reserved.
  33. *
  34. * This software is licensed under terms that can be found in the LICENSE file
  35. * in the root directory of this software component.
  36. * If no LICENSE file comes with this software, it is provided AS-IS.
  37. *
  38. ******************************************************************************
  39. */
  40. /* Includes ------------------------------------------------------------------*/
  41. #include "stm32f2xx_syscfg.h"
  42. #include "stm32f2xx_rcc.h"
  43. /** @addtogroup STM32F2xx_StdPeriph_Driver
  44. * @{
  45. */
  46. /** @defgroup SYSCFG
  47. * @brief SYSCFG driver modules
  48. * @{
  49. */
  50. /* Private typedef -----------------------------------------------------------*/
  51. /* Private define ------------------------------------------------------------*/
  52. /* ------------ RCC registers bit address in the alias region ----------- */
  53. #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE)
  54. /* --- PMC Register ---*/
  55. /* Alias word address of MII_RMII_SEL bit */
  56. #define PMC_OFFSET (SYSCFG_OFFSET + 0x04)
  57. #define MII_RMII_SEL_BitNumber ((uint8_t)0x17)
  58. #define PMC_MII_RMII_SEL_BB (PERIPH_BB_BASE + (PMC_OFFSET * 32) + (MII_RMII_SEL_BitNumber * 4))
  59. /* --- CMPCR Register ---*/
  60. /* Alias word address of CMP_PD bit */
  61. #define CMPCR_OFFSET (SYSCFG_OFFSET + 0x20)
  62. #define CMP_PD_BitNumber ((uint8_t)0x00)
  63. #define CMPCR_CMP_PD_BB (PERIPH_BB_BASE + (CMPCR_OFFSET * 32) + (CMP_PD_BitNumber * 4))
  64. /* Private macro -------------------------------------------------------------*/
  65. /* Private variables ---------------------------------------------------------*/
  66. /* Private function prototypes -----------------------------------------------*/
  67. /* Private functions ---------------------------------------------------------*/
  68. /** @defgroup SYSCFG_Private_Functions
  69. * @{
  70. */
  71. /**
  72. * @brief Deinitializes the Alternate Functions (remap and EXTI configuration)
  73. * registers to their default reset values.
  74. * @param None
  75. * @retval None
  76. */
  77. void SYSCFG_DeInit(void)
  78. {
  79. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  80. RCC_APB2PeriphResetCmd(RCC_APB2Periph_SYSCFG, DISABLE);
  81. }
  82. /**
  83. * @brief Changes the mapping of the specified pin.
  84. * @param SYSCFG_Memory: selects the memory remapping.
  85. * This parameter can be one of the following values:
  86. * @arg SYSCFG_MemoryRemap_Flash: Main Flash memory mapped at 0x00000000
  87. * @arg SYSCFG_MemoryRemap_SystemFlash: System Flash memory mapped at 0x00000000
  88. * @arg SYSCFG_MemoryRemap_FSMC: FSMC (Bank1 (NOR/PSRAM 1 and 2) mapped at 0x00000000
  89. * @arg SYSCFG_MemoryRemap_SRAM: Embedded SRAM (112kB) mapped at 0x00000000
  90. *
  91. * @note In remap mode, the FSMC addressing is fixed to the remap address area only
  92. * (Bank1 NOR/PSRAM 1 and NOR/PSRAM 2) and FSMC control registers are not
  93. * accessible. The FSMC remap function must be disabled to allows addressing
  94. * other memory devices through the FSMC and/or to access FSMC control
  95. * registers.
  96. *
  97. * @retval None
  98. */
  99. void SYSCFG_MemoryRemapConfig(uint8_t SYSCFG_MemoryRemap)
  100. {
  101. /* Check the parameters */
  102. assert_param(IS_SYSCFG_MEMORY_REMAP_CONFING(SYSCFG_MemoryRemap));
  103. SYSCFG->MEMRMP = SYSCFG_MemoryRemap;
  104. }
  105. /**
  106. * @brief Selects the GPIO pin used as EXTI Line.
  107. * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source for
  108. * EXTI lines where x can be (A..I).
  109. * @param EXTI_PinSourcex: specifies the EXTI line to be configured.
  110. * This parameter can be EXTI_PinSourcex where x can be (0..15, except
  111. * for EXTI_PortSourceGPIOI x can be (0..11).
  112. * @retval None
  113. */
  114. void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)
  115. {
  116. uint32_t tmp = 0x00;
  117. /* Check the parameters */
  118. assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx));
  119. assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex));
  120. tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03));
  121. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp;
  122. SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));
  123. }
  124. /**
  125. * @brief Selects the ETHERNET media interface
  126. * @param SYSCFG_ETH_MediaInterface: specifies the Media Interface mode.
  127. * This parameter can be one of the following values:
  128. * @arg SYSCFG_ETH_MediaInterface_MII: MII mode selected
  129. * @arg SYSCFG_ETH_MediaInterface_RMII: RMII mode selected
  130. * @retval None
  131. */
  132. void SYSCFG_ETH_MediaInterfaceConfig(uint32_t SYSCFG_ETH_MediaInterface)
  133. {
  134. assert_param(IS_SYSCFG_ETH_MEDIA_INTERFACE(SYSCFG_ETH_MediaInterface));
  135. /* Configure MII_RMII selection bit */
  136. *(__IO uint32_t *) PMC_MII_RMII_SEL_BB = SYSCFG_ETH_MediaInterface;
  137. }
  138. /**
  139. * @brief Enables or disables the I/O Compensation Cell.
  140. * @note The I/O compensation cell can be used only when the device supply
  141. * voltage ranges from 2.4 to 3.6 V.
  142. * @param NewState: new state of the I/O Compensation Cell.
  143. * This parameter can be one of the following values:
  144. * @arg ENABLE: I/O compensation cell enabled
  145. * @arg DISABLE: I/O compensation cell power-down mode
  146. * @retval None
  147. */
  148. void SYSCFG_CompensationCellCmd(FunctionalState NewState)
  149. {
  150. /* Check the parameters */
  151. assert_param(IS_FUNCTIONAL_STATE(NewState));
  152. *(__IO uint32_t *) CMPCR_CMP_PD_BB = (uint32_t)NewState;
  153. }
  154. /**
  155. * @brief Checks whether the I/O Compensation Cell ready flag is set or not.
  156. * @param None
  157. * @retval The new state of the I/O Compensation Cell ready flag (SET or RESET)
  158. */
  159. FlagStatus SYSCFG_GetCompensationCellStatus(void)
  160. {
  161. FlagStatus bitstatus = RESET;
  162. if ((SYSCFG->CMPCR & SYSCFG_CMPCR_READY ) != (uint32_t)RESET)
  163. {
  164. bitstatus = SET;
  165. }
  166. else
  167. {
  168. bitstatus = RESET;
  169. }
  170. return bitstatus;
  171. }
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. /**
  179. * @}
  180. */