mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/

Add NUCLEO_L152RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32f0xx_wwdg.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.3.0
mbed_official 76:aeb1df146756 6 * @date 16-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the Window watchdog (WWDG) peripheral:
mbed_official 76:aeb1df146756 9 * + Prescaler, Refresh window and Counter configuration
mbed_official 76:aeb1df146756 10 * + WWDG activation
mbed_official 76:aeb1df146756 11 * + Interrupts and flags management
mbed_official 76:aeb1df146756 12 *
mbed_official 76:aeb1df146756 13 * @verbatim
mbed_official 76:aeb1df146756 14 *
mbed_official 76:aeb1df146756 15 ==============================================================================
mbed_official 76:aeb1df146756 16 ##### WWDG features #####
mbed_official 76:aeb1df146756 17 ==============================================================================
mbed_official 76:aeb1df146756 18 [..] Once enabled the WWDG generates a system reset on expiry of a programmed
mbed_official 76:aeb1df146756 19 time period, unless the program refreshes the counter (downcounter)
mbed_official 76:aeb1df146756 20 before to reach 0x3F value (i.e. a reset is generated when the counter
mbed_official 76:aeb1df146756 21 value rolls over from 0x40 to 0x3F).
mbed_official 76:aeb1df146756 22 [..] An MCU reset is also generated if the counter value is refreshed
mbed_official 76:aeb1df146756 23 before the counter has reached the refresh window value. This
mbed_official 76:aeb1df146756 24 implies that the counter must be refreshed in a limited window.
mbed_official 76:aeb1df146756 25
mbed_official 76:aeb1df146756 26 [..] Once enabled the WWDG cannot be disabled except by a system reset.
mbed_official 76:aeb1df146756 27
mbed_official 76:aeb1df146756 28 [..] WWDGRST flag in RCC_CSR register can be used to inform when a WWDG
mbed_official 76:aeb1df146756 29 reset occurs.
mbed_official 76:aeb1df146756 30
mbed_official 76:aeb1df146756 31 [..] The WWDG counter input clock is derived from the APB clock divided
mbed_official 76:aeb1df146756 32 by a programmable prescaler.
mbed_official 76:aeb1df146756 33
mbed_official 76:aeb1df146756 34 [..] WWDG counter clock = PCLK1 / Prescaler.
mbed_official 76:aeb1df146756 35 [..] WWDG timeout = (WWDG counter clock) * (counter value).
mbed_official 76:aeb1df146756 36
mbed_official 76:aeb1df146756 37 [..] Min-max timeout value @32MHz (PCLK1): ~85us / ~43ms.
mbed_official 76:aeb1df146756 38
mbed_official 76:aeb1df146756 39 ##### How to use this driver #####
mbed_official 76:aeb1df146756 40 ==============================================================================
mbed_official 76:aeb1df146756 41 [..]
mbed_official 76:aeb1df146756 42 (#) Enable WWDG clock using RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE)
mbed_official 76:aeb1df146756 43 function.
mbed_official 76:aeb1df146756 44
mbed_official 76:aeb1df146756 45 (#) Configure the WWDG prescaler using WWDG_SetPrescaler() function.
mbed_official 76:aeb1df146756 46
mbed_official 76:aeb1df146756 47 (#) Configure the WWDG refresh window using WWDG_SetWindowValue() function.
mbed_official 76:aeb1df146756 48
mbed_official 76:aeb1df146756 49 (#) Set the WWDG counter value and start it using WWDG_Enable() function.
mbed_official 76:aeb1df146756 50 When the WWDG is enabled the counter value should be configured to
mbed_official 76:aeb1df146756 51 a value greater than 0x40 to prevent generating an immediate reset.
mbed_official 76:aeb1df146756 52
mbed_official 76:aeb1df146756 53 (#) Optionally you can enable the Early wakeup interrupt which is
mbed_official 76:aeb1df146756 54 generated when the counter reach 0x40.
mbed_official 76:aeb1df146756 55 Once enabled this interrupt cannot be disabled except by a system reset.
mbed_official 76:aeb1df146756 56
mbed_official 76:aeb1df146756 57 (#) Then the application program must refresh the WWDG counter at regular
mbed_official 76:aeb1df146756 58 intervals during normal operation to prevent an MCU reset, using
mbed_official 76:aeb1df146756 59 WWDG_SetCounter() function. This operation must occur only when
mbed_official 76:aeb1df146756 60 the counter value is lower than the refresh window value,
mbed_official 76:aeb1df146756 61 programmed using WWDG_SetWindowValue().
mbed_official 76:aeb1df146756 62
mbed_official 76:aeb1df146756 63 * @endverbatim
mbed_official 76:aeb1df146756 64 *
mbed_official 76:aeb1df146756 65 ******************************************************************************
mbed_official 76:aeb1df146756 66 * @attention
mbed_official 76:aeb1df146756 67 *
mbed_official 76:aeb1df146756 68 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 69 *
mbed_official 76:aeb1df146756 70 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 71 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 72 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 73 *
mbed_official 76:aeb1df146756 74 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 75 *
mbed_official 76:aeb1df146756 76 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 77 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 78 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 79 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 80 * limitations under the License.
mbed_official 76:aeb1df146756 81 *
mbed_official 76:aeb1df146756 82 ******************************************************************************
mbed_official 76:aeb1df146756 83 */
mbed_official 76:aeb1df146756 84
mbed_official 76:aeb1df146756 85 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 86 #include "stm32f0xx_wwdg.h"
mbed_official 76:aeb1df146756 87 #include "stm32f0xx_rcc.h"
mbed_official 76:aeb1df146756 88
mbed_official 76:aeb1df146756 89 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 90 * @{
mbed_official 76:aeb1df146756 91 */
mbed_official 76:aeb1df146756 92
mbed_official 76:aeb1df146756 93 /** @defgroup WWDG
mbed_official 76:aeb1df146756 94 * @brief WWDG driver modules
mbed_official 76:aeb1df146756 95 * @{
mbed_official 76:aeb1df146756 96 */
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 99 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 100 /* --------------------- WWDG registers bit mask ---------------------------- */
mbed_official 76:aeb1df146756 101 /* CFR register bit mask */
mbed_official 76:aeb1df146756 102 #define CFR_WDGTB_MASK ((uint32_t)0xFFFFFE7F)
mbed_official 76:aeb1df146756 103 #define CFR_W_MASK ((uint32_t)0xFFFFFF80)
mbed_official 76:aeb1df146756 104 #define BIT_MASK ((uint8_t)0x7F)
mbed_official 76:aeb1df146756 105
mbed_official 76:aeb1df146756 106 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 107 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 108 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 109 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 110
mbed_official 76:aeb1df146756 111 /** @defgroup WWDG_Private_Functions
mbed_official 76:aeb1df146756 112 * @{
mbed_official 76:aeb1df146756 113 */
mbed_official 76:aeb1df146756 114
mbed_official 76:aeb1df146756 115 /** @defgroup WWDG_Group1 Prescaler, Refresh window and Counter configuration functions
mbed_official 76:aeb1df146756 116 * @brief Prescaler, Refresh window and Counter configuration functions
mbed_official 76:aeb1df146756 117 *
mbed_official 76:aeb1df146756 118 @verbatim
mbed_official 76:aeb1df146756 119 ==============================================================================
mbed_official 76:aeb1df146756 120 ##### Prescaler, Refresh window and Counter configuration functions #####
mbed_official 76:aeb1df146756 121 ==============================================================================
mbed_official 76:aeb1df146756 122
mbed_official 76:aeb1df146756 123 @endverbatim
mbed_official 76:aeb1df146756 124 * @{
mbed_official 76:aeb1df146756 125 */
mbed_official 76:aeb1df146756 126
mbed_official 76:aeb1df146756 127 /**
mbed_official 76:aeb1df146756 128 * @brief Deinitializes the WWDG peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 129 * @param None
mbed_official 76:aeb1df146756 130 * @retval None
mbed_official 76:aeb1df146756 131 */
mbed_official 76:aeb1df146756 132 void WWDG_DeInit(void)
mbed_official 76:aeb1df146756 133 {
mbed_official 76:aeb1df146756 134 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
mbed_official 76:aeb1df146756 135 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
mbed_official 76:aeb1df146756 136 }
mbed_official 76:aeb1df146756 137
mbed_official 76:aeb1df146756 138 /**
mbed_official 76:aeb1df146756 139 * @brief Sets the WWDG Prescaler.
mbed_official 76:aeb1df146756 140 * @param WWDG_Prescaler: specifies the WWDG Prescaler.
mbed_official 76:aeb1df146756 141 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 142 * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
mbed_official 76:aeb1df146756 143 * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
mbed_official 76:aeb1df146756 144 * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
mbed_official 76:aeb1df146756 145 * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
mbed_official 76:aeb1df146756 146 * @retval None
mbed_official 76:aeb1df146756 147 */
mbed_official 76:aeb1df146756 148 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
mbed_official 76:aeb1df146756 149 {
mbed_official 76:aeb1df146756 150 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 151 /* Check the parameters */
mbed_official 76:aeb1df146756 152 assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
mbed_official 76:aeb1df146756 153 /* Clear WDGTB[1:0] bits */
mbed_official 76:aeb1df146756 154 tmpreg = WWDG->CFR & CFR_WDGTB_MASK;
mbed_official 76:aeb1df146756 155 /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
mbed_official 76:aeb1df146756 156 tmpreg |= WWDG_Prescaler;
mbed_official 76:aeb1df146756 157 /* Store the new value */
mbed_official 76:aeb1df146756 158 WWDG->CFR = tmpreg;
mbed_official 76:aeb1df146756 159 }
mbed_official 76:aeb1df146756 160
mbed_official 76:aeb1df146756 161 /**
mbed_official 76:aeb1df146756 162 * @brief Sets the WWDG window value.
mbed_official 76:aeb1df146756 163 * @param WindowValue: specifies the window value to be compared to the downcounter.
mbed_official 76:aeb1df146756 164 * This parameter value must be lower than 0x80.
mbed_official 76:aeb1df146756 165 * @retval None
mbed_official 76:aeb1df146756 166 */
mbed_official 76:aeb1df146756 167 void WWDG_SetWindowValue(uint8_t WindowValue)
mbed_official 76:aeb1df146756 168 {
mbed_official 76:aeb1df146756 169 __IO uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 170
mbed_official 76:aeb1df146756 171 /* Check the parameters */
mbed_official 76:aeb1df146756 172 assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
mbed_official 76:aeb1df146756 173 /* Clear W[6:0] bits */
mbed_official 76:aeb1df146756 174
mbed_official 76:aeb1df146756 175 tmpreg = WWDG->CFR & CFR_W_MASK;
mbed_official 76:aeb1df146756 176
mbed_official 76:aeb1df146756 177 /* Set W[6:0] bits according to WindowValue value */
mbed_official 76:aeb1df146756 178 tmpreg |= WindowValue & (uint32_t) BIT_MASK;
mbed_official 76:aeb1df146756 179
mbed_official 76:aeb1df146756 180 /* Store the new value */
mbed_official 76:aeb1df146756 181 WWDG->CFR = tmpreg;
mbed_official 76:aeb1df146756 182 }
mbed_official 76:aeb1df146756 183
mbed_official 76:aeb1df146756 184 /**
mbed_official 76:aeb1df146756 185 * @brief Enables the WWDG Early Wakeup interrupt(EWI).
mbed_official 76:aeb1df146756 186 * @note Once enabled this interrupt cannot be disabled except by a system reset.
mbed_official 76:aeb1df146756 187 * @param None
mbed_official 76:aeb1df146756 188 * @retval None
mbed_official 76:aeb1df146756 189 */
mbed_official 76:aeb1df146756 190 void WWDG_EnableIT(void)
mbed_official 76:aeb1df146756 191 {
mbed_official 76:aeb1df146756 192 WWDG->CFR |= WWDG_CFR_EWI;
mbed_official 76:aeb1df146756 193 }
mbed_official 76:aeb1df146756 194
mbed_official 76:aeb1df146756 195 /**
mbed_official 76:aeb1df146756 196 * @brief Sets the WWDG counter value.
mbed_official 76:aeb1df146756 197 * @param Counter: specifies the watchdog counter value.
mbed_official 76:aeb1df146756 198 * This parameter must be a number between 0x40 and 0x7F (to prevent
mbed_official 76:aeb1df146756 199 * generating an immediate reset).
mbed_official 76:aeb1df146756 200 * @retval None
mbed_official 76:aeb1df146756 201 */
mbed_official 76:aeb1df146756 202 void WWDG_SetCounter(uint8_t Counter)
mbed_official 76:aeb1df146756 203 {
mbed_official 76:aeb1df146756 204 /* Check the parameters */
mbed_official 76:aeb1df146756 205 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 76:aeb1df146756 206 /* Write to T[6:0] bits to configure the counter value, no need to do
mbed_official 76:aeb1df146756 207 a read-modify-write; writing a 0 to WDGA bit does nothing */
mbed_official 76:aeb1df146756 208 WWDG->CR = Counter & BIT_MASK;
mbed_official 76:aeb1df146756 209 }
mbed_official 76:aeb1df146756 210
mbed_official 76:aeb1df146756 211 /**
mbed_official 76:aeb1df146756 212 * @}
mbed_official 76:aeb1df146756 213 */
mbed_official 76:aeb1df146756 214
mbed_official 76:aeb1df146756 215 /** @defgroup WWDG_Group2 WWDG activation functions
mbed_official 76:aeb1df146756 216 * @brief WWDG activation functions
mbed_official 76:aeb1df146756 217 *
mbed_official 76:aeb1df146756 218 @verbatim
mbed_official 76:aeb1df146756 219 ==============================================================================
mbed_official 76:aeb1df146756 220 ##### WWDG activation function #####
mbed_official 76:aeb1df146756 221 ==============================================================================
mbed_official 76:aeb1df146756 222
mbed_official 76:aeb1df146756 223 @endverbatim
mbed_official 76:aeb1df146756 224 * @{
mbed_official 76:aeb1df146756 225 */
mbed_official 76:aeb1df146756 226
mbed_official 76:aeb1df146756 227 /**
mbed_official 76:aeb1df146756 228 * @brief Enables WWDG and load the counter value.
mbed_official 76:aeb1df146756 229 * @param Counter: specifies the watchdog counter value.
mbed_official 76:aeb1df146756 230 * This parameter must be a number between 0x40 and 0x7F (to prevent
mbed_official 76:aeb1df146756 231 * generating an immediate reset).
mbed_official 76:aeb1df146756 232 * @retval None
mbed_official 76:aeb1df146756 233 */
mbed_official 76:aeb1df146756 234 void WWDG_Enable(uint8_t Counter)
mbed_official 76:aeb1df146756 235 {
mbed_official 76:aeb1df146756 236 /* Check the parameters */
mbed_official 76:aeb1df146756 237 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 76:aeb1df146756 238 WWDG->CR = WWDG_CR_WDGA | Counter;
mbed_official 76:aeb1df146756 239 }
mbed_official 76:aeb1df146756 240
mbed_official 76:aeb1df146756 241 /**
mbed_official 76:aeb1df146756 242 * @}
mbed_official 76:aeb1df146756 243 */
mbed_official 76:aeb1df146756 244
mbed_official 76:aeb1df146756 245 /** @defgroup WWDG_Group3 Interrupts and flags management functions
mbed_official 76:aeb1df146756 246 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 247 *
mbed_official 76:aeb1df146756 248 @verbatim
mbed_official 76:aeb1df146756 249 ==============================================================================
mbed_official 76:aeb1df146756 250 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 251 ==============================================================================
mbed_official 76:aeb1df146756 252
mbed_official 76:aeb1df146756 253 @endverbatim
mbed_official 76:aeb1df146756 254 * @{
mbed_official 76:aeb1df146756 255 */
mbed_official 76:aeb1df146756 256
mbed_official 76:aeb1df146756 257 /**
mbed_official 76:aeb1df146756 258 * @brief Checks whether the Early Wakeup interrupt flag is set or not.
mbed_official 76:aeb1df146756 259 * @param None
mbed_official 76:aeb1df146756 260 * @retval The new state of the Early Wakeup interrupt flag (SET or RESET).
mbed_official 76:aeb1df146756 261 */
mbed_official 76:aeb1df146756 262 FlagStatus WWDG_GetFlagStatus(void)
mbed_official 76:aeb1df146756 263 {
mbed_official 76:aeb1df146756 264 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 265
mbed_official 76:aeb1df146756 266 if ((WWDG->SR) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 267 {
mbed_official 76:aeb1df146756 268 bitstatus = SET;
mbed_official 76:aeb1df146756 269 }
mbed_official 76:aeb1df146756 270 else
mbed_official 76:aeb1df146756 271 {
mbed_official 76:aeb1df146756 272 bitstatus = RESET;
mbed_official 76:aeb1df146756 273 }
mbed_official 76:aeb1df146756 274 return bitstatus;
mbed_official 76:aeb1df146756 275 }
mbed_official 76:aeb1df146756 276
mbed_official 76:aeb1df146756 277 /**
mbed_official 76:aeb1df146756 278 * @brief Clears Early Wakeup interrupt flag.
mbed_official 76:aeb1df146756 279 * @param None
mbed_official 76:aeb1df146756 280 * @retval None
mbed_official 76:aeb1df146756 281 */
mbed_official 76:aeb1df146756 282 void WWDG_ClearFlag(void)
mbed_official 76:aeb1df146756 283 {
mbed_official 76:aeb1df146756 284 WWDG->SR = (uint32_t)RESET;
mbed_official 76:aeb1df146756 285 }
mbed_official 76:aeb1df146756 286
mbed_official 76:aeb1df146756 287 /**
mbed_official 76:aeb1df146756 288 * @}
mbed_official 76:aeb1df146756 289 */
mbed_official 76:aeb1df146756 290
mbed_official 76:aeb1df146756 291 /**
mbed_official 76:aeb1df146756 292 * @}
mbed_official 76:aeb1df146756 293 */
mbed_official 76:aeb1df146756 294
mbed_official 76:aeb1df146756 295 /**
mbed_official 76:aeb1df146756 296 * @}
mbed_official 76:aeb1df146756 297 */
mbed_official 76:aeb1df146756 298
mbed_official 76:aeb1df146756 299 /**
mbed_official 76:aeb1df146756 300 * @}
mbed_official 76:aeb1df146756 301 */
mbed_official 76:aeb1df146756 302
mbed_official 76:aeb1df146756 303 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/