This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.

Dependencies:   NDefLib X_NUCLEO_NFC01A1 mbed

Fork of X-MBED-NFC1 by Giovanni Visentini

This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.

The available demos are:

  • SAMPLE_WRITE_URL: write a tag with the ST home page URL
  • SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
  • SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
  • SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.

To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .

Revision:
0:674813bd5ec9
Child:
1:6d202b62ed68
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m24sr/m24sr_class.h	Thu Nov 19 08:50:18 2015 +0000
@@ -0,0 +1,441 @@
+/**
+  ******************************************************************************
+  * @file    m24sr_class.h
+  * @author  MMY Application Team
+  * @version V1.2.0
+  * @date    20-October-2014
+  * @brief   This file provides a set of functions to interface with the M24SR
+  *          device.
+  ******************************************************************************
+  * @attention
+  *
+  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+  *
+  * Redistribution and use in source and binary forms, with or without modification,
+  * are permitted provided that the following conditions are met:
+  *   1. Redistributions of source code must retain the above copyright notice,
+  *      this list of conditions and the following disclaimer.
+  *   2. Redistributions in binary form must reproduce the above copyright notice,
+  *      this list of conditions and the following disclaimer in the documentation
+  *      and/or other materials provided with the distribution.
+  *   3. Neither the name of STMicroelectronics nor the names of its contributors
+  *      may be used to endorse or promote products derived from this software
+  *      without specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  *
+  ******************************************************************************
+  */
+
+
+/* Generated with Stm32CubeTOO -----------------------------------------------*/
+
+
+/* Revision ------------------------------------------------------------------*/
+/*
+	Repository:       http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
+	Branch/Trunk/Tag: trunk
+	Based on:         X-CUBE-MEMS1/trunk/Drivers/BSP/Components/m24sr/m24sr.h
+	Revision:         402
+*/
+
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+
+#ifndef __M24SR_CLASS_H
+#define __M24SR_CLASS_H
+
+
+/* Includes ------------------------------------------------------------------*/
+
+/* ACTION 1 ------------------------------------------------------------------*
+ * Include here platform specific header files.                               *
+ *----------------------------------------------------------------------------*/		
+#include "mbed.h"
+#include "I2C.h"
+/* ACTION 2 ------------------------------------------------------------------*
+ * Include here component specific header files.                              *
+ *----------------------------------------------------------------------------*/		
+#include "m24sr.h"
+/* ACTION 3 ------------------------------------------------------------------*
+ * Include here interface specific header files.                              *
+ *                                                                            *
+ * Example:                                                                   *
+ *   #include "../Interfaces/Humidity_class.h"                                *
+ *   #include "../Interfaces/Temperature_class.h"                             *
+ *----------------------------------------------------------------------------*/
+#include "Interfaces/Nfc_class.h"
+
+
+/* Classes -------------------------------------------------------------------*/
+
+/** Class representing a M24SR component.
+ */
+class M24SR : public Nfc
+{
+
+public:
+
+	/*** Constructor and Destructor Methods ***/
+
+	/**
+	 * @brief Constructor.
+	 * @param address I2C address of the component.
+	 * @param i2c     I2C device to be used for communication.
+	 */
+	M24SR(const uint8_t address, I2C &i2c, const PinName& GPOPinName,const PinName& RFDISPinName) :
+		Nfc(), address(address), dev_i2c(i2c), GPOPin(GPOPinName),RFDisablePin(RFDISPinName),answerReadyInterrupt(GPOPinName)
+	{
+		/* ACTION 4 ----------------------------------------------------------*
+		 * Initialize here the component's member variables, one variable per *
+		 * line.                                                              *
+		 *                                                                    *
+		 * Example:                                                           *
+		 *   T0_out = 0;                                                      *
+		 *   T1_out = 0;                                                      *
+		 *   T0_degC = 0;                                                     *
+		 *   T1_degC = 0;                                                     *
+		 *--------------------------------------------------------------------*/
+		memset(&command, 0, sizeof(C_APDU));
+		M24SR_InitCommandStructure();
+		memset(dataBuffer, 0, 0xFF * sizeof(int8_t));
+		memset(uM24SRbuffer, 0, 0xFF * sizeof(int8_t));
+		M24SR_ManageI2CGPO(I2C_ANSWER_READY);
+		uDIDbyte = 0;
+		RFDisablePin=0;
+		GPOPin.mode(PullNone);
+		answerReadyInterrupt.disable_irq();
+		answerReadyInterrupt.fall(this,&M24SR::M24SR_AnswerReadyInterruptCallback);
+		answerReadyInterrupt.mode(PullNone);
+	}
+	
+	/**
+	 * @brief Destructor.
+	 */
+	virtual ~M24SR(void) {}
+	
+
+	/*** Public Component Related Methods ***/
+
+	/* ACTION 5 --------------------------------------------------------------*
+	 * Implement here the component's public methods, as wrappers of the C    *
+	 * component's functions.                                                 *
+	 * They should be:                                                        *
+	 *   + Methods with the same name of the C component's virtual table's    *
+	 *     functions (1);                                                     *
+	 *   + Methods with the same name of the C component's extended virtual   *
+	 *     table's functions, if any (2).                                     *
+	 *                                                                        *
+	 * Example:                                                               *
+	 *   virtual int GetValue(float *pData) //(1)                             *
+	 *   {                                                                    *
+	 *     return COMPONENT_GetValue(float *pfData);                          *
+	 *   }                                                                    *
+	 *                                                                        *
+	 *   virtual int EnableFeature(void) //(2)                                *
+	 *   {                                                                    *
+	 *     return COMPONENT_EnableFeature();                                  *
+	 *   }                                                                    *
+	 *------------------------------------------------------------------------*/
+	virtual int Init(void *init)
+	{
+		//use the gpo for notfy when a response is ready
+
+		return NFC_OK;
+	}
+
+	virtual int ReadID(uint8_t *id)
+	{
+		return (NFC_StatusTypeDef) M24SR_ReadID((uint8_t *) id);
+	}
+
+	virtual NFC_StatusTypeDef SendInterrupt(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_SendInterrupt();
+	}
+
+	virtual NFC_StatusTypeDef GetSession(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_GetSession();
+	}
+
+	virtual NFC_StatusTypeDef KillSession(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_KillSession();
+	}
+
+	virtual NFC_StatusTypeDef Deselect(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_Deselect();
+	}
+
+	virtual NFC_StatusTypeDef SelectApplication(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_SelectApplication();
+	}
+
+	virtual NFC_StatusTypeDef SelectCCfile(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_SelectCCfile();
+	}
+
+	virtual NFC_StatusTypeDef SelectNDEFfile(uint16_t NDEFfileId)
+	{
+		return (NFC_StatusTypeDef) M24SR_SelectNDEFfile((uint16_t) NDEFfileId);
+	}
+
+	virtual NFC_StatusTypeDef SelectSystemfile(void)
+	{
+		return (NFC_StatusTypeDef) M24SR_SelectSystemfile();
+	}
+
+	virtual NFC_StatusTypeDef ReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead)
+	{
+		return (NFC_StatusTypeDef) M24SR_ReadBinary((uint16_t) Offset, (uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
+	}
+
+	virtual NFC_StatusTypeDef UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite)
+	{
+		return (NFC_StatusTypeDef) M24SR_UpdateBinary((uint16_t) Offset, (uint8_t) NbByteToWrite, (uint8_t *) pDataToWrite);
+	}
+
+	virtual NFC_StatusTypeDef Verify(uint16_t uPwdId, uint8_t NbPwdByte, uint8_t *pPwd)
+	{
+		return (NFC_StatusTypeDef) M24SR_Verify((uint16_t) uPwdId, (uint8_t) NbPwdByte, (uint8_t *) pPwd);
+	}
+
+	virtual NFC_StatusTypeDef ChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd)
+	{
+		return (NFC_StatusTypeDef) M24SR_ChangeReferenceData((uint16_t) uPwdId, (uint8_t *) pPwd);
+	}
+
+	virtual NFC_StatusTypeDef EnableVerificationRequirement(uint16_t uReadOrWrite)
+	{
+		return (NFC_StatusTypeDef) M24SR_EnableVerificationRequirement((uint16_t) uReadOrWrite);
+	}
+
+	virtual NFC_StatusTypeDef DisableVerificationRequirement(uint16_t uReadOrWrite)
+	{
+		return (NFC_StatusTypeDef) M24SR_DisableVerificationRequirement((uint16_t) uReadOrWrite);
+	}
+
+	virtual NFC_StatusTypeDef STReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead)
+	{
+		return (NFC_StatusTypeDef) M24SR_STReadBinary((uint16_t) Offset, (uint8_t) NbByteToRead, (uint8_t *) pBufferRead);
+	}
+
+	virtual NFC_StatusTypeDef EnablePermanentState(uint16_t uReadOrWrite)
+	{
+		return (NFC_StatusTypeDef) M24SR_EnablePermanentState((uint16_t) uReadOrWrite);
+	}
+
+	virtual NFC_StatusTypeDef DisablePermanentState(uint16_t uReadOrWrite)
+	{
+		return (NFC_StatusTypeDef) M24SR_DisablePermanentState((uint16_t) uReadOrWrite);
+	}
+
+	virtual NFC_StatusTypeDef StateControl(uint8_t uSetOrReset)
+	{
+		return (NFC_StatusTypeDef) M24SR_StateControl((uint8_t) uSetOrReset);
+	}
+
+	virtual NFC_StatusTypeDef ManageI2CGPO(uint8_t GPO_I2Cconfig)
+	{
+		return (NFC_StatusTypeDef) M24SR_ManageI2CGPO((uint8_t) GPO_I2Cconfig);
+	}
+
+	virtual NFC_StatusTypeDef ManageRFGPO(uint8_t GPO_RFconfig)
+	{
+		return (NFC_StatusTypeDef) M24SR_ManageRFGPO((uint8_t) GPO_RFconfig);
+	}
+
+	virtual NFC_StatusTypeDef RFConfig(uint8_t OnOffChoice)
+	{
+		return (NFC_StatusTypeDef) M24SR_RFConfig((uint8_t) OnOffChoice);
+	}
+
+
+	/*** Public Interrupt Related Methods ***/
+
+	/* ACTION 6 --------------------------------------------------------------*
+	 * Implement here interrupt related methods, if any.                      *
+	 * Note that interrupt handling is platform dependent, e.g.:              *
+	 *   + mbed:                                                              *
+	 *     InterruptIn feature_int(pin); //Interrupt object.                  *
+	 *     feature_int.rise(callback);   //Attach a callback.                 *
+	 *     feature_int.mode(PullNone);   //Set interrupt mode.                *
+	 *     feature_int.enable_irq();     //Enable interrupt.                  *
+	 *     feature_int.disable_irq();    //Disable interrupt.                 *
+	 *   + Arduino:                                                           *
+	 *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
+	 *     detachInterrupt(pin);                   //Detach a callback.       *
+	 *                                                                        *
+	 * Example (mbed):                                                        *
+	 *   void Attach_Feature_IRQ(void (*fptr) (void))                         *
+	 *   {                                                                    *
+	 *     feature_int.rise(fptr);                                            *
+	 *   }                                                                    *
+	 *                                                                        *
+	 *   void Enable_Feature_IRQ(void)                                        *
+	 *   {                                                                    *
+	 *     feature_int.enable_irq();                                          *
+	 *   }                                                                    *
+	 *                                                                        *
+	 *   void Disable_Feature_IRQ(void)                                       *
+	 *   {                                                                    *
+	 *     feature_int.disable_irq();                                         *
+	 *   }                                                                    *
+	 *------------------------------------------------------------------------*/
+
+
+protected:
+
+	/*** Protected Component Related Methods ***/
+
+	/* ACTION 7 --------------------------------------------------------------*
+	 * Declare here the component's specific methods.                         *
+	 * They should be:                                                        *
+	 *   + Methods with the same name of the C component's virtual table's    *
+	 *     functions (1);                                                     *
+	 *   + Methods with the same name of the C component's extended virtual   *
+	 *     table's functions, if any (2);                                     *
+	 *   + Helper methods, if any, like functions declared in the component's *
+	 *     source files but not pointed by the component's virtual table (3). *
+	 *                                                                        *
+	 * Example:                                                               *
+	 *   DrvStatusTypeDef COMPONENT_GetValue(float* pfData); //(1)            *
+	 *   DrvStatusTypeDef COMPONENT_EnableFeature(void);     //(2)            *
+	 *   DrvStatusTypeDef COMPONENT_ComputeAverage(void);    //(3)            *
+	 *------------------------------------------------------------------------*/
+	NFC_StatusTypeDef M24SR_Init(NFC_InitTypeDef *);
+	void M24SR_InitCommandStructure ( void );
+	NFC_StatusTypeDef M24SR_ReadID(uint8_t *nfc_id);
+	NFC_StatusTypeDef M24SR_GetSession(void);
+	NFC_StatusTypeDef M24SR_KillSession(void);
+	NFC_StatusTypeDef M24SR_Deselect(void);
+	NFC_StatusTypeDef M24SR_SelectApplication(void);
+	NFC_StatusTypeDef M24SR_SelectCCfile(void);
+	NFC_StatusTypeDef M24SR_SelectNDEFfile(uint16_t NDEFfileId);
+	NFC_StatusTypeDef M24SR_SelectSystemfile(void);
+	NFC_StatusTypeDef M24SR_ReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
+	NFC_StatusTypeDef M24SR_STReadBinary(uint16_t Offset, uint8_t NbByteToRead, uint8_t *pBufferRead);
+	NFC_StatusTypeDef M24SR_UpdateBinary(uint16_t Offset, uint8_t NbByteToWrite, uint8_t *pDataToWrite);
+	NFC_StatusTypeDef M24SR_Verify(uint16_t uPwdId, uint8_t NbPwdByte, uint8_t *pPwd);
+	NFC_StatusTypeDef M24SR_ChangeReferenceData(uint16_t uPwdId, uint8_t *pPwd);
+	NFC_StatusTypeDef M24SR_EnableVerificationRequirement(uint16_t uReadOrWrite);
+	NFC_StatusTypeDef M24SR_DisableVerificationRequirement(uint16_t uReadOrWrite);
+	NFC_StatusTypeDef M24SR_EnablePermanentState(uint16_t uReadOrWrite);
+	NFC_StatusTypeDef M24SR_DisablePermanentState(uint16_t uReadOrWrite);
+	NFC_StatusTypeDef M24SR_SendInterrupt(void);
+	NFC_StatusTypeDef M24SR_StateControl(uint8_t uSetOrReset);
+	NFC_StatusTypeDef M24SR_ManageI2CGPO(uint8_t GPO_I2Cconfig);
+	NFC_StatusTypeDef M24SR_ManageRFGPO(uint8_t GPO_RFconfig);
+	NFC_StatusTypeDef M24SR_RFConfig(uint8_t OnOffChoice);
+	NFC_StatusTypeDef M24SR_FWTExtension(uint8_t FWTbyte );
+
+
+	/* ACTION 8 --------------------------------------------------------------*
+	 * Implement here other I/O methods beyond those already implemented      *
+	 * above, which are declared extern within the component's header file.   *
+	 *------------------------------------------------------------------------*/
+
+
+	NFC_StatusTypeDef M24SR_IO_IsAnswerReady(void);
+
+	NFC_StatusTypeDef M24SR_IO_SendI2Ccommand(uint8_t NbByte , uint8_t *pBuffer);
+
+	NFC_StatusTypeDef M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte , uint8_t *pBuffer);
+
+
+	NFC_StatusTypeDef M24SR_IO_PollI2C(void);
+
+	void M24SR_IO_GPO_ReadPin(GPIO_PinState *pPinState)
+	{
+		if(GPOPin==0)
+			(*pPinState)=GPIO_PIN_RESET;
+		else
+			(*pPinState)=GPIO_PIN_SET;
+	}
+
+	void M24SR_IO_RFDIS_WritePin(GPIO_PinState PinState)
+	{
+		if(PinState==GPIO_PIN_RESET)
+			RFDisablePin=0;
+		else
+			RFDisablePin=1;
+	}
+
+	void M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_MGMT mode)
+	{
+		syncMode=mode;
+	}
+
+	void M24SR_AnswerReadyInterruptCallback(){
+		interruptIsFired=true;
+	}
+
+	/*** Component's Instance Variables ***/
+
+	/* Identity */
+	uint8_t who_am_i;
+
+	/* ACTION 9 --------------------------------------------------------------*
+	 * There should be only a unique identifier for each component, which     *
+	 * should be the "who_am_i" parameter, hence this parameter is optional.  *
+	 *------------------------------------------------------------------------*/
+	/* Type. */
+	uint8_t type;
+
+	/* Configuration. */
+	uint8_t address;
+
+	/* IO Device. */
+	I2C &dev_i2c;
+
+	/* GPIO */
+	DigitalIn GPOPin;
+	DigitalOut RFDisablePin;
+	InterruptIn answerReadyInterrupt;
+	M24SR_WAITINGTIME_MGMT syncMode;
+
+	/* Interrupts. */
+	/* ACTION 10 -------------------------------------------------------------*
+	 * Put here interrupt related objects, if needed.                         *
+	 * Note that interrupt handling is platform dependent, see                *
+	 * "Interrupt Related Methods" above.                                     *
+	 *                                                                        *
+	 * Example:                                                               *
+	 *   + mbed:                                                              *
+	 *     InterruptIn feature_int;                                           *
+	 *------------------------------------------------------------------------*/
+
+	/* Data. */
+	/* ACTION 11 -------------------------------------------------------------*
+	 * Declare here the component's data, one variable per line.              *
+	 *                                                                        *
+	 * Example:                                                               *
+	 *   int T0_out;                                                          *
+	 *   int T1_out;                                                          *
+	 *   float T0_degC;                                                       *
+	 *   float T1_degC;                                                       *
+	 *------------------------------------------------------------------------*/
+	C_APDU	command;
+	uint8_t	dataBuffer[0xFF];
+	uint8_t	uM24SRbuffer [0xFF];
+	uint8_t	uDIDbyte;
+	bool interruptIsFired;
+};
+
+#endif // __M24SR_CLASS_H
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 
+