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:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
76:aeb1df146756
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

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 106:ced8cbb51063 68 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 69 *
mbed_official 106:ced8cbb51063 70 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 106:ced8cbb51063 71 * are permitted provided that the following conditions are met:
mbed_official 106:ced8cbb51063 72 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 106:ced8cbb51063 73 * this list of conditions and the following disclaimer.
mbed_official 106:ced8cbb51063 74 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 106:ced8cbb51063 75 * this list of conditions and the following disclaimer in the documentation
mbed_official 106:ced8cbb51063 76 * and/or other materials provided with the distribution.
mbed_official 106:ced8cbb51063 77 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 106:ced8cbb51063 78 * may be used to endorse or promote products derived from this software
mbed_official 106:ced8cbb51063 79 * without specific prior written permission.
mbed_official 76:aeb1df146756 80 *
mbed_official 106:ced8cbb51063 81 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 106:ced8cbb51063 82 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 106:ced8cbb51063 83 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 106:ced8cbb51063 84 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 106:ced8cbb51063 85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 106:ced8cbb51063 86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 106:ced8cbb51063 87 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 106:ced8cbb51063 88 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 106:ced8cbb51063 89 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 106:ced8cbb51063 90 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 91 *
mbed_official 76:aeb1df146756 92 ******************************************************************************
mbed_official 76:aeb1df146756 93 */
mbed_official 76:aeb1df146756 94
mbed_official 76:aeb1df146756 95 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 96 #include "stm32f0xx_wwdg.h"
mbed_official 76:aeb1df146756 97 #include "stm32f0xx_rcc.h"
mbed_official 76:aeb1df146756 98
mbed_official 76:aeb1df146756 99 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 100 * @{
mbed_official 76:aeb1df146756 101 */
mbed_official 76:aeb1df146756 102
mbed_official 76:aeb1df146756 103 /** @defgroup WWDG
mbed_official 76:aeb1df146756 104 * @brief WWDG driver modules
mbed_official 76:aeb1df146756 105 * @{
mbed_official 76:aeb1df146756 106 */
mbed_official 76:aeb1df146756 107
mbed_official 76:aeb1df146756 108 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 109 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 110 /* --------------------- WWDG registers bit mask ---------------------------- */
mbed_official 76:aeb1df146756 111 /* CFR register bit mask */
mbed_official 76:aeb1df146756 112 #define CFR_WDGTB_MASK ((uint32_t)0xFFFFFE7F)
mbed_official 76:aeb1df146756 113 #define CFR_W_MASK ((uint32_t)0xFFFFFF80)
mbed_official 76:aeb1df146756 114 #define BIT_MASK ((uint8_t)0x7F)
mbed_official 76:aeb1df146756 115
mbed_official 76:aeb1df146756 116 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 117 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 118 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 119 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 120
mbed_official 76:aeb1df146756 121 /** @defgroup WWDG_Private_Functions
mbed_official 76:aeb1df146756 122 * @{
mbed_official 76:aeb1df146756 123 */
mbed_official 76:aeb1df146756 124
mbed_official 76:aeb1df146756 125 /** @defgroup WWDG_Group1 Prescaler, Refresh window and Counter configuration functions
mbed_official 76:aeb1df146756 126 * @brief Prescaler, Refresh window and Counter configuration functions
mbed_official 76:aeb1df146756 127 *
mbed_official 76:aeb1df146756 128 @verbatim
mbed_official 76:aeb1df146756 129 ==============================================================================
mbed_official 76:aeb1df146756 130 ##### Prescaler, Refresh window and Counter configuration functions #####
mbed_official 76:aeb1df146756 131 ==============================================================================
mbed_official 76:aeb1df146756 132
mbed_official 76:aeb1df146756 133 @endverbatim
mbed_official 76:aeb1df146756 134 * @{
mbed_official 76:aeb1df146756 135 */
mbed_official 76:aeb1df146756 136
mbed_official 76:aeb1df146756 137 /**
mbed_official 76:aeb1df146756 138 * @brief Deinitializes the WWDG peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 139 * @param None
mbed_official 76:aeb1df146756 140 * @retval None
mbed_official 76:aeb1df146756 141 */
mbed_official 76:aeb1df146756 142 void WWDG_DeInit(void)
mbed_official 76:aeb1df146756 143 {
mbed_official 76:aeb1df146756 144 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
mbed_official 76:aeb1df146756 145 RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
mbed_official 76:aeb1df146756 146 }
mbed_official 76:aeb1df146756 147
mbed_official 76:aeb1df146756 148 /**
mbed_official 76:aeb1df146756 149 * @brief Sets the WWDG Prescaler.
mbed_official 76:aeb1df146756 150 * @param WWDG_Prescaler: specifies the WWDG Prescaler.
mbed_official 76:aeb1df146756 151 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 152 * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
mbed_official 76:aeb1df146756 153 * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
mbed_official 76:aeb1df146756 154 * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
mbed_official 76:aeb1df146756 155 * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
mbed_official 76:aeb1df146756 156 * @retval None
mbed_official 76:aeb1df146756 157 */
mbed_official 76:aeb1df146756 158 void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
mbed_official 76:aeb1df146756 159 {
mbed_official 76:aeb1df146756 160 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 161 /* Check the parameters */
mbed_official 76:aeb1df146756 162 assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
mbed_official 76:aeb1df146756 163 /* Clear WDGTB[1:0] bits */
mbed_official 76:aeb1df146756 164 tmpreg = WWDG->CFR & CFR_WDGTB_MASK;
mbed_official 76:aeb1df146756 165 /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
mbed_official 76:aeb1df146756 166 tmpreg |= WWDG_Prescaler;
mbed_official 76:aeb1df146756 167 /* Store the new value */
mbed_official 76:aeb1df146756 168 WWDG->CFR = tmpreg;
mbed_official 76:aeb1df146756 169 }
mbed_official 76:aeb1df146756 170
mbed_official 76:aeb1df146756 171 /**
mbed_official 76:aeb1df146756 172 * @brief Sets the WWDG window value.
mbed_official 76:aeb1df146756 173 * @param WindowValue: specifies the window value to be compared to the downcounter.
mbed_official 76:aeb1df146756 174 * This parameter value must be lower than 0x80.
mbed_official 76:aeb1df146756 175 * @retval None
mbed_official 76:aeb1df146756 176 */
mbed_official 76:aeb1df146756 177 void WWDG_SetWindowValue(uint8_t WindowValue)
mbed_official 76:aeb1df146756 178 {
mbed_official 76:aeb1df146756 179 __IO uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 180
mbed_official 76:aeb1df146756 181 /* Check the parameters */
mbed_official 76:aeb1df146756 182 assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
mbed_official 76:aeb1df146756 183 /* Clear W[6:0] bits */
mbed_official 76:aeb1df146756 184
mbed_official 76:aeb1df146756 185 tmpreg = WWDG->CFR & CFR_W_MASK;
mbed_official 76:aeb1df146756 186
mbed_official 76:aeb1df146756 187 /* Set W[6:0] bits according to WindowValue value */
mbed_official 76:aeb1df146756 188 tmpreg |= WindowValue & (uint32_t) BIT_MASK;
mbed_official 76:aeb1df146756 189
mbed_official 76:aeb1df146756 190 /* Store the new value */
mbed_official 76:aeb1df146756 191 WWDG->CFR = tmpreg;
mbed_official 76:aeb1df146756 192 }
mbed_official 76:aeb1df146756 193
mbed_official 76:aeb1df146756 194 /**
mbed_official 76:aeb1df146756 195 * @brief Enables the WWDG Early Wakeup interrupt(EWI).
mbed_official 76:aeb1df146756 196 * @note Once enabled this interrupt cannot be disabled except by a system reset.
mbed_official 76:aeb1df146756 197 * @param None
mbed_official 76:aeb1df146756 198 * @retval None
mbed_official 76:aeb1df146756 199 */
mbed_official 76:aeb1df146756 200 void WWDG_EnableIT(void)
mbed_official 76:aeb1df146756 201 {
mbed_official 76:aeb1df146756 202 WWDG->CFR |= WWDG_CFR_EWI;
mbed_official 76:aeb1df146756 203 }
mbed_official 76:aeb1df146756 204
mbed_official 76:aeb1df146756 205 /**
mbed_official 76:aeb1df146756 206 * @brief Sets the WWDG counter value.
mbed_official 76:aeb1df146756 207 * @param Counter: specifies the watchdog counter value.
mbed_official 76:aeb1df146756 208 * This parameter must be a number between 0x40 and 0x7F (to prevent
mbed_official 76:aeb1df146756 209 * generating an immediate reset).
mbed_official 76:aeb1df146756 210 * @retval None
mbed_official 76:aeb1df146756 211 */
mbed_official 76:aeb1df146756 212 void WWDG_SetCounter(uint8_t Counter)
mbed_official 76:aeb1df146756 213 {
mbed_official 76:aeb1df146756 214 /* Check the parameters */
mbed_official 76:aeb1df146756 215 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 76:aeb1df146756 216 /* Write to T[6:0] bits to configure the counter value, no need to do
mbed_official 76:aeb1df146756 217 a read-modify-write; writing a 0 to WDGA bit does nothing */
mbed_official 76:aeb1df146756 218 WWDG->CR = Counter & BIT_MASK;
mbed_official 76:aeb1df146756 219 }
mbed_official 76:aeb1df146756 220
mbed_official 76:aeb1df146756 221 /**
mbed_official 76:aeb1df146756 222 * @}
mbed_official 76:aeb1df146756 223 */
mbed_official 76:aeb1df146756 224
mbed_official 76:aeb1df146756 225 /** @defgroup WWDG_Group2 WWDG activation functions
mbed_official 76:aeb1df146756 226 * @brief WWDG activation functions
mbed_official 76:aeb1df146756 227 *
mbed_official 76:aeb1df146756 228 @verbatim
mbed_official 76:aeb1df146756 229 ==============================================================================
mbed_official 76:aeb1df146756 230 ##### WWDG activation function #####
mbed_official 76:aeb1df146756 231 ==============================================================================
mbed_official 76:aeb1df146756 232
mbed_official 76:aeb1df146756 233 @endverbatim
mbed_official 76:aeb1df146756 234 * @{
mbed_official 76:aeb1df146756 235 */
mbed_official 76:aeb1df146756 236
mbed_official 76:aeb1df146756 237 /**
mbed_official 76:aeb1df146756 238 * @brief Enables WWDG and load the counter value.
mbed_official 76:aeb1df146756 239 * @param Counter: specifies the watchdog counter value.
mbed_official 76:aeb1df146756 240 * This parameter must be a number between 0x40 and 0x7F (to prevent
mbed_official 76:aeb1df146756 241 * generating an immediate reset).
mbed_official 76:aeb1df146756 242 * @retval None
mbed_official 76:aeb1df146756 243 */
mbed_official 76:aeb1df146756 244 void WWDG_Enable(uint8_t Counter)
mbed_official 76:aeb1df146756 245 {
mbed_official 76:aeb1df146756 246 /* Check the parameters */
mbed_official 76:aeb1df146756 247 assert_param(IS_WWDG_COUNTER(Counter));
mbed_official 76:aeb1df146756 248 WWDG->CR = WWDG_CR_WDGA | Counter;
mbed_official 76:aeb1df146756 249 }
mbed_official 76:aeb1df146756 250
mbed_official 76:aeb1df146756 251 /**
mbed_official 76:aeb1df146756 252 * @}
mbed_official 76:aeb1df146756 253 */
mbed_official 76:aeb1df146756 254
mbed_official 76:aeb1df146756 255 /** @defgroup WWDG_Group3 Interrupts and flags management functions
mbed_official 76:aeb1df146756 256 * @brief Interrupts and flags management functions
mbed_official 76:aeb1df146756 257 *
mbed_official 76:aeb1df146756 258 @verbatim
mbed_official 76:aeb1df146756 259 ==============================================================================
mbed_official 76:aeb1df146756 260 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 261 ==============================================================================
mbed_official 76:aeb1df146756 262
mbed_official 76:aeb1df146756 263 @endverbatim
mbed_official 76:aeb1df146756 264 * @{
mbed_official 76:aeb1df146756 265 */
mbed_official 76:aeb1df146756 266
mbed_official 76:aeb1df146756 267 /**
mbed_official 76:aeb1df146756 268 * @brief Checks whether the Early Wakeup interrupt flag is set or not.
mbed_official 76:aeb1df146756 269 * @param None
mbed_official 76:aeb1df146756 270 * @retval The new state of the Early Wakeup interrupt flag (SET or RESET).
mbed_official 76:aeb1df146756 271 */
mbed_official 76:aeb1df146756 272 FlagStatus WWDG_GetFlagStatus(void)
mbed_official 76:aeb1df146756 273 {
mbed_official 76:aeb1df146756 274 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 275
mbed_official 76:aeb1df146756 276 if ((WWDG->SR) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 277 {
mbed_official 76:aeb1df146756 278 bitstatus = SET;
mbed_official 76:aeb1df146756 279 }
mbed_official 76:aeb1df146756 280 else
mbed_official 76:aeb1df146756 281 {
mbed_official 76:aeb1df146756 282 bitstatus = RESET;
mbed_official 76:aeb1df146756 283 }
mbed_official 76:aeb1df146756 284 return bitstatus;
mbed_official 76:aeb1df146756 285 }
mbed_official 76:aeb1df146756 286
mbed_official 76:aeb1df146756 287 /**
mbed_official 76:aeb1df146756 288 * @brief Clears Early Wakeup interrupt flag.
mbed_official 76:aeb1df146756 289 * @param None
mbed_official 76:aeb1df146756 290 * @retval None
mbed_official 76:aeb1df146756 291 */
mbed_official 76:aeb1df146756 292 void WWDG_ClearFlag(void)
mbed_official 76:aeb1df146756 293 {
mbed_official 76:aeb1df146756 294 WWDG->SR = (uint32_t)RESET;
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 */
mbed_official 76:aeb1df146756 304
mbed_official 76:aeb1df146756 305 /**
mbed_official 76:aeb1df146756 306 * @}
mbed_official 76:aeb1df146756 307 */
mbed_official 76:aeb1df146756 308
mbed_official 76:aeb1df146756 309 /**
mbed_official 76:aeb1df146756 310 * @}
mbed_official 76:aeb1df146756 311 */
mbed_official 76:aeb1df146756 312
mbed_official 76:aeb1df146756 313 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/