stm32f0xx_misc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_misc.c
  4. * @author MCD Application Team
  5. * @version V1.5.0
  6. * @date 05-December-2014
  7. * @brief This file provides all the miscellaneous firmware functions (add-on
  8. * to CMSIS functions).
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f0xx_misc.h"
  30. /** @addtogroup STM32F0xx_StdPeriph_Driver
  31. * @{
  32. */
  33. /** @defgroup MISC
  34. * @brief MISC driver modules
  35. * @{
  36. */
  37. /* Private typedef -----------------------------------------------------------*/
  38. /* Private define ------------------------------------------------------------*/
  39. /* Private macro -------------------------------------------------------------*/
  40. /* Private variables ---------------------------------------------------------*/
  41. /* Private function prototypes -----------------------------------------------*/
  42. /* Private functions ---------------------------------------------------------*/
  43. /** @defgroup MISC_Private_Functions
  44. * @{
  45. */
  46. /**
  47. *
  48. @verbatim
  49. *******************************************************************************
  50. ##### Interrupts configuration functions #####
  51. *******************************************************************************
  52. [..] This section provide functions allowing to configure the NVIC interrupts
  53. (IRQ). The Cortex-M0 exceptions are managed by CMSIS functions.
  54. (#) Enable and Configure the priority of the selected IRQ Channels.
  55. The priority can be 0..3.
  56. -@- Lower priority values gives higher priority.
  57. -@- Priority Order:
  58. (#@) Lowest priority.
  59. (#@) Lowest hardware priority (IRQn position).
  60. @endverbatim
  61. */
  62. /**
  63. * @brief Initializes the NVIC peripheral according to the specified
  64. * parameters in the NVIC_InitStruct.
  65. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  66. * the configuration information for the specified NVIC peripheral.
  67. * @retval None
  68. */
  69. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  70. {
  71. uint32_t tmppriority = 0x00;
  72. /* Check the parameters */
  73. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  74. assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority));
  75. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  76. {
  77. /* Compute the Corresponding IRQ Priority --------------------------------*/
  78. tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02];
  79. tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)));
  80. tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8));
  81. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority;
  82. /* Enable the Selected IRQ Channels --------------------------------------*/
  83. NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  84. }
  85. else
  86. {
  87. /* Disable the Selected IRQ Channels -------------------------------------*/
  88. NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  89. }
  90. }
  91. /**
  92. * @brief Selects the condition for the system to enter low power mode.
  93. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  94. * This parameter can be one of the following values:
  95. * @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend.
  96. * @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request.
  97. * @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit.
  98. * @param NewState: new state of LP condition.
  99. * This parameter can be: ENABLE or DISABLE.
  100. * @retval None
  101. */
  102. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  103. {
  104. /* Check the parameters */
  105. assert_param(IS_NVIC_LP(LowPowerMode));
  106. assert_param(IS_FUNCTIONAL_STATE(NewState));
  107. if (NewState != DISABLE)
  108. {
  109. SCB->SCR |= LowPowerMode;
  110. }
  111. else
  112. {
  113. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  114. }
  115. }
  116. /**
  117. * @brief Configures the SysTick clock source.
  118. * @param SysTick_CLKSource: specifies the SysTick clock source.
  119. * This parameter can be one of the following values:
  120. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  121. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  122. * @retval None
  123. */
  124. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  125. {
  126. /* Check the parameters */
  127. assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
  128. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  129. {
  130. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  131. }
  132. else
  133. {
  134. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  135. }
  136. }
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */
  143. /**
  144. * @}
  145. */
  146. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/