X_NUCLEO_NFC02A1 library for M24LR

Dependencies:   ST_INTERFACES

Dependents:   HelloWorld_NFC02A1_mbedOS HelloWorld_NFC02A1laatste HelloWorld_NFC02A1

Fork of X_NUCLEO_NFC02A1 by ST Expansion SW Team

X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board Firmware Package

Introduction

This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board based on M24LR.

Firmware Library

Class X_NUCLEO_NFC02A1 is intended to represent the Dynamic NFC Tag Expansion Board with the same name.
It provides an API to access to the M24LR component and to the three onboard LEDs.
It is intentionally implemented as a singleton because only one X_NUCLEO_NFC02A1 at a time might be deployed in a HW component stack.
The library also provides an implementation of the NDEF library API for M24LR, providing an simple way to read/write NDEF formatted messages from/to the M24LR dynamic NFC tag.

Example application

Hello World is a simple application to program and read an URI from the NFC tag.

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Wed Jul 12 12:34:12 2017 +0000
Parent:
7:b876cdcf095a
Commit message:
Updated to fit ARM mbed coding style.

Changed in this revision

XNucleoNFC02A1.cpp Show annotated file Show diff for this revision Revisions of this file
XNucleoNFC02A1.h Show annotated file Show diff for this revision Revisions of this file
m24lr/M24LR.cpp Show annotated file Show diff for this revision Revisions of this file
m24lr/M24LR.h Show annotated file Show diff for this revision Revisions of this file
m24lr/NDefNfcTagM24LR.cpp Show annotated file Show diff for this revision Revisions of this file
m24lr/NDefNfcTagM24LR.h Show annotated file Show diff for this revision Revisions of this file
diff -r b876cdcf095a -r 7c4cf671960b XNucleoNFC02A1.cpp
--- a/XNucleoNFC02A1.cpp	Tue Jul 11 15:23:56 2017 +0000
+++ b/XNucleoNFC02A1.cpp	Wed Jul 12 12:34:12 2017 +0000
@@ -51,7 +51,7 @@
 
 XNucleoNFC02A1 *XNucleoNFC02A1::mInstance = NULL;
 
