Firmware library for the X-NUCLEO-NFC01A1 Dynamic NFC Tag board.

Dependencies:   M24SR

Dependents:   NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more

Fork of X_NUCLEO_NFC01A1 by ST Expansion SW Team

X-NUCLEO-NFC01A1 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-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.

Firmware Library

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

Example applications

1. Hello World
2. Asynchronous Hello World

Revision:
9:9f2e2e68d695
Parent:
7:19fc04b8fec6
Child:
10:482175f7ae66
--- a/m24sr/m24sr_class.cpp	Mon Jan 11 13:06:23 2016 +0000
+++ b/m24sr/m24sr_class.cpp	Thu Jan 14 07:54:59 2016 +0000
@@ -2,6 +2,7 @@
  ******************************************************************************
  * @file    m24sr_class.cpp
  * @author  ST Central Labs
+ * @version V1.0.0
  * @date    05 Nov 2015
  * @brief   This file provides a set of functions to interface with the M24SR
  *          device.
@@ -42,7 +43,7 @@
 #include "m24sr.h"
 
 /**
- * default password, it is used also for reach the super user mode throught the i2c channel
+ * default password, also used to enable super user mode throught the I2C channel
  */
 const uint8_t M24SR::DEFAULT_PASSWORD[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@@ -59,7 +60,7 @@
 
 #ifndef errchk
 
-/** value return by the NFC chip when a command is successfully done */
+/** value returned by the NFC chip when a command is successfully completed */
 #define NFC_COMMAND_SUCCESS 0x9000
 
 /** call the fCall funtion and check that the return status is NFC_SUCCESS,
@@ -89,7 +90,7 @@
 /**
  * @brief  This function returns the CRC 16 
  * @param  Data : pointer on the data used to compute the CRC16
- * @param  Length : number of byte of the data
+ * @param  Length : number of bytes of the data
  * @retval CRC16 
  */
 static uint16_t M24SR_ComputeCrc(uint8_t *Data, uint8_t Length) {
@@ -106,7 +107,7 @@
 
 /**  
  * @brief  	This function computes the CRC16 residue as defined by CRC ISO/IEC 13239
- * @param  	DataIn		:	input to data 
+ * @param  	DataIn		:	input data 
  * @param	Length 		: 	Number of bits of DataIn
  * @retval 	Status (SW1&SW2)  	:   CRC16 residue is correct	
  * @retval 	M24SR_ERROR_CRC  	:  CRC16 residue is false
@@ -138,10 +139,10 @@
 
 /**
  * @brief 		This functions creates an I block command according to the structures CommandStructure and data->command.
- * @param	 	Command : structue which contains the field of the different parameter
- * @param	 	CommandStructure : structure that contain the structure of the command (if the different field are presnet or not 
- * @param	 	NbByte : number of byte of the command
- * @param	 	pCommand : pointer of the command created
+ * @param	 	Command : structure which contains the field of the different parameters
+ * @param	 	CommandStructure : structure of the command 
+ * @param	 	NbByte : number of bytes of the command
+ * @param	 	pCommand : pointer to the command created
  */
 static void M24SR_BuildIBlockCommand(uint16_t CommandStructure, C_APDU *Command,
 		uint8_t uDIDbyte, uint16_t *NbByte, uint8_t *pCommand) {
@@ -203,51 +204,10 @@
 
 }
 
-#if 0
-/**  
- * @brief  	This function return M24SR_STATUS_SUCCESS if the pBuffer is an I-block
- * @param  	pBuffer		:	pointer of the data
- * @retval 	M24SR_STATUS_SUCCESS  :  the data is a I-Block
- * @retval 	M24SR_ERROR_DEFAULT  	:  the data is not a I-Block
- */
-static int8_t IsIBlock (uint8_t *pBuffer)
-{
-
-	if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_IBLOCK)
-	{
-		return M24SR_STATUS_SUCCESS;
-	}
-	else
-	{
-		return M24SR_ERROR_DEFAULT;
-	}
-
-}
 
 /**  
- * @brief  	This function return M24SR_STATUS_SUCCESS if the pBuffer is an R-block
- * @param  	pBuffer		:	pointer of the data
- * @retval 	M24SR_STATUS_SUCCESS  :  the data is a R-Block
- * @retval 	M24SR_ERROR_DEFAULT  	:  the data is not a R-Block
- */
-static int8_t IsRBlock (uint8_t *pBuffer)
-{
-
-	if ((pBuffer[M24SR_OFFSET_PCB] & M24SR_MASK_BLOCK) == M24SR_MASK_RBLOCK)
-	{
-		return M24SR_STATUS_SUCCESS;
-	}
-	else
-	{
-		return M24SR_ERROR_DEFAULT;
-	}
-
-}
-#endif	
-
-/**  
- * @brief  	This function return M24SR_STATUS_SUCCESS if the pBuffer is an s-block
- * @param  	pBuffer		:	pointer of the data
+ * @brief  	This function returns M24SR_STATUS_SUCCESS if the pBuffer is an s-block
+ * @param  	pBuffer		:	pointer to the data
  * @retval 	NFC_SUCCESS  :  the data is a S-Block
  * @retval 	NFC_ERROR  	:  the data is not a S-Block
  */
@@ -264,7 +224,7 @@
 /**
  * @brief  This function sends the FWT extension command (S-Block format)
  * @param	FWTbyte : FWT value
- * @return NFC_SUCCESS if no error happen
+ * @return NFC_SUCCESS if no errors
  */
 NFC_StatusTypeDef M24SR::M24SR_FWTExtension(uint8_t FWTbyte) {
 	uint8_t pBuffer[M24SR_STATUSRESPONSE_NBBYTE];
@@ -299,7 +259,7 @@
 /**
  * @brief  This function sends the KillSession command to the M24SR device
  * @param  None
- * @return NFC_SUCCESS if no error happen
+ * @return NFC_SUCCESS if no errors
  */
 NFC_StatusTypeDef M24SR::M24SR_KillSession(void) {
 	uint8_t commandBuffer[] = M24SR_KILLSESSION_COMMAND;
@@ -316,7 +276,7 @@
 
 /**
  * @brief  This function sends the Deselect command (S-Block format)
- * @return NFC_SUCCESS if no error happen
+ * @return NFC_SUCCESS if no errors
  */
 NFC_StatusTypeDef M24SR::M24SR_Deselect(void) {
 	uint8_t pBuffer[] = M24SR_DESELECTREQUEST_COMMAND;
@@ -333,7 +293,7 @@
 
 /**
  * @brief  This function sends the SelectApplication command
- * @return NFC_SUCCESS if no error happen
+ * @return NFC_SUCCESS if no errors
  */
 NFC_StatusTypeDef M24SR::M24SR_SelectApplication(void) {
 
@@ -403,8 +363,8 @@
 
 /**
  * @brief  This function sends the GetSession command to the M24SR device
- * @retval NFC_SUCCESS : the function is successful.
- * @retval Status (SW1&SW2) : if operation does not complete.
+ * @retval NFC_SUCCESS the function is successful.
+ * @retval Status (SW1&SW2) if operation does not complete.
  */
 NFC_StatusTypeDef M24SR::M24SR_GetSession(void) {
 	uint8_t commandBuffer[] = M24SR_OPENSESSION_COMMAND;
@@ -422,9 +382,9 @@
 
 /**
  * @brief  This function sends the SelectCCFile command
- * @retval NFC_SUCCESS : the function is successful.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
- * @retval Status (SW1&SW2) : if operation does not complete for another reason.
+ * @retval NFC_SUCCESS the function is successful.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
+ * @retval Status (SW1&SW2)   if operation does not complete for another reason.
  */
 NFC_StatusTypeDef M24SR::M24SR_SelectCCfile(void) {
 	C_APDU command;
@@ -465,8 +425,8 @@
 
 /**
  * @brief  This function sends the SelectSystemFile command
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_SelectSystemfile(void) {
 	C_APDU command;
@@ -507,8 +467,8 @@
 
 /**
  * @brief  This function sends the SelectNDEFfile command
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_SelectNDEFfile(uint16_t NDEFfileId) {
 	C_APDU command;
@@ -548,11 +508,11 @@
 
 /**
  * @brief  This function sends a read binary command
- * @param	Offset : first byte to read
- * @param	NbByteToRead : number of byte to read
- * @param	pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	Offset   first byte to read
+ * @param	NbByteToRead   number of bytes to read
+ * @param	pBufferRead   pointer to the buffer read from the M24SR device
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_ReadBinary(uint16_t Offset, uint8_t NbByteToRead,
 		uint8_t *pBufferRead) {
@@ -590,11 +550,11 @@
 
 /**
  * @brief  This function sends a ST read binary command (no error if access is not inside NDEF file)
- * @param	Offset : first byte to read
- * @param	NbByteToRead : number of byte to read
- * @param	pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	Offset   first byte to read
+ * @param	NbByteToRead number of bytes to read
+ * @param	pBufferRead  pointer to the buffer read from the M24SR device
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_STReadBinary(uint16_t Offset,
 		uint8_t NbByteToRead, uint8_t *pBufferRead) {
@@ -632,11 +592,11 @@
 
 /**
  * @brief  This function sends a Update binary command
- * @param	Offset : first byte to read
- * @param	NbByteToWrite : number of byte to write
- * @param	pBufferRead : pointer of the buffer read from the M24SR device
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	Offset   first byte to read
+ * @param	NbByteToWrite   number of bytes to write
+ * @param	pBufferRead   pointer to the buffer read from the M24SR device
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_UpdateBinary(uint16_t Offset,
 		uint8_t NbByteToWrite, uint8_t *pDataToWrite) {
@@ -690,11 +650,11 @@
 
 /**
  * @brief  This function sends the Verify command
- * @param	uPwdId : PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
- * @param	NbPwdByte : Number of byte ( 0x00 or 0x10)
- * @param	pPwd : pointer on the passwaord
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uPwdId   PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
+ * @param	NbPwdByte   Number of bytes ( 0x00 or 0x10)
+ * @param	pPwd   pointer to the password
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_Verify(uint16_t uPwdId, uint8_t NbPwdByte,
 		const uint8_t *pPwd) {
@@ -718,7 +678,7 @@
 	/* copy the Password Id */
 	command.Header.P1 = GETMSB(uPwdId);
 	command.Header.P2 = GETLSB(uPwdId);
-	/* copy the number of byte of the data field */
+	/* copy the number of bytes of the data field */
 	command.Body.LC = NbPwdByte;
 
 	if (NbPwdByte == 0x10) {
@@ -752,10 +712,10 @@
 
 /**
  * @brief  This function sends the ChangeReferenceData command
- * @param	uPwdId : PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
- * @param	pPwd : pointer on the passwaord
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uPwdId   PasswordId ( 0x0001 : Read NDEF pwd or 0x0002 : Write NDEF pwd or 0x0003 : I2C pwd)
+ * @param	pPwd   pointer to the passwaord
+ * @retval Status (SW1&SW2) Satus of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_ChangeReferenceData(uint16_t uPwdId,
 		uint8_t *pPwd) {
@@ -800,9 +760,9 @@
 
 /**
  * @brief  This function sends the EnableVerificationRequirement command
- * @param	uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uReadOrWrite enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_EnableVerificationRequirement(
 		uint16_t uReadOrWrite) {
@@ -843,9 +803,9 @@
 
 /**
  * @brief  This function sends the DisableVerificationRequirement command
- * @param	uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uReadOrWrite enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
+ * @retval Status (SW1&SW2)   Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_DisableVerificationRequirement(
 		uint16_t uReadOrWrite) {
@@ -888,9 +848,9 @@
 
 /**
  * @brief  This function sends the EnablePermananentState command
- * @param	uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uReadOrWrite   enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
+ * @retval Status (SW1&SW2)   Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_EnablePermanentState(uint16_t uReadOrWrite) {
 	C_APDU command;
@@ -930,9 +890,9 @@
 
 /**
  * @brief  This function sends the DisablePermanentState command
- * @param	uReadOrWrite : enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @param	uReadOrWrite enable the read or write protection ( 0x0001 : Read or 0x0002 : Write  )
+ * @retval Status (SW1&SW2)   Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_DisablePermanentState(uint16_t uReadOrWrite) {
 	C_APDU command;
@@ -972,10 +932,10 @@
 }
 
 /**
- * @brief  This function generates a interrupt on GPO pin
+ * @brief  This function generates an interrupt on GPO pin
  * @param	None
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @retval Status (SW1&SW2)   Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_SendInterrupt(void) {
 	C_APDU command;
@@ -1015,10 +975,10 @@
 }
 
 /**
- * @brief  This function force GPO pin to low state or high Z
- * @param	uSetOrReset : select if GPO must be low (reset) or HiZ
- * @retval Status (SW1&SW2) : Status of the operation to complete.
- * @retval M24SR_ERROR_I2CTIMEOUT : The I2C timeout occurred.
+ * @brief  This function forces GPO pin to low state or high Z
+ * @param	uSetOrReset select if GPO must be low (reset) or HiZ
+ * @retval Status (SW1&SW2) Status of the operation to complete.
+ * @retval M24SR_ERROR_I2CTIMEOUT I2C timeout occurred.
  */
 NFC_StatusTypeDef M24SR::M24SR_StateControl(uint8_t uSetOrReset) {
 	C_APDU command;