mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Sep 28 20:15:09 2015 +0100
Revision:
634:ac7d6880524d
Parent:
632:7687fb9c4f91
Synchronized with git revision 9b7d23d47153c298a6d24de9a415202705889d11

Full URL: https://github.com/mbedmicro/mbed/commit/9b7d23d47153c298a6d24de9a415202705889d11/

Revert "[NUCLEO_F303K8] add support of the STM32F303K8"

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 634:ac7d6880524d 5 * @version V1.1.0
mbed_official 634:ac7d6880524d 6 * @date 12-Sept-2014
mbed_official 375:3d36234a1087 7 * @brief I2C Extended HAL module driver.
mbed_official 237:f3da66175598 8 * This file provides firmware functions to manage the following
mbed_official 375:3d36234a1087 9 * functionalities of I2C Extended peripheral:
mbed_official 375:3d36234a1087 10 * + Extended features functions
mbed_official 237:f3da66175598 11 *
mbed_official 237:f3da66175598 12 @verbatim
mbed_official 237:f3da66175598 13 ==============================================================================
mbed_official 375:3d36234a1087 14 ##### I2C peripheral Extended 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 634:ac7d6880524d 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 375:3d36234a1087 71 /** @defgroup I2CEx I2C Extended HAL module driver
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 375:3d36234a1087 85 /** @defgroup I2CEx_Exported_Functions I2C Extended Exported Functions
mbed_official 237:f3da66175598 86 * @{
mbed_official 237:f3da66175598 87 */
mbed_official 237:f3da66175598 88
mbed_official 375:3d36234a1087 89 /** @defgroup I2CEx_Exported_Functions_Group1 Extended features functions
mbed_official 237:f3da66175598 90 * @brief Extended features functions
mbed_official 237:f3da66175598 91 *
mbed_official 237:f3da66175598 92 @verbatim
mbed_official 237:f3da66175598 93 ===============================================================================
mbed_official 375:3d36234a1087 94 ##### Extended features functions #####
mbed_official 237:f3da66175598 95 ===============================================================================
mbed_official 237:f3da66175598 96 [..] This section provides functions allowing to:
mbed_official 237:f3da66175598 97 (+) Configure Noise Filters
mbed_official 237:f3da66175598 98
mbed_official 237:f3da66175598 99 @endverbatim
mbed_official 237:f3da66175598 100 * @{
mbed_official 237:f3da66175598 101 */
mbed_official 237:f3da66175598 102
mbed_official 237:f3da66175598 103 /**
mbed_official 237:f3da66175598 104 * @brief Configures I2C Analog noise filter.
mbed_official 237:f3da66175598 105 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 106 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 107 * @param AnalogFilter : new state of the Analog filter.
mbed_official 237:f3da66175598 108 * @retval HAL status
mbed_official 237:f3da66175598 109 */
mbed_official 237:f3da66175598 110 HAL_StatusTypeDef HAL_I2CEx_AnalogFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t AnalogFilter)
mbed_official 237:f3da66175598 111 {
mbed_official 237:f3da66175598 112 /* Check the parameters */
mbed_official 237:f3da66175598 113 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 114 assert_param(IS_I2C_ANALOG_FILTER(AnalogFilter));
mbed_official 237:f3da66175598 115
mbed_official 237:f3da66175598 116 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 117 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 118 {
mbed_official 237:f3da66175598 119 return HAL_BUSY;
mbed_official 237:f3da66175598 120 }
mbed_official 237:f3da66175598 121
mbed_official 237:f3da66175598 122 /* Process Locked */
mbed_official 237:f3da66175598 123 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 124
mbed_official 237:f3da66175598 125 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 126
mbed_official 237:f3da66175598 127 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 128 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 129
mbed_official 237:f3da66175598 130 /* Reset I2Cx ANOFF bit */
mbed_official 237:f3da66175598 131 hi2c->Instance->CR1 &= ~(I2C_CR1_ANFOFF);
mbed_official 237:f3da66175598 132
mbed_official 237:f3da66175598 133 /* Set analog filter bit*/
mbed_official 237:f3da66175598 134 hi2c->Instance->CR1 |= AnalogFilter;
mbed_official 237:f3da66175598 135
mbed_official 237:f3da66175598 136 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 137
mbed_official 237:f3da66175598 138 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 139
mbed_official 237:f3da66175598 140 /* Process Unlocked */
mbed_official 237:f3da66175598 141 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 142
mbed_official 237:f3da66175598 143 return HAL_OK;
mbed_official 237:f3da66175598 144 }
mbed_official 237:f3da66175598 145
mbed_official 237:f3da66175598 146 /**
mbed_official 237:f3da66175598 147 * @brief Configures I2C Digital noise filter.
mbed_official 237:f3da66175598 148 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 149 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 150 * @param DigitalFilter : Coefficient of digital noise filter between 0x00 and 0x0F.
mbed_official 237:f3da66175598 151 * @retval HAL status
mbed_official 237:f3da66175598 152 */
mbed_official 237:f3da66175598 153 HAL_StatusTypeDef HAL_I2CEx_DigitalFilter_Config(I2C_HandleTypeDef *hi2c, uint32_t DigitalFilter)
mbed_official 237:f3da66175598 154 {
mbed_official 237:f3da66175598 155 uint32_t tmpreg = 0;
mbed_official 237:f3da66175598 156
mbed_official 237:f3da66175598 157 /* Check the parameters */
mbed_official 237:f3da66175598 158 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 159 assert_param(IS_I2C_DIGITAL_FILTER(DigitalFilter));
mbed_official 237:f3da66175598 160
mbed_official 237:f3da66175598 161 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 162 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 163 {
mbed_official 237:f3da66175598 164 return HAL_BUSY;
mbed_official 237:f3da66175598 165 }
mbed_official 237:f3da66175598 166
mbed_official 237:f3da66175598 167 /* Process Locked */
mbed_official 237:f3da66175598 168 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 169
mbed_official 237:f3da66175598 170 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 171
mbed_official 237:f3da66175598 172 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 173 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 174
mbed_official 237:f3da66175598 175 /* Get the old register value */
mbed_official 237:f3da66175598 176 tmpreg = hi2c->Instance->CR1;
mbed_official 237:f3da66175598 177
mbed_official 237:f3da66175598 178 /* Reset I2Cx DNF bits [11:8] */
mbed_official 237:f3da66175598 179 tmpreg &= ~(I2C_CR1_DFN);
mbed_official 237:f3da66175598 180
mbed_official 237:f3da66175598 181 /* Set I2Cx DNF coefficient */
mbed_official 237:f3da66175598 182 tmpreg |= DigitalFilter << 8;
mbed_official 237:f3da66175598 183
mbed_official 237:f3da66175598 184 /* Store the new register value */
mbed_official 237:f3da66175598 185 hi2c->Instance->CR1 = tmpreg;
mbed_official 237:f3da66175598 186
mbed_official 237:f3da66175598 187 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 188
mbed_official 237:f3da66175598 189 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 190
mbed_official 237:f3da66175598 191 /* Process Unlocked */
mbed_official 237:f3da66175598 192 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 193
mbed_official 237:f3da66175598 194 return HAL_OK;
mbed_official 237:f3da66175598 195 }
mbed_official 237:f3da66175598 196
mbed_official 237:f3da66175598 197 /**
mbed_official 237:f3da66175598 198 * @brief Enables I2C wakeup from stop mode.
mbed_official 237:f3da66175598 199 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 200 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 201 * @retval HAL status
mbed_official 237:f3da66175598 202 */
mbed_official 237:f3da66175598 203 HAL_StatusTypeDef HAL_I2CEx_EnableWakeUp (I2C_HandleTypeDef *hi2c)
mbed_official 237:f3da66175598 204 {
mbed_official 237:f3da66175598 205 /* Check the parameters */
mbed_official 237:f3da66175598 206 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 207
mbed_official 237:f3da66175598 208 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 209 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 210 {
mbed_official 237:f3da66175598 211 return HAL_BUSY;
mbed_official 237:f3da66175598 212 }
mbed_official 237:f3da66175598 213
mbed_official 237:f3da66175598 214 /* Process Locked */
mbed_official 237:f3da66175598 215 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 216
mbed_official 237:f3da66175598 217 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 218
mbed_official 237:f3da66175598 219 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 220 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 221
mbed_official 237:f3da66175598 222 /* Enable wakeup from stop mode */
mbed_official 237:f3da66175598 223 hi2c->Instance->CR1 |= I2C_CR1_WUPEN;
mbed_official 237:f3da66175598 224
mbed_official 237:f3da66175598 225 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 226
mbed_official 237:f3da66175598 227 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 228
mbed_official 237:f3da66175598 229 /* Process Unlocked */
mbed_official 237:f3da66175598 230 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 231
mbed_official 237:f3da66175598 232 return HAL_OK;
mbed_official 237:f3da66175598 233 }
mbed_official 237:f3da66175598 234
mbed_official 237:f3da66175598 235
mbed_official 237:f3da66175598 236 /**
mbed_official 237:f3da66175598 237 * @brief Disables I2C wakeup from stop mode.
mbed_official 237:f3da66175598 238 * @param hi2c : pointer to a I2C_HandleTypeDef structure that contains
mbed_official 237:f3da66175598 239 * the configuration information for the specified I2Cx peripheral.
mbed_official 237:f3da66175598 240 * @retval HAL status
mbed_official 237:f3da66175598 241 */
mbed_official 237:f3da66175598 242 HAL_StatusTypeDef HAL_I2CEx_DisableWakeUp (I2C_HandleTypeDef *hi2c)
mbed_official 237:f3da66175598 243 {
mbed_official 237:f3da66175598 244 /* Check the parameters */
mbed_official 237:f3da66175598 245 assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
mbed_official 237:f3da66175598 246
mbed_official 237:f3da66175598 247 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 248 || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_TX) || (hi2c->State == HAL_I2C_STATE_SLAVE_BUSY_RX))
mbed_official 237:f3da66175598 249 {
mbed_official 237:f3da66175598 250 return HAL_BUSY;
mbed_official 237:f3da66175598 251 }
mbed_official 237:f3da66175598 252
mbed_official 237:f3da66175598 253 /* Process Locked */
mbed_official 237:f3da66175598 254 __HAL_LOCK(hi2c);
mbed_official 237:f3da66175598 255
mbed_official 237:f3da66175598 256 hi2c->State = HAL_I2C_STATE_BUSY;
mbed_official 237:f3da66175598 257
mbed_official 237:f3da66175598 258 /* Disable the selected I2C peripheral */
mbed_official 237:f3da66175598 259 __HAL_I2C_DISABLE(hi2c);
mbed_official 237:f3da66175598 260
mbed_official 237:f3da66175598 261 /* Enable wakeup from stop mode */
mbed_official 237:f3da66175598 262 hi2c->Instance->CR1 &= ~(I2C_CR1_WUPEN);
mbed_official 237:f3da66175598 263
mbed_official 237:f3da66175598 264 __HAL_I2C_ENABLE(hi2c);
mbed_official 237:f3da66175598 265
mbed_official 237:f3da66175598 266 hi2c->State = HAL_I2C_STATE_READY;
mbed_official 237:f3da66175598 267
mbed_official 237:f3da66175598 268 /* Process Unlocked */
mbed_official 237:f3da66175598 269 __HAL_UNLOCK(hi2c);
mbed_official 237:f3da66175598 270
mbed_official 237:f3da66175598 271 return HAL_OK;
mbed_official 237:f3da66175598 272 }
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 #endif /* HAL_I2C_MODULE_ENABLED */
mbed_official 237:f3da66175598 283 /**
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 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/