-XNucleoNFC02A1* XNucleoNFC02A1::instance(DevI2C *devI2C,
+XNucleoNFC02A1* XNucleoNFC02A1::instance(DevI2C &devI2C,
 		const PinName &gpoName,
 		const PinName &RFDisableName, const PinName &led1Name,
 		const PinName &led2Name, const PinName &led3Name) {
diff -r b876cdcf095a -r 7c4cf671960b XNucleoNFC02A1.h
--- a/XNucleoNFC02A1.h	Tue Jul 11 15:23:56 2017 +0000
+++ b/XNucleoNFC02A1.h	Wed Jul 12 12:34:12 2017 +0000
@@ -73,7 +73,7 @@
 	 * @param led2Name Pin to control the led1 status.
 	 * @param led3Name Pin to control the led1 status.
 	 */
-	XNucleoNFC02A1(DevI2C *devI2C,
+	XNucleoNFC02A1(DevI2C &devI2C,
 			const PinName &gpoName,	const PinName &RFDisableName,
 			const PinName &led1Name, const PinName &led2Name,
 			const PinName &led3Name):
@@ -99,7 +99,7 @@
 	 * @param led2Name Pin to control the led1 status.
 	 * @param led3Name Pin to control the led1 status.
 	 */
-	static XNucleoNFC02A1* instance(DevI2C *devI2C,
+	static XNucleoNFC02A1* instance(DevI2C &devI2C,
 			const PinName &gpoName = DEFAULT_GPO_PIN,
  			const PinName &RFDisableName = DEFAULT_RF_DISABLE_PIN,
  			const PinName &led1Name = DEFAULT_LED1_PIN,
diff -r b876cdcf095a -r 7c4cf671960b m24lr/M24LR.cpp
--- a/m24lr/M24LR.cpp	Tue Jul 11 15:23:56 2017 +0000
+++ b/m24lr/M24LR.cpp	Wed Jul 12 12:34:12 2017 +0000
@@ -35,28 +35,25 @@
   ******************************************************************************
   */
 
-
-
 #include "M24LR.h"
 
 uint8_t M24LR::NfctagInitialized = 0; 
 
-
 /**
-  * @brief  This function activate Energy Harvesting mode
+  * @brief  Activate Energy Harvesting mode.
   */
 void M24LR::enable_energy_harvesting( void )
 {
   /* Initialise M24LR Board */
   
-    /* Enable Energy Harvesting */
-    i2c_set_EH( );
+  /* Enable Energy Harvesting */
+  i2c_set_EH( );
 
-    /* Store configuration in non Volatile Memory */
-    i2c_enable_EH_mode();
-    i2c_write_EH_cfg( M24LR_EH_Cfg_6MA );
-  
+  /* Store configuration in non Volatile Memory */
+  i2c_enable_EH_mode();
+  i2c_write_EH_cfg( M24LR_EH_Cfg_6MA );
 }
+
 /**
   * @brief  Set M24LR nfctag Initialization
   * @param  None
@@ -66,28 +63,22 @@
 { 
   uint8_t nfctag_id = 0;
   
-  if( NfctagInitialized == 0 )
-  {
-    
+  if ( NfctagInitialized == 0 ) {
     /* M24LR Init */
-   if( i2c_init() != NFCTAG_OK )
-    {
+    if ( i2c_init() != NFCTAG_OK ) {
       return NFCTAG_ERROR;
     }
-    
+      
     /* Check M24LR driver ID */
-   i2c_read_id(&nfctag_id);
-    if( (nfctag_id == I_AM_M24LR04) || (nfctag_id == I_AM_M24LR16) || (nfctag_id == I_AM_M24LR64) )
-    {
+    i2c_read_id(&nfctag_id);
+    if ( (nfctag_id == I_AM_M24LR04) || (nfctag_id == I_AM_M24LR16) || (nfctag_id == I_AM_M24LR64) ) {
       NfctagInitialized = 1;
-     // Nfctag_Drv = &M24lr_i2c_Drv;
-     // Nfctag_Drv->pData = &M24lr_i2c_ExtDrv;
-    }
-    else
-    {
+      // Nfctag_Drv = &M24lr_i2c_Drv;
+      // Nfctag_Drv->pData = &M24lr_i2c_ExtDrv;
+    } else {
       NfctagInitialized = 0;
-     // Nfctag_Drv = NULL;
-     // NfctagInitialized = 0;
+      // Nfctag_Drv = NULL;
+      // NfctagInitialized = 0;
       return NFCTAG_ERROR;
     }
   }
@@ -104,7 +95,7 @@
 {
   /* Configure the low level interface */
   return(NFCTAG_OK);
- // return mM24LR_IO.Init( );
+  //eturn mM24LR_IO.Init( );
 }
 
 /**
@@ -119,10 +110,11 @@
   /* Read ICRef on device */
   //return M24LR_i2c_read_register( pICRef, M24LR_ICREF_REG, 1 );
   /* Before calling this function M24LR must be ready, here is a check to detect an issue */
-   status = i2c_read_register(pBuffer, M24LR_ICREF_REG, 1);
+  status = i2c_read_register(pBuffer, M24LR_ICREF_REG, 1);
 
-  if (status  == 0)
+  if (status  == 0) {
     return NFCTAG_OK;
+  }
   return NFCTAG_TIMEOUT;
  
 }
@@ -135,18 +127,18 @@
 NFCTAG_StatusTypeDef M24LR::i2c_is_device_ready( const uint32_t Trials )
 {
   /* Test i2c with M24LR */
- // return mM24LR_IO.IsDeviceReady( M24LR_ADDR_DATA_I2C, Trials );
+  //return mM24LR_IO.IsDeviceReady( M24LR_ADDR_DATA_I2C, Trials );
   uint8_t status = 1;
   char buffer;
   while (status != 0) {
     /* for device is ready address in M24Lr is M24LR_ADDR_DATA_I2C */
-    status = dev_I2C->read(i2c_address_data, &buffer, 1, false);
+    status = dev_I2C.read(i2c_address_data, &buffer, 1, false);
   }
-  if ( status == 0 )
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  } else {
     return NFCTAG_TIMEOUT;
-  
+  }
 }
 
 /**
@@ -159,12 +151,9 @@
   NFCTAG_StatusTypeDef status = NFCTAG_ERROR;
   
   /* Configure GPO function on M24LR */
-  if( (ITConf & M24LR_IT_BUSY_MASK) == M24LR_IT_BUSY_MASK )
-  {
+  if ( (ITConf & M24LR_IT_BUSY_MASK) == M24LR_IT_BUSY_MASK ) {
     status = i2c_setRF_Busy( );
-  }
-  else if( (ITConf & M24LR_IT_WIP_MASK) == M24LR_IT_WIP_MASK )
-  {
+  } else if ( (ITConf & M24LR_IT_WIP_MASK) == M24LR_IT_WIP_MASK ) {
     status = i2c_set_RF_WIP( );
   }
   return status;
@@ -181,9 +170,7 @@
   NFCTAG_StatusTypeDef status;
   status = i2c_read_register(&reg_value, M24LR_CFG_REG, 1);
   
-
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -194,7 +181,6 @@
   return i2c_write_register( &reg_value, M24LR_CFG_REG, 1 );
 }
 
-
 /**
   * @brief  Get Configuration of M24LR GPO
   * @param  GPOStatus : 0x01 = RFBUSY, 0x02 = RFWIP
@@ -207,18 +193,14 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Extract RF WIP/BUSY information */
-  if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
-  {
+  if ( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK ) {
     *pGPOStatus = M24LR_IT_WIP_MASK;
-  }
-  else
-  {
+  } else {
     *pGPOStatus = M24LR_IT_BUSY_MASK;
   }
   
@@ -236,17 +218,17 @@
 {  
   int status;
   /* Before calling this function M24LR must be ready, here is a check to detect an issue */
-  if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
-  {
+  if ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {
     return NFCTAG_TIMEOUT;
   }
-  /* Rosarium : To check M24LR_ADDR_DATA_I2C is this case */
- /* return M24lr_IO_MemRead( pData, M24LR_ADDR_DATA_I2C, TarAddr, NbByte ); */
-   status = dev_I2C->i2c_read(pData, i2c_address_data, TarAddr, NbByte);
-    if ( status == 0 )
+  /* Rosarium: To check M24LR_ADDR_DATA_I2C is this case */
+  /* return M24lr_IO_MemRead( pData, M24LR_ADDR_DATA_I2C, TarAddr, NbByte ); */
+  status = dev_I2C.i2c_read(pData, i2c_address_data, TarAddr, NbByte);
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  } else {
     return NFCTAG_TIMEOUT;
+  }
 }
 
 /**
@@ -267,43 +249,42 @@
   uint8_t *pdata_index = (uint8_t *)pData;
   
   /* Before calling this function M24LR must be ready, here is a check to detect an issue */
-  if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
-  {
+  if ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {
     return NFCTAG_TIMEOUT;
   }
   
   /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
-  do
-  {
+  do {
     /* To write data in M24LR, data must be aligned on the same row in memory */
     /* align_mem_offset is used to copy only Bytes that are on the same row  in memory */
-    if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
-    {
+    if ( bytes_to_write > M24LR_PAGEWRITE_NBBYTE ) {
       /* DataSize higher than max page write, copy data by page */
       align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
-    }
-    else
-    {
+    } else {
       /* DataSize lower or equal to max page write, copy only last bytes */
       align_mem_offset = bytes_to_write;
     }
+
     /* Write align_mem_offset bytes in memory */
-    /* Rosarium to Check as the address here is 0xA6 rather than 0xAE */
-    /* Rosarium dev_I2C.i2c_write(pdata_index, M24LR_ADDR_DATA_I2C, mem_addr, align_mem_offset); */
-    status = dev_I2C->i2c_write(pdata_index, i2c_address_data, mem_addr, align_mem_offset);
+    /* Rosarium: to Check as the address here is 0xA6 rather than 0xAE */
+    /* dev_I2C.i2c_write(pdata_index, M24LR_ADDR_DATA_I2C, mem_addr, align_mem_offset); */
+    status = dev_I2C.i2c_write(pdata_index, i2c_address_data, mem_addr, align_mem_offset);
     
     /* update index, dest address, size for next write */
     pdata_index += align_mem_offset;
     mem_addr += align_mem_offset;
     bytes_to_write -= align_mem_offset;
+
     /* Poll until EEPROM is available */
-    while( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
+    while ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
   }
-  while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
-  if ( status == 0 )
+  while ( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  }
+  else {
     return NFCTAG_ERROR;
+  }
 }
 
 /**
@@ -319,17 +300,18 @@
   int status;
   
   /* Before calling any read function M24LR must be ready, here is a check to detect an issue */
-  if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
-  {
+  if ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {
     return NFCTAG_TIMEOUT;
   }
-   /* Read actual value of register */
-  status = dev_I2C->i2c_read(pData, i2c_address_syst, TarAddr, NbByte);
+  
+  /* Read actual value of register */
+  status = dev_I2C.i2c_read(pData, i2c_address_syst, TarAddr, NbByte);
   
-    if ( status == 0 )
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  } else {
     return NFCTAG_TIMEOUT;
+  }
 }
 
 /**
@@ -348,42 +330,41 @@
   uint8_t *pdata_index = (uint8_t *)pData;
   
   /* Before calling this function M24LR must be ready, here is a check to detect an issue */
-  if( i2c_is_device_ready( 1 ) != NFCTAG_OK )
-  {
+  if ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {
     return NFCTAG_TIMEOUT;
   }
   
   /* M24LR can write a maximum of 4 bytes in EEPROM per i2c communication */
-  do
-  {
+  do {
     /* To write data in M24LR, data must be aligned on the same row in memory */
     /* align_mem_offset is used to copy only Bytes that are on the same row  in memory */
-    if( bytes_to_write > M24LR_PAGEWRITE_NBBYTE )
-    {
+    if ( bytes_to_write > M24LR_PAGEWRITE_NBBYTE ) {
       /* DataSize higher than max page write, copy data by page */
       align_mem_offset = M24LR_PAGEWRITE_NBBYTE - (mem_addr % M24LR_PAGEWRITE_NBBYTE);
-    }
-    else
-    {
+    } else {
       /* DataSize lower or equal to max page write, copy only last bytes */
       align_mem_offset = bytes_to_write;
     }
+    
     /* Write align_mem_offset bytes in register */
-   // status = M24lr_IO_MemWrite( pdata_index, M24LR_ADDR_SYST_I2C, mem_addr, align_mem_offset );
-    status = dev_I2C->i2c_write(pdata_index, i2c_address_syst, mem_addr, align_mem_offset);
+    // status = M24lr_IO_MemWrite( pdata_index, M24LR_ADDR_SYST_I2C, mem_addr, align_mem_offset );
+    status = dev_I2C.i2c_write(pdata_index, i2c_address_syst, mem_addr, align_mem_offset);
+    
     /* update index, dest address, size for next write */
     pdata_index += align_mem_offset;
     mem_addr += align_mem_offset;
     bytes_to_write -= align_mem_offset;
+    
     /* Poll until EEPROM is available */
-    while( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
+    while ( i2c_is_device_ready( 1 ) != NFCTAG_OK ) {};
   }
-  while( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
+  while ( ( bytes_to_write > 0 ) && ( status == NFCTAG_OK ) );
   
-    if ( status == 0 )
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  } else {
     return NFCTAG_ERROR;
+  }
 }
 
 /**
@@ -399,23 +380,20 @@
   
   /* Read actual value of UID registers */
   status = i2c_read_register( areg_value, M24LR_UID_REG, 8 );
-  if( status != NFCTAG_OK )
-  {
+
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Store information in 2 WORD */
   pUid->MSB_UID = 0;
   
-  for( i = 0; i < 4; i++ )
-  {
+  for ( i = 0; i < 4; i++ ) {
     pUid->MSB_UID = (pUid->MSB_UID << 8) | areg_value[7 - i];
   }
-  
   pUid->LSB_UID = 0;
   
-  for( i = 0; i < 4; i++ )
-  {
+  for ( i = 0; i < 4; i++ ) {
     pUid->LSB_UID = (pUid->LSB_UID << 8) | areg_value[3 - i];
   }
   
@@ -456,8 +434,7 @@
 
   /* Read actual value of I2c Write Lock registers */
   status = i2c_read_register( areg_value, M24LR_LOCK_REG, 8 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -491,8 +468,7 @@
   
   /* Read actual WriteLockStatus */
   status = i2c_read_register( &reg_value, sector_write_lock_addr, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -520,8 +496,7 @@
   
   /* Read actual WriteLockStatus */
   status = i2c_read_register( &reg_value, sector_write_lock_addr, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -545,8 +520,7 @@
   /* Build I2C Message with Password + Validation code 0x09 + Password */
   ai2c_message[4] = 0x09;
   i = 0;
-  while( i < 4 )
-  {
+  while ( i < 4 ) {
     ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
     ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
     i++;
@@ -570,8 +544,7 @@
   /* Build I2C Message with Password + Validation code 0x07 + Password */
   ai2c_message[4] = 0x07;
   i = 0;
-  while( i < 4 ) 
-  {
+  while ( i < 4 ) {
     ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;
     ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;
     i++;
@@ -598,8 +571,7 @@
   
   /* Read actual value of SectorSecurityStatus register */
   status = i2c_read_register( &reg_value, sector_security_addr, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -647,8 +619,7 @@
   
   /* Read actual value of Mem_Size register */
   status = i2c_read_register( areg_value, M24LR_MEMSIZE_REG, 3 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -672,18 +643,14 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Extract RF WIP/BUSY information */
-  if( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK )
-  {
+  if ( (reg_value & M24LR_CFG_WIPBUSY_MASK) == M24LR_CFG_WIPBUSY_MASK ) {
     *pRf_Wip_Busy = M24LR_GPO_WIP;
-  }
-  else
-  {
+  } else {
     *pRf_Wip_Busy = M24LR_GPO_BUSY;
   }
 
@@ -701,9 +668,8 @@
   int status;
   
   /* Read actual value of CFG register */
-  status = dev_I2C->i2c_read( &reg_value, i2c_address_syst, (uint16_t)M24LR_CFG_REG, 1 );
-  if( status != 0 )
-  {
+  status = dev_I2C.i2c_read( &reg_value, i2c_address_syst, (uint16_t)M24LR_CFG_REG, 1 );
+  if ( status != 0 ) {
     return NFCTAG_TIMEOUT;
   }
   
@@ -712,13 +678,13 @@
   
   /* Write CFG register */
   status = i2c_write_register( &reg_value, M24LR_CFG_REG, 1 );
-  if ( status == 0 )
+  if ( status == 0 ) {
     return NFCTAG_OK;
-  else
+  } else {
     return NFCTAG_TIMEOUT;
+  }
 }
 
-
 /**
   * @brief  Get Energy harvesting mode status
   * @param  EH_mode : M24LR_EH_MODE_STATUS pointer of the data to store
@@ -731,18 +697,14 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Extract EH_mode configuration */
-  if( (reg_value & M24LR_CFG_EHMODE_MASK) == M24LR_CFG_EHMODE_MASK )
-  {
+  if ( (reg_value & M24LR_CFG_EHMODE_MASK) == M24LR_CFG_EHMODE_MASK ) {
     *pEH_mode = M24LR_EH_MODE_DISABLE;
-  }
-  else
-  {
+  } else {
     *pEH_mode = M24LR_EH_MODE_ENABLE;
   }
   
@@ -761,8 +723,7 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -785,8 +746,7 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -809,30 +769,32 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Extract Vout configuration for EH information */
   reg_value &= (M24LR_CFG_EHCFG1_MASK | M24LR_CFG_EHCFG0_MASK);
-  switch( reg_value )
-  {
-    case 0:
+  switch ( reg_value ) {
+    case 0: {
       *pEH_Cfg = M24LR_EH_Cfg_6MA;
       break;
-    case 1:
+    }
+    case 1: {
       *pEH_Cfg = M24LR_EH_Cfg_3MA;
       break;
-    case 2:
+    }
+    case 2: {
       *pEH_Cfg = M24LR_EH_Cfg_1MA;
       break;
-    case 3:
+    }
+    case 3: {
       *pEH_Cfg = M24LR_EH_Cfg_300UA;
       break;
-    
-    default:
+    }
+    default: {
       *pEH_Cfg = M24LR_EH_Cfg_6MA;
+    }
   } 
   
   return NFCTAG_OK;
@@ -850,8 +812,7 @@
   
   /* Read actual value of CFG register */
   status = i2c_read_register( &reg_value, M24LR_CFG_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -875,18 +836,14 @@
   
   /* Read actual value of CTRL register */
   status = i2c_read_register( &reg_value, M24LR_CTRL_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
   /* Extract EH information */
-  if( (reg_value & M24LR_CTRL_EHEN_MASK) == M24LR_CTRL_EHEN_MASK )
-  {
+  if ( (reg_value & M24LR_CTRL_EHEN_MASK) == M24LR_CTRL_EHEN_MASK ) {
     *pEH_Val = M24LR_EH_ENABLE;
-  }
-  else
-  {
+  } else {
     *pEH_Val = M24LR_EH_DISABLE;
   }
   
@@ -905,8 +862,7 @@
   
   /* Read actual value of CTRL register */
   status = i2c_read_register( &reg_value, M24LR_CTRL_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -929,8 +885,7 @@
   
   /* Read actual value of CTRL register */
   status = i2c_read_register( &reg_value, M24LR_CTRL_REG, 1 );
-  if( status != NFCTAG_OK )
-  {
+  if ( status != NFCTAG_OK ) {
     return status;
   }
   
@@ -950,19 +905,15 @@
 {
   NFCTAG_StatusTypeDef status;
   uint8_t reg_value = 0;
-  
+
   /* Read actual value of CTRL register */
   status = i2c_read_register( &reg_value, M24LR_CTRL_REG, 1 );
   
   /* Extract RF Field information */
-  if( status == NFCTAG_OK )
-  {
-    if( (reg_value & M24LR_CTRL_FIELD_MASK) == M24LR_CTRL_FIELD_MASK )
-    {
+  if ( status == NFCTAG_OK ) {
+    if ( (reg_value & M24LR_CTRL_FIELD_MASK) == M24LR_CTRL_FIELD_MASK ) {
       *pRF_Field = M24LR_FIELD_ON;
-    }
-    else
-    {
+    } else {
       *pRF_Field = M24LR_FIELD_OFF;
     }
     
@@ -986,37 +937,18 @@
   status = i2c_read_register( &reg_value, M24LR_CTRL_REG, 1 );
   
   /* Extract T-Prog information */
-  if( status == NFCTAG_OK )
-  {
-    if( (reg_value & M24LR_CTRL_TPROG_MASK) == M24LR_CTRL_TPROG_MASK )
-    {
+  if ( status == NFCTAG_OK ) {
+    if ( (reg_value & M24LR_CTRL_TPROG_MASK) == M24LR_CTRL_TPROG_MASK ) {
       *pT_Prog = M24LR_T_PROG_OK;
-    }
-    else
-    {
+    } else {
       *pT_Prog = M24LR_T_PROG_NO;
     }
 
     return NFCTAG_OK;
+  } else {
+    return status;
   }
-  else
-    return status;
 }
 
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
-
-/**
- * @}
- */
 
 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
diff -r b876cdcf095a -r 7c4cf671960b m24lr/M24LR.h
--- a/m24lr/M24LR.h	Tue Jul 11 15:23:56 2017 +0000
+++ b/m24lr/M24LR.h	Wed Jul 12 12:34:12 2017 +0000
@@ -204,12 +204,10 @@
   uint8_t PassCtrl;
 } M24LR_SECTOR_SEC;
 
-
-  /**
-  * @}
-  */
-  
-class   M24LR : public Nfc {
+/**
+ * @brief  M24LR class.
+ */
+class M24LR : public Nfc {
 public:
     NFCTAG_StatusTypeDef i2c_init( void );
     NFCTAG_StatusTypeDef i2c_read_id( uint8_t * const pICRef );
@@ -220,8 +218,7 @@
     NFCTAG_StatusTypeDef i2c_write_data( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
     NFCTAG_StatusTypeDef i2c_read_register( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
     NFCTAG_StatusTypeDef i2c_write_register( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte );
- 
-    
+
     /* Extended Functions */
     NFCTAG_StatusTypeDef i2c_read_UID( M24LR_UID * const pUid );
     NFCTAG_StatusTypeDef i2c_read_DSFID( uint8_t * const pDsfid );
@@ -251,53 +248,42 @@
     void enable_energy_harvesting( void );
     NFCTAG_StatusTypeDef initialization( void );
     
-    virtual int read_binary(uint16_t Offset, uint8_t NbByteToRead,
-            uint8_t *pBufferRead) {
-           return  i2c_read_data( pBufferRead, Offset, NbByteToRead );
+    virtual int read_binary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead) {
+        return  i2c_read_data( pBufferRead, Offset, NbByteToRead );
         
     }
-
-    virtual int update_binary(uint16_t Offset,
-            uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
-          return i2c_write_data( pDataToWrite, Offset, NbByteToWrite );
+    
+    virtual int update_binary(uint16_t Offset, uint8_t NbByteToWrite,uint8_t *pDataToWrite) {
+        return i2c_write_data( pDataToWrite, Offset, NbByteToWrite );
     }
     
-    M24LR(uint8_t const address, uint8_t const addressData, DevI2C *devI2C ):
+    M24LR(uint8_t const address, uint8_t const addressData, DevI2C &devI2C ):
       NDefTagUtil(*this), i2c_address_syst(address), i2c_address_data(addressData), dev_I2C(devI2C) {}
-    
-   
-   NDefLib::NDefNfcTag& get_NDef_tag(){
+
+    NDefLib::NDefNfcTag& get_NDef_tag(){
       return NDefTagUtil;
-  }
-   
-   
-   virtual int init(void *ptr) {
-                (void)ptr;
+    }
+
+    virtual int init(void *ptr) {
+        (void)ptr;
         return i2c_init();
     }
 
-  virtual int read_id(uint8_t *id) {
+    virtual int read_id(uint8_t *id) {
         return i2c_read_id(id);
     }
-  private:
-        static uint8_t NfctagInitialized;
-   
-   
-        /*
-         * Object implementing the interface to use the NDefLib.
-         */
-       NDefNfcTagM24LR NDefTagUtil;
-       
-       uint8_t i2c_address_syst;
-       uint8_t i2c_address_data;
-       DevI2C *dev_I2C;
+
+private:
+    static uint8_t NfctagInitialized;
+    /* Object implementing the interface to use the NDefLib. */
+    NDefNfcTagM24LR NDefTagUtil;
+    
+    uint8_t i2c_address_syst;
+    uint8_t i2c_address_data;
+    DevI2C &dev_I2C;
 };
-  
-  
 
-  
 #endif /* __M24LR_H */
 
 
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r b876cdcf095a -r 7c4cf671960b m24lr/NDefNfcTagM24LR.cpp
--- a/m24lr/NDefNfcTagM24LR.cpp	Tue Jul 11 15:23:56 2017 +0000
+++ b/m24lr/NDefNfcTagM24LR.cpp	Wed Jul 12 12:34:12 2017 +0000
@@ -37,7 +37,6 @@
 
 
 #include <cmath>
-
 #include "NDefNfcTagM24LR.h"
 
 
@@ -75,11 +74,11 @@
 #define NFCTAG_16M_SIZE           0x800
 #define NFCTAG_64M_SIZE           0x2000
 
-    
 #define MAX_NDEF_MEM                 0x200
 #define M24LR_MAX_SIZE               NFCTAG_4M_SIZE
 #define M24LR_NDEF_MAX_SIZE          MIN(M24LR_MAX_SIZE,MAX_NDEF_MEM)
 #define NFC_DEVICE_MAX_NDEFMEMORY    M24LR_NDEF_MAX_SIZE
+
 /**
   * @brief  This function read the data stored in NDEF file at defined offset.
   * @param  Offset : Offset in the NDEF file.
@@ -90,63 +89,53 @@
   * @retval NDEF_ERROR : No NDEF in the tag.
   * @retval NDEF_OK : The operation is completed.
   */
-uint16_t  NDefNfcTagM24LR::ReadData( uint16_t Offset , uint16_t DataSize , uint8_t* pData )
+uint16_t NDefNfcTagM24LR::ReadData( uint16_t Offset , uint16_t DataSize , uint8_t* pData )
 {
   uint16_t status = NDEF_ERROR;
   uint8_t atlv_detect[4];
   uint8_t index = 0;
   
   /* If too many data to write return error */
-  if( DataSize > NDEF_MAX_SIZE )
-  {
+  if ( DataSize > NDEF_MAX_SIZE ) {
     return NDEF_ERROR_MEMORY_INTERNAL;
   }
   
   /* Detect NDEF message in memory */
   status = NfcType5_NDEFDetection( );
-  if( status != NDEF_OK )
-  {
+  if ( status != NDEF_OK ) {
     return status;
   }
 
   /* Read TL of Type 5 */
   status = NDefReadByte(CCFileStruct.NDEF_offset, 4, atlv_detect);
-  if( status != NDEF_OK )
-  {
+  if ( status != NDEF_OK ){
     return status;
   }
   
-  if( atlv_detect[1] == NFCT5_3_BYTES_L_TLV )
-      index=2;
-
-  if(Offset==0 && DataSize>=2){
-      if( atlv_detect[1] == NFCT5_3_BYTES_L_TLV )
-      {
-        pData[0] = atlv_detect[2];
-        pData[1] = atlv_detect[3];
+  if ( atlv_detect[1] == NFCT5_3_BYTES_L_TLV ) {
+    index = 2;
+  }
 
-      }
-      else
-      {
-        pData[0] = 0x00;
-        pData[1] = atlv_detect[1];
-
-      }
-      DataSize-=2;
-      pData+=2;
+  if (Offset==0 && DataSize>=2) {
+    if ( atlv_detect[1] == NFCT5_3_BYTES_L_TLV ) {
+      pData[0] = atlv_detect[2];
+      pData[1] = atlv_detect[3];
+    } else {
+      pData[0] = 0x00;
+      pData[1] = atlv_detect[1];
+    }
+    DataSize -= 2;
+    pData += 2;
   }
 
   /* Check CC file is in the correct mode to proceed */
-  if( CCFileStruct.State ==  TT5_INITIALIZED )
-  {
+  if ( CCFileStruct.State ==  TT5_INITIALIZED ) {
     return NDEF_ERROR;
   }
 
-  if(DataSize > 0)
-  {
+  if (DataSize > 0) {
     /* Read NDEF */
-    if( NDefReadByte(CCFileStruct.NDEF_offset + index + Offset, DataSize, pData) != NFC_SUCCESS )
-    {
+    if ( NDefReadByte(CCFileStruct.NDEF_offset + index + Offset, DataSize, pData) != NFC_SUCCESS ) {
       return NDEF_ERROR;
     }
   }
@@ -175,14 +164,12 @@
   DataSize -= FIRST_RECORD_OFFSET;
   
   /* If too many data to write return error */
-  if( DataSize > NDEF_MAX_SIZE )
-  {
+  if ( DataSize > NDEF_MAX_SIZE ) {
     return NDEF_ERROR_MEMORY_INTERNAL;
   }
   
   /* Detect NDEF message in memory */
-  if( NfcType5_NDEFDetection( ) != NDEF_OK )
-  {
+  if ( NfcType5_NDEFDetection( ) != NDEF_OK ) {
     return NDEF_ERROR;
   }
  
@@ -191,56 +178,41 @@
   NDEF_Size = NDEF_Size | (uint16_t)(pData[1] );
   
   /* If entire NDEF is written, update Length of Type 5 */
-  if( DataSize == NDEF_Size )
-  {
+  if ( DataSize == NDEF_Size ) {
     /* Check if L is on 3 or 1 byte */
-    if( NDEF_Size >= NFCT5_3_BYTES_L_TLV )
-    {
+    if ( NDEF_Size >= NFCT5_3_BYTES_L_TLV ) {
       /* First init L with 0, will be updated at the end */
       atlv[1] = 0x00;
       atlv[2] = 0x00;
       atlv[3] = 0x00;
-      
       status = NDefWriteByte( (atlv + 1), 3, (CCFileStruct.NDEF_offset + 1));
-      
       index += 4; 
-    }
-    else
-    {
+    } else {
       /* First inti L with 0, will be updated at the end */
       atlv[1] = 0x00;
-      
       status = NDefWriteByte( (atlv + 1), 1, (CCFileStruct.NDEF_offset + 1));
-      
       index += 2;
     }
   }
   
   /* Start write NDEF message to EEPROM */
   status = NDefWriteByte( (pData + FIRST_RECORD_OFFSET), DataSize, CCFileStruct.NDEF_offset + index + Offset);
-  if( status != NFC_SUCCESS )
-  {
+  if ( status != NFC_SUCCESS ) {
     return NDEF_ERROR;
   }
   
   /* If entire NDEF is written, update Length of Type 5 */
-  if( DataSize == NDEF_Size )
-  {
+  if ( DataSize == NDEF_Size ) {
     /* Check if L is on 3 or 1 byte */
-    if( NDEF_Size >= NFCT5_3_BYTES_L_TLV )
-    {
+    if ( NDEF_Size >= NFCT5_3_BYTES_L_TLV ) {
       /* Update Length value */
       atlv[1] = NFCT5_3_BYTES_L_TLV;
       atlv[2] = pData[0];
       atlv[3] = pData[1];
-      
       status = NDefWriteByte( (atlv + 1), 3, (CCFileStruct.NDEF_offset + 1));
-    }
-    else
-    {
+    } else {
       /* Update Length value */
       atlv[1] = pData[1];
-      
       status = NDefWriteByte( (atlv + 1), 1, (CCFileStruct.NDEF_offset + 1));
     }
 
@@ -254,7 +226,7 @@
 
 /**
   * @brief  This functions writes CCFile in EEPROM.
-  * @Param  pCCBuffer : pointer on the buffer containnig CC file.
+  * @param  pCCBuffer : pointer on the buffer containnig CC file.
   * @retval NFCTAG status.
   */
 uint16_t NDefNfcTagM24LR::NfcType5_WriteCCFile( const uint8_t * const pCCBuffer )
@@ -265,22 +237,22 @@
   ret_value = NDefWriteByte( pCCBuffer, 0x4, 0x00);
  
   /* If extended memory writes the next 4 bytes */
-  if( (pCCBuffer[2] == 0x00) && (ret_value == NFC_SUCCESS) )
-  {
+  if ( (pCCBuffer[2] == 0x00) && (ret_value == NFC_SUCCESS) ) {
     ret_value = NDefWriteByte( pCCBuffer + 4, 4, 0x04);
   }
 
-  if( ret_value != NFC_SUCCESS )
-  {
+  if ( ret_value != NFC_SUCCESS ) {
     return NDEF_ERROR;
   }
   
-    return NDEF_OK;
+  return NDEF_OK;
 }
 
-
-
-
+/**
+  * @brief  This functions reads CCFile from EEPROM.
+  * @param  pCCBuffer : pointer on the buffer containnig CC file.
+  * @retval NFCTAG status.
+  */
 uint16_t NDefNfcTagM24LR::NfcType5_ReadCCFile( uint8_t * const pCCBuffer )
 {
   bool ret_value;
@@ -289,18 +261,22 @@
   ret_value = NDefReadByte(0x00, 4, pCCBuffer);
 
   /* If extended memory reads the next 4 bytes */
-  if( (pCCBuffer[2] == 0x00) && (ret_value == NFC_SUCCESS) )
-  {
+  if ( (pCCBuffer[2] == 0x00) && (ret_value == NFC_SUCCESS) ) {
     ret_value = NDefReadByte(0x04, 4, pCCBuffer + 4 );
   }
   
-  if( ret_value != NFC_SUCCESS )
-  {
+  if ( ret_value != NFC_SUCCESS ) {
     return NDEF_ERROR;
   }
   
   return NDEF_OK;
 }
+
+/**
+  * @brief  This functions initializes Nfc Type.
+  * @param  None.
+  * @retval NFCTAG status.
+  */
 uint16_t NDefNfcTagM24LR::NfcType5_TT5Init( void )
 {
   bool ret_value ;
@@ -316,8 +292,7 @@
   CCFileStruct.NDEF_offset = 0x04;
   
   /* If extended memory prepare the length bytes */
-  if( CCFileStruct.MemorySize == NFCT5_EXTENDED_CCFILE )
-  {
+  if ( CCFileStruct.MemorySize == NFCT5_EXTENDED_CCFILE ) {
     accbuffer[6] = (uint8_t)(CCFileStruct.ExtMemorySize >> 8);
     accbuffer[7] = (uint8_t)(CCFileStruct.ExtMemorySize & 0xFF);
     CCFileStruct.NDEF_offset = 0x08;
@@ -325,8 +300,7 @@
   
   /* Update CCFile */
   status = NfcType5_WriteCCFile( accbuffer );
-  if( status != NDEF_OK )
-  {
+  if ( status != NDEF_OK ) {
     return status;
   }
   
@@ -334,23 +308,26 @@
   /* Update T */
   cdata = NFCT5_NDEF_MSG_TLV;
   ret_value = NDefWriteByte( &cdata, 1, CCFileStruct.NDEF_offset);
-  if( ret_value != NFC_SUCCESS )
-  {
+  if ( ret_value != NFC_SUCCESS ) {
     return NDEF_ERROR;
   }
 
   /* Update L */
   cdata = 0x00;
   ret_value = NDefWriteByte( &cdata, 1, (CCFileStruct.NDEF_offset + 1));
-  if( ret_value != NFC_SUCCESS )
-  {
+  if ( ret_value != NFC_SUCCESS ) {
     return NDEF_ERROR;
   }
   
   return NDEF_OK;
 }
 
-
+/**
+  * @brief  This functions detects Nfc Tyoe.
+  * @param  None.
+  * @retval NDEF_ERROR_NOT_FORMATED : CCFile data not supported.
+  * @retval NDEF_OK : The operation is completed.
+  */
 uint16_t NDefNfcTagM24LR::NfcType5_NDEFDetection( void )
 {
   uint8_t acc_buffer[8];
@@ -362,34 +339,26 @@
   
   /* Read CCFile */
   status = NfcType5_ReadCCFile( acc_buffer );
-  if( status != NDEF_OK )
-  {
+  if ( status != NDEF_OK ) {
     return status;
   }
   
   /* Check Byte 0 is equal to magic number */
-  if( ( acc_buffer[0] != NFCT5_MAGICNUMBER_E1_CCFILE ) && ( acc_buffer[0] != NFCT5_MAGICNUMBER_E2_CCFILE ) )
-  {
+  if ( ( acc_buffer[0] != NFCT5_MAGICNUMBER_E1_CCFILE ) && ( acc_buffer[0] != NFCT5_MAGICNUMBER_E2_CCFILE ) ) {
     return NDEF_ERROR_NOT_FORMATED;
-  }
-  /* Check Version number */
-  else if( ( (acc_buffer[1]&0xFC) != 0x40 ) )
-  {
+  } else if ( ( (acc_buffer[1]&0xFC) != 0x40 ) ) { /* Check Version number */
     return NDEF_ERROR_NOT_FORMATED;
   }
   
   /* Check if CCFile is on 4 Bytes or 8 Bytes */
-  if( acc_buffer[2] == 0x00 )
-  {
+  if ( acc_buffer[2] == 0x00 ) {
     /* Update CCFIle structure */
     CCFileStruct.MemorySize = 0x0;
     CCFileStruct.ExtMemorySize = (uint16_t)acc_buffer[6];
     CCFileStruct.ExtMemorySize = ( CCFileStruct.ExtMemorySize << 8 ) |  acc_buffer[7];
     memory_size = CCFileStruct.ExtMemorySize;
     CCFileStruct.NDEF_offset = 8;
-  }
-  else
-  {
+  } else {
     /* Update CCFIle structure */
     CCFileStruct.MemorySize = acc_buffer[2];
     CCFileStruct.ExtMemorySize = 0x0;
@@ -403,127 +372,153 @@
   CCFileStruct.TT5Tag = acc_buffer[3];
   
   /* Search for position of NDEF TLV in memory and tag status */
-  while( ( NDefReadByte(CCFileStruct.NDEF_offset, 4, atlv_detect) == NFC_SUCCESS ) && ( CCFileStruct.NDEF_offset < memory_size ) )
-  {
+  while( ( NDefReadByte(CCFileStruct.NDEF_offset, 4, atlv_detect) == NFC_SUCCESS ) && ( CCFileStruct.NDEF_offset < memory_size ) ) {
     /* Detect first NDEF Message in memory */
-    if( atlv_detect[0] == NFCT5_NDEF_MSG_TLV )
-    {
-      if( atlv_detect[1] == 0x00 )
-      {
+    if ( atlv_detect[0] == NFCT5_NDEF_MSG_TLV ) {
+      if ( atlv_detect[1] == 0x00 ) {
         CCFileStruct.State = TT5_INITIALIZED;
-      }
-      else
-      {
-        if( CCFileStruct.Version & 0x3 )
-        {
+      } else {
+        if ( CCFileStruct.Version & 0x3 ) {
           CCFileStruct.State = TT5_READ;
-        }
-        else
-        {
+        } else {
           CCFileStruct.State = TT5_READ_WRITE;
         }
       }
       return NDEF_OK;
-    }
-    /* If Proprietary NDEF jump to end of proprietary message */
-    else if( atlv_detect[0] == NFCT5_PROPRIETARY_TLV )
-    {
-      if( atlv_detect[1] == NFCT5_3_BYTES_L_TLV )
-      {
+    } else if ( atlv_detect[0] == NFCT5_PROPRIETARY_TLV ) { /* If Proprietary NDEF jump to end of proprietary message */
+      if ( atlv_detect[1] == NFCT5_3_BYTES_L_TLV ) {
         CCFileStruct.NDEF_offset = CCFileStruct.NDEF_offset + ( (uint32_t)atlv_detect[2] << 8 ) + atlv_detect[3];
         continue;
-      }
-      else
-      {
+      } else {
         CCFileStruct.NDEF_offset = CCFileStruct.NDEF_offset + atlv_detect[1];
         continue;
       }
-    }
-    /* if Terminator no NDEF detected */
-    else if( atlv_detect[0] == NFCT5_TERMINATOR_TLV )
-    {
+    } else if ( atlv_detect[0] == NFCT5_TERMINATOR_TLV ) { /* if Terminator no NDEF detected */
       return NDEF_ERROR_NOT_FORMATED;
     }
-      
+
     CCFileStruct.NDEF_offset++;
   }
   
   return NDEF_ERROR_NOT_FORMATED;
 }
 
+/**
+  * @brief  This functions opens a session.
+  * @param  force : force the opening.
+  * @retval true.
+  */
 bool NDefNfcTagM24LR::open_session(bool force) {
-uint16_t status;
-
-      status = NfcType5_NDEFDetection();
+  uint16_t status = NfcType5_NDEFDetection();
 
-      if ( status != NDEF_OK ) 
-      {
-        CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
-      CCFileStruct.Version = NFCT5_VERSION_V1_0;
-      CCFileStruct.MemorySize = ( M24LR_MAX_SIZE / 8 ) & 0xFF;
-      CCFileStruct.TT5Tag = 0x05;
-      /* Init of the Type Tag 5 component (M24LR) */
-      while( NfcType5_TT5Init( ) != NDEF_OK );
-      }
-      mIsSessionOpen = 1;
-      return true; 
+  if ( status != NDEF_OK ) {
+    CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
+    CCFileStruct.Version = NFCT5_VERSION_V1_0;
+    CCFileStruct.MemorySize = ( M24LR_MAX_SIZE / 8 ) & 0xFF;
+    CCFileStruct.TT5Tag = 0x05;
+    /* Init of the Type Tag 5 component (M24LR) */
+    while ( NfcType5_TT5Init( ) != NDEF_OK );
+  }
 
+  mIsSessionOpen = 1;
+
+  return true;
 }
 
+
+/**
+  * @brief  This functions closes a session.
+  * @param  None.
+  * @retval true.
+  */
 bool NDefNfcTagM24LR::close_session() 
 {
-    
     return true;
 }
 
-bool NDefNfcTagM24LR::writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset,
-        byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)
+/**
+  * @brief  This functions writes bytes.
+  * @param  byffer : the buffer containing data.
+  * @param  length: the length of the buffer in bytes.
+  * @param  offset: the offset of the buffer in bytes.
+  * @retval true if written, false otherwise.
+  */
+bool NDefNfcTagM24LR::writeByte(const uint8_t *buffer, uint16_t length, uint16_t offset,
+    byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)
 {
-  
-  if(WriteData(offset, length, (uint8_t*)buffer)== NDEF_OK){
+  if (WriteData(offset, length, (uint8_t*)buffer)== NDEF_OK) {
     callback(callbackStatus,true,buffer,length);
     return true;
   }
-  callback(callbackStatus,false,buffer,length);
-  return false;
-}
-                
-bool NDefNfcTagM24LR::readByte(const uint16_t byteOffset, const uint16_t length,
-        uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)
-{
-  
-  //first it reads the 2 byte for the length then when it will have the call back it reads the real message
-  if(ReadData(byteOffset, length, (uint8_t*)buffer)== NDEF_OK){
-    callback(callbackStatus,true,buffer,length);
-    return true;
-  }
+
   callback(callbackStatus,false,buffer,length);
   return false;
 }
 
-uint16_t NDefNfcTagM24LR::NDefWriteByte(const uint8_t *buffer, uint16_t length,uint16_t offset){
+/**
+  * @brief  This functions reads bytes.
+  * @param  byteOffset : the offset of the buffer in bytes.
+  * @param  length: the length of the buffer in bytes.
+  * @param  buffer : the buffer containing data.
+  * @param  callback : a function to call after reading data.
+  * @param  callbackStatus : the status of the callback.
+  * @retval true if read, false otherwise.
+  */       
+bool NDefNfcTagM24LR::readByte(const uint16_t byteOffset, const uint16_t length,
+    uint8_t *buffer, byteOperationCallback_t callback, CallbackStatus_t *callbackStatus)
+{
+  
+  //first it reads the 2 byte for the length then when it will have the callback it reads the real message
+  if (ReadData(byteOffset, length, (uint8_t*)buffer)== NDEF_OK){
+    callback(callbackStatus,true,buffer,length);
+    return true;
+  }
+
+  callback(callbackStatus,false,buffer,length);
+  return false;
+}
+
+/**
+  * @brief  This functions writes bytes.
+  * @param  byffer : the buffer containing data.
+  * @param  length: the length of the buffer in bytes.
+  * @param  offset: the offset of the buffer in bytes.
+  * @retval NFCTAG status.
+  */
+uint16_t NDefNfcTagM24LR::NDefWriteByte(const uint8_t *buffer, uint16_t length, uint16_t offset)
+{
     uint16_t status;
-    do{
+    do {
         uint8_t writeLength =(uint8_t) std::min<uint16_t>(0xFF,length);
-        status= mDevice.update_binary(offset, writeLength, (uint8_t*)buffer);
+        status = mDevice.update_binary(offset, writeLength, (uint8_t*)buffer);
         offset+=writeLength;
         buffer+=writeLength;
         length-=writeLength;
-    }while(status==NDEF_OK && length!=0);
+    } while (status==NDEF_OK && length!=0);
+
     return status;
 }
 
-
-uint16_t NDefNfcTagM24LR::NDefReadByte(uint16_t byteOffset, uint16_t length, uint8_t *buffer){
+/**
+  * @brief  This functions reads bytes.
+  * @param  byteOffset : the offset of the buffer in bytes.
+  * @param  length: the length of the buffer in bytes.
+  * @param  buffer : the buffer containing data.
+  * @retval NFCTAG status.
+  */
+uint16_t NDefNfcTagM24LR::NDefReadByte(uint16_t byteOffset, uint16_t length, uint8_t *buffer)
+{
     uint16_t status;
-    do{
+    do {
         uint8_t readBuffer = (uint8_t)std::min<uint16_t>(0xFF,length);
         status= mDevice.read_binary(byteOffset, readBuffer, (uint8_t*)buffer);
         byteOffset+=readBuffer;
         buffer+=readBuffer;
         length-=readBuffer;
-    }while(status==NDEF_OK && length!=0);
+    } while (status==NDEF_OK && length!=0);
+
   return status;
 }
 
+
 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 
diff -r b876cdcf095a -r 7c4cf671960b m24lr/NDefNfcTagM24LR.h
--- a/m24lr/NDefNfcTagM24LR.h	Tue Jul 11 15:23:56 2017 +0000
+++ b/m24lr/NDefNfcTagM24LR.h	Wed Jul 12 12:34:12 2017 +0000
@@ -81,19 +81,17 @@
     /**
     * Close the open session.
     */
-    virtual ~NDefNfcTagM24LR(){
+    virtual ~NDefNfcTagM24LR() {
         if(is_session_open())
             close_session();
     }//~NDefNfcTagM24SR
 
     protected:
-
         virtual bool writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset,
-                byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
+            byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
 
         virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength,
-                uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
-                
+            uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus);
 
     private:
         uint16_t NDefWriteByte(const uint8_t *buffer, uint16_t length,uint16_t offset);
@@ -143,10 +141,9 @@
           uint16_t ExtMemorySize;
           TT5_State State;
           uint32_t NDEF_offset;
-        }sCCFileInfo;
+        } sCCFileInfo;
                 
         sCCFileInfo CCFileStruct;
-
     };
 
 #endif /* X_NUCLEO_NFC02A1_M24LR_NDEFNFCTAGM24LR_H_ */