mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Jun 24 14:45:08 2014 +0100
Revision:
237:f3da66175598
Child:
375:3d36234a1087
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7

Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/

[NUCLEO_F334R8] Add platform files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_i2c_ex.c
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 237:f3da66175598 5 * @version V1.0.1
mbed_official 237:f3da66175598 6 * @date 18-June-2014
mbed_official 237:f3da66175598 7 * @brief I2C Extension HAL module driver.
mbed_official 237:f3da66175598 8 * This file provides firmware functions to manage the following
mbed_official 237:f3da66175598 9 * functionalities of I2C extension peripheral:
mbed_official 237:f3da66175598 10 * + Extension features functions
mbed_official 237:f3da66175598 11 *
mbed_official 237:f3da66175598 12 @verbatim
mbed_official 237:f3da66175598 13 ==============================================================================
mbed_official 237:f3da66175598 14 ##### I2C peripheral extension features #####
mbed_official 237:f3da66175598 15 ==============================================================================
mbed_official 237:f3da66175598 16
mbed_official 237:f3da66175598 17 [..] Comparing to other previous devices, the I2C interface for STM32F3XX
mbed_official 237:f3da66175598 18 devices contains the following additional features
mbed_official 237:f3da66175598 19
mbed_official 237:f3da66175598 20 (+) Possibility to disable or enable Analog Noise Filter
mbed_official 237:f3da66175598 21 (+) Use of a configured Digital Noise Filter
mbed_official 237:f3da66175598 22 (+) Disable or enable wakeup from Stop mode
mbed_official 237:f3da66175598 23
mbed_official 237:f3da66175598 24 ##### How to use this driver #####
mbed_official 237:f3da66175598 25 ==============================================================================
mbed_official 237:f3da66175598 26 [..] This driver provides functions to configure Noise Filter
mbed_official 237:f3da66175598 27 (#) Configure I2C Analog noise filter using the function HAL_I2CEx_AnalogFilter_Config()
mbed_official 237:f3da66175598 28 (#) Configure I2C Digital noise filter using the function HAL_I2CEx_DigitalFilter_Config()
mbed_official 237:f3da66175598 29 (#) Configure the enabling or disabling of I2C Wake Up Mode using the functions :
mbed_official 237:f3da66175598 30 + HAL_I2CEx_EnableWakeUp()
mbed_official 237:f3da66175598 31 + HAL_I2CEx_DisableWakeUp()
mbed_official 237:f3da66175598 32
mbed_official 237:f3da66175598 33 @endverbatim
mbed_official 237:f3da66175598 34 ******************************************************************************
mbed_official 237:f3da66175598 35 * @attention
mbed_official 237:f3da66175598 36 *
mbed_official 237:f3da66175598 37 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 38 *
mbed_official 237:f3da66175598 39 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 40 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 41 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 42 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 43 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 44 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 45 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 46 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 47 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 48 * without specific prior written permission.
mbed_official 237:f3da66175598 49 *
mbed_official 237:f3da66175598 50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 51 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 53 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 56 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 57 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 58 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 60 *
mbed_official 237:f3da66175598 61 ******************************************************************************
mbed_official 237:f3da66175598 62 */
mbed_official 237:f3da66175598 63
mbed_official 237:f3da66175598 64 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 65 #include "stm32f3xx_hal.h"
mbed_official 237:f3da66175598 66
mbed_official 237:f3da66175598 67 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 68 * @{
mbed_official 237:f3da66175598 69 */
mbed_official 237:f3da66175598 70
mbed_official 237:f3da66175598 71 /** @defgroup I2CEx
mbed_official 237:f3da66175598 72 * @brief I2C Extended HAL module driver
mbed_official 237:f3da66175598 73 * @{
mbed_official 237:f3da66175598 74 */
mbed_official 237:f3da66175598 75
mbed_official 237:f3da66175598 76 #ifdef HAL_I2C_MODULE_ENABLED
mbed_official 237:f3da66175598 77
mbed_official 237:f3da66175598 78 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 79 /* Private define ------------------------------------------------------------*/
mbed_official 237:f3da66175598 80 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 81 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 82 /* Private function prototypes -----------------------------------------------*/
mbed_official 237:f3da66175598 83 /* Private functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 84
mbed_official 237:f3da66175598 85 /** @defgroup I2CEx_Private_Functions
mbed_official 237:f3da66175598 86 * @{
mbed_official 237:f3da66175598 87 */
mbed_official 237:f3da66175598 88
mbed_official 237:f3da66175598 89
mbed_official 237:f3da66175598 90 /** @defgroup I2CEx_Group1 Extended features functions
mbed_official 237:f3da66175598 91 * @brief Extended features functions
mbed_official 237:f3da66175598 92 *
mbed_official 237:f3da66175598 93 @verbatim
mbed_official 237:f3da66175598 94 ===============================================================================
mbed_official 237:f3da66175598 95 ##### Extension features functions #####
mbed_official 237:f3da66175598 96 ===============================================================================
mbed_official 237:f3da66175598 97 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 98 (+) Configure Noise Filters
mbed_official 237:f3da66175598 99
mbed_official 237:f3da66175598 100 @endverbatim
mbed_official 237:f3da66175598 101 * @{
mbed_official 237:f3da66175598 102 */
mbed_official 237:f3da66175598 103
mbed_official 237:f3da66175598 104 /**
mbed_official 237:f3da66175598 105 * @brief Configures I2C Analog noise filter.
mbed_official 237:f3da66175598 106 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 107 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 108 * @param AnalogFilter : new state of the Analog filter.
mbed_official 237:f3da66175598 109 * @retval HAL status
mbed_official 237:f3da66175598 110 */
mbed_official 237:f3da66175598 111 HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
mbed_official 237:f3da66175598 112 {
mbed_official 237:f3da66175598 113 /* Check the parameters */
mbed_official 237:f3da66175598 114 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 115 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
mbed_official 237:f3da66175598 116
mbed_official 237:f3da66175598 117 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
mbed_official 237:f3da66175598 118 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 119 {
mbed_official 237:f3da66175598 120 return HAL_BUSY;
mbed_official 237:f3da66175598 121 }
mbed_official 237:f3da66175598 122
mbed_official 237:f3da66175598 123 /* Process Locked */
mbed_official 237:f3da66175598 124 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 125
mbed_official 237:f3da66175598 126 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 127
mbed_official 237:f3da66175598 128 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 129 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 130
mbed_official 237:f3da66175598 131 /* Reset I2Cx ANOFF bit */
mbed_official 237:f3da66175598 132 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
mbed_official 237:f3da66175598 133
mbed_official 237:f3da66175598 134 /* Set analog filter bit*/
mbed_official 237:f3da66175598 135 hi2c->Instance->CR1 |= AnalogFilter;
mbed_official 237:f3da66175598 136
mbed_official 237:f3da66175598 137 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 138
mbed_official 237:f3da66175598 139 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 140
mbed_official 237:f3da66175598 141 /* Process Unlocked */
mbed_official 237:f3da66175598 142 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 143
mbed_official 237:f3da66175598 144 return HAL_OK;
mbed_official 237:f3da66175598 145 }
mbed_official 237:f3da66175598 146
mbed_official 237:f3da66175598 147 /**
mbed_official 237:f3da66175598 148 * @brief Configures I2C Digital noise filter.
mbed_official 237:f3da66175598 149 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 150 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 151 * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
mbed_official 237:f3da66175598 152 * @retval HAL status
mbed_official 237:f3da66175598 153 */
mbed_official 237:f3da66175598 154 HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
mbed_official 237:f3da66175598 155 {
mbed_official 237:f3da66175598 156 uint32_t tmpreg = 0;
mbed_official 237:f3da66175598 157
mbed_official 237:f3da66175598 158 /* Check the parameters */
mbed_official 237:f3da66175598 159 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 160 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
mbed_official 237:f3da66175598 161
mbed_official 237:f3da66175598 162 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
mbed_official 237:f3da66175598 163 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 164 {
mbed_official 237:f3da66175598 165 return HAL_BUSY;
mbed_official 237:f3da66175598 166 }
mbed_official 237:f3da66175598 167
mbed_official 237:f3da66175598 168 /* Process Locked */
mbed_official 237:f3da66175598 169 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 170
mbed_official 237:f3da66175598 171 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 172
mbed_official 237:f3da66175598 173 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 174 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 175
mbed_official 237:f3da66175598 176 /* Get the old register value */
mbed_official 237:f3da66175598 177 tmpreg = hi2c->Instance->CR1;
mbed_official 237:f3da66175598 178
mbed_official 237:f3da66175598 179 /* Reset I2Cx DNF bits [11:8] */
mbed_official 237:f3da66175598 180 tmpreg &= ~(I2C_CR1_DFN);
mbed_official 237:f3da66175598 181
mbed_official 237:f3da66175598 182 /* Set I2Cx DNF coefficient */
mbed_official 237:f3da66175598 183 tmpreg |= DigitalFilter << 8;
mbed_official 237:f3da66175598 184
mbed_official 237:f3da66175598 185 /* Store the new register value */
mbed_official 237:f3da66175598 186 hi2c->Instance->CR1 = tmpreg;
mbed_official 237:f3da66175598 187
mbed_official 237:f3da66175598 188 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 189
mbed_official 237:f3da66175598 190 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 191
mbed_official 237:f3da66175598 192 /* Process Unlocked */
mbed_official 237:f3da66175598 193 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 194
mbed_official 237:f3da66175598 195 return HAL_OK;
mbed_official 237:f3da66175598 196 }
mbed_official 237:f3da66175598 197
mbed_official 237:f3da66175598 198 /**
mbed_official 237:f3da66175598 199 * @brief Enables I2C wakeup from stop mode.
mbed_official 237:f3da66175598 200 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 201 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 202 * @retval HAL status
mbed_official 237:f3da66175598 203 */
mbed_official 237:f3da66175598 204 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef *hi2c)
mbed_official 237:f3da66175598 205 {
mbed_official 237:f3da66175598 206 /* Check the parameters */
mbed_official 237:f3da66175598 207 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 208
mbed_official 237:f3da66175598 209 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
mbed_official 237:f3da66175598 210 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 211 {
mbed_official 237:f3da66175598 212 return HAL_BUSY;
mbed_official 237:f3da66175598 213 }
mbed_official 237:f3da66175598 214
mbed_official 237:f3da66175598 215 /* Process Locked */
mbed_official 237:f3da66175598 216 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 217
mbed_official 237:f3da66175598 218 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 219
mbed_official 237:f3da66175598 220 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 221 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 222
mbed_official 237:f3da66175598 223 /* Enable wakeup from stop mode */
mbed_official 237:f3da66175598 224 hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
mbed_official 237:f3da66175598 225
mbed_official 237:f3da66175598 226 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 227
mbed_official 237:f3da66175598 228 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 229
mbed_official 237:f3da66175598 230 /* Process Unlocked */
mbed_official 237:f3da66175598 231 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 232
mbed_official 237:f3da66175598 233 return HAL_OK;
mbed_official 237:f3da66175598 234 }
mbed_official 237:f3da66175598 235
mbed_official 237:f3da66175598 236
mbed_official 237:f3da66175598 237 /**
mbed_official 237:f3da66175598 238 * @brief Disables I2C wakeup from stop mode.
mbed_official 237:f3da66175598 239 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 240 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 241 * @retval HAL status
mbed_official 237:f3da66175598 242 */
mbed_official 237:f3da66175598 243 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef *hi2c)
mbed_official 237:f3da66175598 244 {
mbed_official 237:f3da66175598 245 /* Check the parameters */
mbed_official 237:f3da66175598 246 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 247
mbed_official 237:f3da66175598 248 if((hi2c->State == HAL_I2C_STATE_BUSY) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_MASTER_BUSY_RX)
mbed_official 237:f3da66175598 249 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 250 {
mbed_official 237:f3da66175598 251 return HAL_BUSY;
mbed_official 237:f3da66175598 252 }
mbed_official 237:f3da66175598 253
mbed_official 237:f3da66175598 254 /* Process Locked */
mbed_official 237:f3da66175598 255 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 256
mbed_official 237:f3da66175598 257 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 258
mbed_official 237:f3da66175598 259 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 260 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 261
mbed_official 237:f3da66175598 262 /* Enable wakeup from stop mode */
mbed_official 237:f3da66175598 263 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
mbed_official 237:f3da66175598 264
mbed_official 237:f3da66175598 265 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 266
mbed_official 237:f3da66175598 267 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 268
mbed_official 237:f3da66175598 269 /* Process Unlocked */
mbed_official 237:f3da66175598 270 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 271
mbed_official 237:f3da66175598 272 return HAL_OK;
mbed_official 237:f3da66175598 273 }
mbed_official 237:f3da66175598 274
mbed_official 237:f3da66175598 275 /**
mbed_official 237:f3da66175598 276 * @}
mbed_official 237:f3da66175598 277 */
mbed_official 237:f3da66175598 278
mbed_official 237:f3da66175598 279 /**
mbed_official 237:f3da66175598 280 * @}
mbed_official 237:f3da66175598 281 */
mbed_official 237:f3da66175598 282
mbed_official 237:f3da66175598 283 #endif /* HAL_I2C_MODULE_ENABLED */
mbed_official 237:f3da66175598 284 /**
mbed_official 237:f3da66175598 285 * @}
mbed_official 237:f3da66175598 286 */
mbed_official 237:f3da66175598 287
mbed_official 237:f3da66175598 288 /**
mbed_official 237:f3da66175598 289 * @}
mbed_official 237:f3da66175598 290 */
mbed_official 237:f3da66175598 291
mbed_official 237:f3da66175598 292 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/