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.

Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_i2c.c	Mon Sep 28 10:30:09 2015 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_STM32F0/stm32f0xx_hal_i2c.c	Mon Sep 28 10:45:10 2015 +0100
@@ -2,14 +2,14 @@
   ******************************************************************************
   * @file    stm32f0xx_hal_i2c.c
   * @author  MCD Application Team
-  * @version V1.2.0
-  * @date    11-December-2014
+  * @version V1.3.0
+  * @date    26-June-2015
   * @brief   I2C HAL module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of the Inter Integrated Circuit (I2C) peripheral:
   *           + Initialization and de-initialization functions
   *           + IO operation functions
-  *           + Peripheral State functions
+  *           + Peripheral State and Errors functions
   *         
   @verbatim
   ==============================================================================
@@ -21,32 +21,32 @@
     (#) Declare a I2C_HandleTypeDef handle structure, for example:
         I2C_HandleTypeDef  hi2c; 
 
-    (#)Initialize the I2C low level resources by implement the HAL_I2C_MspInit ()API:
-        (++) Enable the I2Cx interface clock
-        (++) I2C pins configuration
+    (#)Initialize the I2C low level resources by implementing the HAL_I2C_MspInit() API:
+        (##) Enable the I2Cx interface clock
+        (##) I2C pins configuration
             (+++) Enable the clock for the I2C GPIOs
             (+++) Configure I2C pins as alternate function open-drain
-        (++) NVIC configuration if you need to use interrupt process
+        (##) NVIC configuration if you need to use interrupt process
             (+++) Configure the I2Cx interrupt priority
             (+++) Enable the NVIC I2C IRQ Channel
-        (++) DMA Configuration if you need to use DMA process
+        (##) DMA Configuration if you need to use DMA process
             (+++) Declare a DMA_HandleTypeDef handle structure for the transmit or receive channel
             (+++) Enable the DMAx interface clock using
             (+++) Configure the DMA handle parameters
             (+++) Configure the DMA Tx or Rx channel
-            (+++) Associate the initilalized DMA handle to the hi2c DMA Tx or Rx handle
-            (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx or Rx channel
-
-    (#) Configure the Communication Clock Timing, Own Address1, Master Adressing Mode, Dual Addressing mode,
+            (+++) Associate the initialized DMA handle to the hi2c DMA Tx or Rx handle
+            (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on 
+                  the DMA Tx or Rx channel
+
+    (#) Configure the Communication Clock Timing, Own Address1, Master Addressing Mode, Dual Addressing mode,
         Own Address2, Own Address2 Mask, General call and Nostretch mode in the hi2c Init structure.
 
-    (#) Initialize the I2C registers by calling the HAL_I2C_Init() API:
-        (++) These API s configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
-             by calling the customed HAL_I2C_MspInit(&hi2c) API.
+    (#) Initialize the I2C registers by calling the HAL_I2C_Init(), configures also the low level Hardware 
+        (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_I2C_MspInit(&hi2c) API.
 
     (#) To check if target device is ready for communication, use the function HAL_I2C_IsDeviceReady()
 
-    (#) For I2C IO and IO MEM operations, three modes of operations are available within this driver :
+    (#) For I2C IO and IO MEM operations, three operation modes are available within this driver :
 
     *** Polling mode IO operation ***
     =================================
@@ -66,70 +66,70 @@
     *** Interrupt mode IO operation ***
     ===================================
     [..]
-      (+) Transmit in master mode an amount of data in non blocking mode using HAL_I2C_Master_Transmit_IT()
-      (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
-      (+) Receive in master mode an amount of data in non blocking mode using HAL_I2C_Master_Receive_IT()
-      (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
-      (+) Transmit in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Transmit_IT()
-      (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
-      (+) Receive in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Receive_IT()
-      (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
+      (+) Transmit in master mode an amount of data in non-blocking mode using HAL_I2C_Master_Transmit_IT()
+      (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback()
+      (+) Receive in master mode an amount of data in non-blocking mode using HAL_I2C_Master_Receive_IT()
+      (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback()
+      (+) Transmit in slave mode an amount of data in non-blocking mode using HAL_I2C_Slave_Transmit_IT()
+      (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback()
+      (+) Receive in slave mode an amount of data in non-blocking mode using HAL_I2C_Slave_Receive_IT()
+      (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback()
       (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
-           add his own code by customization of function pointer HAL_I2C_ErrorCallback
+           add his own code by customization of function pointer HAL_I2C_ErrorCallback()
 
     *** Interrupt mode IO MEM operation ***
     =======================================
     [..]
-      (+) Write an amount of data in no-blocking mode with Interrupt to a specific memory address using
+      (+) Write an amount of data in non-blocking mode with Interrupt to a specific memory address using
           HAL_I2C_Mem_Write_IT()
-      (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
-      (+) Read an amount of data in no-blocking mode with Interrupt from a specific memory address using
+      (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback()
+      (+) Read an amount of data in non-blocking mode with Interrupt from a specific memory address using
           HAL_I2C_Mem_Read_IT()
-      (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
+      (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback()
       (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
-           add his own code by customization of function pointer HAL_I2C_ErrorCallback
+           add his own code by customization of function pointer HAL_I2C_ErrorCallback()
 
     *** DMA mode IO operation ***
     ==============================
     [..]
-      (+) Transmit in master mode an amount of data in non blocking mode (DMA) using
+      (+) Transmit in master mode an amount of data in non-blocking mode (DMA) using
           HAL_I2C_Master_Transmit_DMA()
-      (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback
-      (+) Receive in master mode an amount of data in non blocking mode (DMA) using
+      (+) At transmission end of transfer HAL_I2C_MasterTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback()
+      (+) Receive in master mode an amount of data in non-blocking mode (DMA) using
           HAL_I2C_Master_Receive_DMA()
-      (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback
-      (+) Transmit in slave mode an amount of data in non blocking mode (DMA) using
+      (+) At reception end of transfer HAL_I2C_MasterRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback()
+      (+) Transmit in slave mode an amount of data in non-blocking mode (DMA) using
           HAL_I2C_Slave_Transmit_DMA()
-      (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback
-      (+) Receive in slave mode an amount of data in non blocking mode (DMA) using
+      (+) At transmission end of transfer HAL_I2C_SlaveTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback()
+      (+) Receive in slave mode an amount of data in non-blocking mode (DMA) using
           HAL_I2C_Slave_Receive_DMA()
-      (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback
+      (+) At reception end of transfer HAL_I2C_SlaveRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback()
       (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
-           add his own code by customization of function pointer HAL_I2C_ErrorCallback
+           add his own code by customization of function pointer HAL_I2C_ErrorCallback()
 
     *** DMA mode IO MEM operation ***
     =================================
     [..]
-      (+) Write an amount of data in no-blocking mode with DMA to a specific memory address using
+      (+) Write an amount of data in non-blocking mode with DMA to a specific memory address using
           HAL_I2C_Mem_Write_DMA()
-      (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback
-      (+) Read an amount of data in no-blocking mode with DMA from a specific memory address using
+      (+) At MEM end of write transfer HAL_I2C_MemTxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback()
+      (+) Read an amount of data in non-blocking mode with DMA from a specific memory address using
           HAL_I2C_Mem_Read_DMA()
-      (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can
-           add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback
+      (+) At MEM end of read transfer HAL_I2C_MemRxCpltCallback() is executed and user can
+           add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback()
       (+) In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can
-           add his own code by customization of function pointer HAL_I2C_ErrorCallback
+           add his own code by customization of function pointer HAL_I2C_ErrorCallback()
 
 
      *** I2C HAL driver macros list ***
@@ -137,12 +137,12 @@
      [..]
        Below the list of most used macros in I2C HAL driver.
 
-      (+) __HAL_I2C_ENABLE: Enable the I2C peripheral
-      (+) __HAL_I2C_DISABLE: Disable the I2C peripheral
-      (+) __HAL_I2C_GET_FLAG : Checks whether the specified I2C flag is set or not
-      (+) __HAL_I2C_CLEAR_FLAG : Clears the specified I2C pending flag
-      (+) __HAL_I2C_ENABLE_IT: Enables the specified I2C interrupt
-      (+) __HAL_I2C_DISABLE_IT: Disables the specified I2C interrupt
+      (+) __HAL_I2C_ENABLE:      Enable the I2C peripheral
+      (+) __HAL_I2C_DISABLE:     Disable the I2C peripheral
+      (+) __HAL_I2C_GET_FLAG:    Checks whether the specified I2C flag is set or not
+      (+) __HAL_I2C_CLEAR_FLAG:  Clear the specified I2C pending flag
+      (+) __HAL_I2C_ENABLE_IT:   Enable the specified I2C interrupt
+      (+) __HAL_I2C_DISABLE_IT:  Disable the specified I2C interrupt
 
      [..]
        (@) You can refer to the I2C HAL driver header file for more useful macros
@@ -151,7 +151,7 @@
   ******************************************************************************
   * @attention
   *
-  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * are permitted provided that the following conditions are met:
@@ -185,7 +185,7 @@
   * @{
   */
 
-/** @defgroup I2C I2C HAL module driver
+/** @defgroup I2C I2C
   * @brief I2C HAL module driver
   * @{
   */
@@ -230,9 +230,9 @@
 static HAL_StatusTypeDef I2C_RequestMemoryWrite(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout);
 static HAL_StatusTypeDef I2C_RequestMemoryRead(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout);
 static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
+static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout);
 static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout);
 static HAL_StatusTypeDef I2C_WaitOnSTOPFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout);
-static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout);
 static HAL_StatusTypeDef I2C_IsAcknowledgeFailed(I2C_HandleTypeDef *hi2c, uint32_t Timeout);
 
 static HAL_StatusTypeDef I2C_MasterTransmit_ISR(I2C_HandleTypeDef *hi2c);
@@ -246,7 +246,7 @@
   * @}
   */ 
   
-/* Exported functions ---------------------------------------------------------*/
+/* Exported functions --------------------------------------------------------*/
 
 /** @defgroup I2C_Exported_Functions I2C Exported Functions
   * @{
@@ -257,10 +257,10 @@
  *
 @verbatim    
  ===============================================================================
-              ##### Initialization and Configuration functions #####
+              ##### Initialization and de-initialization functions #####
  ===============================================================================
     [..]  This subsection provides a set of functions allowing to initialize and 
-          de-initialiaze the I2Cx peripheral:
+          deinitialize the I2Cx peripheral:
 
       (+) User must Implement HAL_I2C_MspInit() function in which he configures 
           all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
@@ -277,7 +277,7 @@
         (++) Nostretch mode
 
       (+) Call the function HAL_I2C_DeInit() to restore the default configuration 
-          of the selected I2Cx periperal.       
+          of the selected I2Cx peripheral.       
 
 @endverbatim
   * @{
@@ -285,7 +285,7 @@
 
 /**
   * @brief  Initializes the I2C according to the specified parameters 
-  *         in the I2C_InitTypeDef and create the associated handle.
+  *         in the I2C_InitTypeDef and initialize the associated handle.
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @retval HAL status
@@ -310,6 +310,9 @@
 
   if(hi2c->State == HAL_I2C_STATE_RESET)
   {
+    /* Allocate lock resource and initialize it */
+    hi2c->Lock = HAL_UNLOCKED;
+    
     /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
     HAL_I2C_MspInit(hi2c);
   }
@@ -365,7 +368,7 @@
 }
 
 /**
-  * @brief  DeInitializes the I2C peripheral. 
+  * @brief  DeInitialize the I2C peripheral. 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @retval HAL status
@@ -390,6 +393,7 @@
   HAL_I2C_MspDeInit(hi2c);
   
   hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
+
   hi2c->State = HAL_I2C_STATE_RESET;
   
   /* Release Lock */
@@ -399,27 +403,27 @@
 }
 
 /**
-  * @brief I2C MSP Init.
+  * @brief Initialize the I2C MSP.
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @retval None
   */
  __weak void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_MspInit could be implemented in the user file
    */ 
 }
 
 /**
-  * @brief I2C MSP DeInit
+  * @brief DeInitialize the I2C MSP.
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @retval None
   */
  __weak void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_MspDeInit could be implemented in the user file
    */ 
 }
@@ -439,7 +443,7 @@
     This subsection provides a set of functions allowing to manage the I2C data 
     transfers.
 
-    (#) There is two mode of transfer:
+    (#) There are two modes of transfer:
        (++) Blocking mode : The communication is performed in the polling mode. 
             The status of all data processing is returned by the same function 
             after finishing transfer.  
@@ -474,7 +478,7 @@
         (++) HAL_I2C_Mem_Write_DMA()
         (++) HAL_I2C_Mem_Read_DMA()
 
-    (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode:
+    (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
         (++) HAL_I2C_MemTxCpltCallback()
         (++) HAL_I2C_MemRxCpltCallback()
         (++) HAL_I2C_MasterTxCpltCallback()
@@ -592,7 +596,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     hi2c->State = HAL_I2C_STATE_READY; 	  
     
@@ -706,7 +710,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
     
     hi2c->State = HAL_I2C_STATE_READY; 	  
     
@@ -963,7 +967,7 @@
 }
 
 /**
-  * @brief  Transmit in master mode an amount of data in no-blocking mode with Interrupt
+  * @brief  Transmit in master mode an amount of data in non-blocking mode with Interrupt
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1035,7 +1039,7 @@
 }
 
 /**
-  * @brief  Receive in master mode an amount of data in no-blocking mode with Interrupt
+  * @brief  Receive in master mode an amount of data in non-blocking mode with Interrupt
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1106,7 +1110,7 @@
 }
 
 /**
-  * @brief  Transmit in slave mode an amount of data in no-blocking mode with Interrupt 
+  * @brief  Transmit in slave mode an amount of data in non-blocking mode with Interrupt 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  pData: Pointer to data buffer
@@ -1156,7 +1160,7 @@
 }
 
 /**
-  * @brief  Receive in slave mode an amount of data in no-blocking mode with Interrupt 
+  * @brief  Receive in slave mode an amount of data in non-blocking mode with Interrupt 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  pData: Pointer to data buffer
@@ -1206,7 +1210,7 @@
 }
 
 /**
-  * @brief  Transmit in master mode an amount of data in no-blocking mode with DMA
+  * @brief  Transmit in master mode an amount of data in non-blocking mode with DMA
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1297,7 +1301,7 @@
 }
 
 /**
-  * @brief  Receive in master mode an amount of data in no-blocking mode with DMA 
+  * @brief  Receive in master mode an amount of data in non-blocking mode with DMA 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1378,7 +1382,7 @@
 }
 
 /**
-  * @brief  Transmit in slave mode an amount of data in no-blocking mode with DMA 
+  * @brief  Transmit in slave mode an amount of data in non-blocking mode with DMA 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  pData: Pointer to data buffer
@@ -1464,7 +1468,7 @@
 }
 
 /**
-  * @brief  Receive in slave mode an amount of data in no-blocking mode with DMA 
+  * @brief  Receive in slave mode an amount of data in non-blocking mode with DMA 
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  pData: Pointer to data buffer
@@ -1533,7 +1537,6 @@
     return HAL_BUSY;
   }
 }
-
 /**
   * @brief  Write an amount of data in blocking mode to a specific memory address
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
@@ -1662,7 +1665,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     hi2c->State = HAL_I2C_STATE_READY; 	  
     
@@ -1800,7 +1803,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
     
     hi2c->State = HAL_I2C_STATE_READY;
     
@@ -1814,9 +1817,8 @@
     return HAL_BUSY;
   }
 }
-
 /**
-  * @brief  Write an amount of data in no-blocking mode with Interrupt to a specific memory address
+  * @brief  Write an amount of data in non-blocking mode with Interrupt to a specific memory address
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1909,7 +1911,7 @@
 }
 
 /**
-  * @brief  Read an amount of data in no-blocking mode with Interrupt from a specific memory address
+  * @brief  Read an amount of data in non-blocking mode with Interrupt from a specific memory address
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -1999,9 +2001,8 @@
     return HAL_BUSY; 
   }   
 }
-
 /**
-  * @brief  Write an amount of data in no-blocking mode with DMA to a specific memory address
+  * @brief  Write an amount of data in non-blocking mode with DMA to a specific memory address
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -2110,7 +2111,7 @@
 }
 
 /**
-  * @brief  Reads an amount of data in no-blocking mode with DMA from a specific memory address.
+  * @brief  Reads an amount of data in non-blocking mode with DMA from a specific memory address.
   * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *                the configuration information for the specified I2C.
   * @param  DevAddress: Target device address
@@ -2241,7 +2242,7 @@
     do
     {
       /* Generate Start */
-      hi2c->Instance->CR2 = __HAL_I2C_GENERATE_START(hi2c->Init.AddressingMode,DevAddress);
+      hi2c->Instance->CR2 = I2C_GENERATE_START(hi2c->Init.AddressingMode,DevAddress);
       
       /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
       /* Wait until STOPF flag is set or a NACK flag is set*/
@@ -2325,6 +2326,13 @@
     return HAL_BUSY;
   }
 }
+/**
+  * @}
+  */
+
+/** @defgroup I2C_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
+ * @{
+ */   
 
 /**
   * @brief  This function handles I2C event interrupt request.
@@ -2408,7 +2416,7 @@
   }
 
   /* Call the Error Callback in case of Error detected */
-  if(hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
+  if((hi2c->ErrorCode & (HAL_I2C_ERROR_BERR | HAL_I2C_ERROR_OVR | HAL_I2C_ERROR_ARLO)) !=  HAL_I2C_ERROR_NONE)
   {
     hi2c->State = HAL_I2C_STATE_READY;
     
@@ -2424,7 +2432,7 @@
   */
  __weak void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */ 
 }
@@ -2437,7 +2445,7 @@
   */
 __weak void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */
 }
@@ -2449,7 +2457,7 @@
   */
  __weak void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */ 
 }
@@ -2462,7 +2470,7 @@
   */
 __weak void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */
 }
@@ -2475,7 +2483,7 @@
   */
  __weak void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */ 
 }
@@ -2488,7 +2496,7 @@
   */
 __weak void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_TxCpltCallback could be implemented in the user file
    */
 }
@@ -2501,7 +2509,7 @@
   */
  __weak void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
 {
-  /* NOTE : This function Should not be modified, when the callback is needed,
+  /* NOTE : This function should not be modified, when the callback is needed,
             the HAL_I2C_ErrorCallback could be implemented in the user file
    */ 
 }
@@ -2518,7 +2526,7 @@
             ##### Peripheral State and Errors functions #####
  ===============================================================================  
     [..]
-    This subsection permit to get in run-time the status of the peripheral 
+    This subsection permits to get in run-time the status of the peripheral 
     and the data flow.
 
 @endverbatim
@@ -2526,20 +2534,22 @@
   */
 
 /**
-  * @brief  Returns the I2C state.
-  * @param  hi2c : I2C handle
+  * @brief  Return the I2C handle state.
+  * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
+  *                the configuration information for the specified I2C.
   * @retval HAL state
   */
 HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c)
 {
+  /* Return I2C handle state */
   return hi2c->State;
 }
 
 /**
-* @brief  Return the I2C error code
-* @param  hi2c : pointer to a I2C_HandleTypeDef structure that contains
+* @brief  Return the I2C error code.
+  * @param  hi2c : Pointer to a I2C_HandleTypeDef structure that contains
   *              the configuration information for the specified I2C.
-* @retval I2C Error Code
+  * @retval I2C Error Code
 */
 uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c)
 {
@@ -2631,7 +2641,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
 
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     hi2c->State = HAL_I2C_STATE_READY;
 
@@ -2738,7 +2748,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
       
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
     
     hi2c->State = HAL_I2C_STATE_READY;
 
@@ -2949,13 +2959,13 @@
   if(MemAddSize == I2C_MEMADD_SIZE_8BIT)
   {
     /* Send Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_LSB(MemAddress);    
+    hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);    
   }      
   /* If Memory address size is 16Bit */
   else
   {
     /* Send MSB of Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_MSB(MemAddress); 
+    hi2c->Instance->TXDR = I2C_MEM_ADD_MSB(MemAddress); 
     
     /* Wait until TXIS flag is set */
     if(I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout) != HAL_OK)
@@ -2971,7 +2981,7 @@
     }
     
     /* Send LSB of Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_LSB(MemAddress);  
+    hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);  
   }
   
   /* Wait until TCR flag is set */
@@ -3014,13 +3024,13 @@
   if(MemAddSize == I2C_MEMADD_SIZE_8BIT)
   {
     /* Send Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_LSB(MemAddress);    
+    hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);    
   }      
-  /* If Mememory address size is 16Bit */
+  /* If Memory address size is 16Bit */
   else
   {
     /* Send MSB of Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_MSB(MemAddress); 
+    hi2c->Instance->TXDR = I2C_MEM_ADD_MSB(MemAddress); 
     
     /* Wait until TXIS flag is set */
     if(I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout) != HAL_OK)
@@ -3036,7 +3046,7 @@
     }
     
     /* Send LSB of Memory Address */
-    hi2c->Instance->TXDR = __HAL_I2C_MEM_ADD_LSB(MemAddress);  
+    hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);  
   }
   
   /* Wait until TC flag is set */
@@ -3092,7 +3102,7 @@
       __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
           
       /* Clear Configuration Register 2 */
-      __HAL_I2C_RESET_CR2(hi2c);
+      I2C_RESET_CR2(hi2c);
 
       hi2c->XferCount = 0;
     
@@ -3149,7 +3159,7 @@
         __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
             
         /* Clear Configuration Register 2 */
-        __HAL_I2C_RESET_CR2(hi2c);
+        I2C_RESET_CR2(hi2c);
 
         hi2c->XferCount = 0;
 
@@ -3183,7 +3193,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     /* Disable DMA Request */
     hi2c->Instance->CR1 &= ~I2C_CR1_TXDMAEN; 
@@ -3299,7 +3309,7 @@
       __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
           
       /* Clear Configuration Register 2 */
-      __HAL_I2C_RESET_CR2(hi2c);
+      I2C_RESET_CR2(hi2c);
     
       hi2c->XferCount = 0;
     
@@ -3362,7 +3372,7 @@
         __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
             
         /* Clear Configuration Register 2 */
-        __HAL_I2C_RESET_CR2(hi2c);
+        I2C_RESET_CR2(hi2c);
       
         hi2c->XferCount = 0;
       
@@ -3397,7 +3407,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
   
     /* Disable DMA Request */
     hi2c->Instance->CR1 &= ~I2C_CR1_RXDMAEN; 
@@ -3514,7 +3524,7 @@
       __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
           
       /* Clear Configuration Register 2 */
-      __HAL_I2C_RESET_CR2(hi2c);
+      I2C_RESET_CR2(hi2c);
 
       hi2c->XferCount = 0;
     
@@ -3571,7 +3581,7 @@
         __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
             
         /* Clear Configuration Register 2 */
-        __HAL_I2C_RESET_CR2(hi2c);
+        I2C_RESET_CR2(hi2c);
 
         hi2c->XferCount = 0;
 
@@ -3605,7 +3615,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     /* Disable DMA Request */
     hi2c->Instance->CR1 &= ~I2C_CR1_TXDMAEN; 
@@ -3670,7 +3680,7 @@
       __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
           
       /* Clear Configuration Register 2 */
-      __HAL_I2C_RESET_CR2(hi2c);
+      I2C_RESET_CR2(hi2c);
     
       hi2c->XferCount = 0;
     
@@ -3733,7 +3743,7 @@
         __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
             
         /* Clear Configuration Register 2 */
-        __HAL_I2C_RESET_CR2(hi2c);
+        I2C_RESET_CR2(hi2c);
       
         hi2c->XferCount = 0;
 
@@ -3767,7 +3777,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
   	
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
   
     /* Disable DMA Request */
     hi2c->Instance->CR1 &= ~I2C_CR1_RXDMAEN; 
@@ -3953,7 +3963,7 @@
       __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
 
       /* Clear Configuration Register 2 */
-      __HAL_I2C_RESET_CR2(hi2c);
+      I2C_RESET_CR2(hi2c);
 
       hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
       hi2c->State= HAL_I2C_STATE_READY;
@@ -4030,7 +4040,7 @@
     __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
 
     /* Clear Configuration Register 2 */
-    __HAL_I2C_RESET_CR2(hi2c);
+    I2C_RESET_CR2(hi2c);
 
     hi2c->ErrorCode = HAL_I2C_ERROR_AF;
     hi2c->State= HAL_I2C_STATE_READY;