Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: M24SR
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of X_NUCLEO_NFC01A1 by
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 31:85fdf6fd3da5, committed 2017-05-15
- Comitter:
- giovannivisentini
- Date:
- Mon May 15 13:47:03 2017 +0000
- Parent:
- 29:7a2dfd06cb29
- Commit message:
- remove M24SR_IO_PollI2C function
Changed in this revision
--- a/m24sr/M24SR.cpp Fri Apr 28 12:14:12 2017 +0000
+++ b/m24sr/M24SR.cpp Mon May 15 13:47:03 2017 +0000
@@ -55,6 +55,8 @@
#define M24SR_MAX_BYTE_OPERATION_LENGHT (246)
+#define M24SR_MAX_I2C_ACCESS_TRY 1000
+
/**
* default password, also used to enable super user mode through the I2C channel
*/
@@ -300,15 +302,7 @@
mLastCommandSend=UPDATE;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS)
- return M24SR_ReceiveUpdateBinary();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_updated_binary(this,status,mLastCommandData.offset,
- mLastCommandData.data,mLastCommandData.length);
- return status;
- }//if-else
+ return M24SR_ReceiveUpdateBinary();
}//if
return M24SR_SUCCESS;
@@ -325,20 +319,24 @@
if(status!= M24SR_SUCCESS)
return status;
//leave the gpo always up
+
if(GPOPin.is_connected()!=0){
status = M24SR_ManageI2CGPO(DEFAULT_GPO_STATUS);
if(status!= M24SR_SUCCESS)
return status;
}
+
if(RFDisablePin.is_connected()!=0){
status = M24SR_ManageRFGPO(DEFAULT_GPO_STATUS);
if(status!= M24SR_SUCCESS)
return status;
}
+
//close the session
status = M24SR_Deselect();
if(status!= M24SR_SUCCESS)
return status;
+
if(GPOPin.is_connected()!=0){
mGpoEventInterrupt.enable_irq();
}
@@ -363,7 +361,7 @@
/* Insure no access will be done just after open session */
/* The only way here is to poll I2C to know when M24SR is ready */
/* GPO can not be use with KillSession command */
- status = M24SR_IO_PollI2C();
+ //status = M24SR_IO_PollI2C();
getCallback()->on_session_open(this,status);
return status;
@@ -386,16 +384,8 @@
mLastCommandSend=DESELECT;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS)
- return M24SR_ReceiveDeselect();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_selected_application(this,status);
- return status;
- }//if-else
-
- }
+ return M24SR_ReceiveDeselect();
+ }//if
return M24SR_SUCCESS;
}
@@ -403,6 +393,9 @@
M24SR::StatusTypeDef M24SR::M24SR_ReceiveDeselect(void){
uint8_t pBuffer[4];
M24SR::StatusTypeDef status;
+
+ mLastCommandSend=NONE;
+
status = M24SR_IO_ReceiveI2Cresponse(sizeof(pBuffer), pBuffer);
getCallback()->on_deselect(this,status);
return status;
@@ -428,7 +421,7 @@
/* Insure no access will be done just after open session */
/* The only way here is to poll I2C to know when M24SR is ready */
/* GPO can not be use with KillSession command */
- status = M24SR_IO_PollI2C();
+ //status = M24SR_IO_PollI2C();
getCallback()->on_session_open(this,status);
return status;
@@ -473,14 +466,7 @@
mLastCommandSend=SELECT_APPLICATION;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS)
- return M24SR_ReceiveSelectApplication();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_selected_application(this,status);
- return status;
- }//if-else
+ return M24SR_ReceiveSelectApplication();
}//if
return M24SR_SUCCESS;
@@ -557,14 +543,7 @@
mLastCommandSend=SELECT_CC_FILE;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS)
- return M24SR_ReceiveSelectCCfile();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_selected_CC_file(this,status);
- return status;
- }//if-else
+ return M24SR_ReceiveSelectCCfile();
}//if
return M24SR_SUCCESS;
@@ -610,7 +589,7 @@
/* copy the number of byte of the data field */
command.Body.LC = sizeof(pDataOut);
command.Body.pData = pDataOut;
- /* build the I²C command */
+ /* build the I2C command */
M24SR_BuildIBlockCommand(M24SR_CMDSTRUCT_SELECTCCFILE, &command, uDIDbyte,
&NbByte, pBuffer);
@@ -624,14 +603,7 @@
mLastCommandSend=SELECT_SYSTEM_FILE;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS)
- return M24SR_ReceiveSelectSystemfile();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_selected_system_file(this,status);
- return status;
- }//if-else
+ return M24SR_ReceiveSelectSystemfile();
}//if
return M24SR_SUCCESS;
@@ -690,14 +662,7 @@
mLastCommandSend=SELECT_NDEF_FILE;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS)
- return M24SR_ReceiveSelectNDEFfile();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_selected_NDEF_file(this,status);
- return status;
- }
+ return M24SR_ReceiveSelectNDEFfile();
}
return M24SR_SUCCESS;
@@ -765,14 +730,7 @@
mLastCommandData.offset=Offset;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveReadBinary();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_read_byte(this,status,Offset,pBufferRead,NbByteToRead);
- return status;
- }//if-else
+ return M24SR_ReceiveReadBinary();
}//if
return M24SR_SUCCESS;
@@ -846,14 +804,7 @@
mLastCommandData.length=NbByteToRead;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveReadBinary();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_read_byte(this,status,Offset,pBufferRead,NbByteToRead);
- return status;
- }//if-else
+ return M24SR_ReceiveReadBinary();
}//if
return M24SR_SUCCESS;
@@ -904,14 +855,7 @@
mLastCommandData.offset=Offset;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveUpdateBinary();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_updated_binary(this,status,Offset,pDataToWrite,NbByteToWrite);
- return status;
- }//if-else
+ return M24SR_ReceiveUpdateBinary();
}
return M24SR_SUCCESS;
@@ -1009,14 +953,7 @@
mLastCommandData.offset=uPwdId;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS)
- return M24SR_ReceiveVerify();
- else{
- mLastCommandSend = NONE;
- getCallback()->on_verified(this,status,constToPasswordType(uPwdId),pPwd);
- return status;
- }
+ return M24SR_ReceiveVerify();
}
return M24SR_SUCCESS;
@@ -1036,7 +973,6 @@
getCallback()->on_verified(this,status,type,data);
return status;
}
-
status = M24SR_IsCorrectCRC16Residue(respBuffer, M24SR_STATUSRESPONSE_NBBYTE);
getCallback()->on_verified(this,status,type,data);
return status;
@@ -1091,15 +1027,7 @@
mLastCommandData.offset = (uint8_t)uPwdId;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS){
- return M24SR_ReceiveChangeReferenceData();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_change_reference_data(this,status,
- constToPasswordType(uPwdId), pPwd);
- return status;
- }//if-else
+ return M24SR_ReceiveChangeReferenceData();
}//if
return M24SR_SUCCESS;
@@ -1167,15 +1095,7 @@
mLastCommandData.offset = (uint8_t)uReadOrWrite;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status == M24SR_SUCCESS){
- return M24SR_ReceiveEnableVerificationRequirement();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_enable_verification_requirement(this,status,
- constToPasswordType(uReadOrWrite));
- return status;
- }//if-else
+ return M24SR_ReceiveEnableVerificationRequirement();
}//if
return M24SR_SUCCESS;
@@ -1243,15 +1163,7 @@
mLastCommandData.offset = (uint8_t)uReadOrWrite;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveDisableVerificationRequirement();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_disable_verification_requirement(this,status,
- constToPasswordType(uReadOrWrite));
- return status;
- }//if-else
+ return M24SR_ReceiveDisableVerificationRequirement();
}
return M24SR_SUCCESS;
@@ -1320,15 +1232,7 @@
mLastCommandData.offset = (uint8_t)uReadOrWrite;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveEnablePermanentState();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_enable_permanent_state(this,status,
- constToPasswordType(uReadOrWrite));
- return status;
- }//if-else
+ return M24SR_ReceiveEnablePermanentState();
}
return M24SR_SUCCESS;
@@ -1395,15 +1299,7 @@
mLastCommandData.offset = (uint8_t)uReadOrWrite;
if(mCommunicationType==M24SR::SYNC){
- status = M24SR_IO_PollI2C();
- if(status==M24SR_SUCCESS){
- return M24SR_ReceiveDisablePermanentState();
- }else{
- mLastCommandSend = NONE;
- getCallback()->on_disable_permanent_state(this,status,
- constToPasswordType(uReadOrWrite));
- return status;
- }//if-else
+ return M24SR_ReceiveDisablePermanentState();
}
return M24SR_SUCCESS;
@@ -1458,7 +1354,7 @@
/* send the request */
errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_PollI2C());
+ //errchk(M24SR_IO_PollI2C());
/* read the response */
errchk(
M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
@@ -1506,7 +1402,7 @@
/* send the request */
errchk(M24SR_IO_SendI2Ccommand(NbByte, pBuffer));
- errchk(M24SR_IO_PollI2C());
+ //errchk(M24SR_IO_PollI2C());
/* read the response */
errchk(
M24SR_IO_ReceiveI2Cresponse (M24SR_STATUSRESPONSE_NBBYTE , pBuffer ));
@@ -1524,7 +1420,6 @@
if (GPO_I2Cconfig > STATE_CONTROL) {
return M24SR_IO_ERROR_PARAMETER;
}
-
//enable the callback for change the gpo
mComponentCallback = &mManageGPOCallback;
mManageGPOCallback.set_new_GPO_config(true,GPO_I2Cconfig);
@@ -1565,34 +1460,34 @@
M24SR::StatusTypeDef M24SR::M24SR_IO_SendI2Ccommand(uint8_t NbByte,
uint8_t *pBuffer) {
- int ret = dev_I2C.write(address, (char*) pBuffer, NbByte);
- if (ret == 0)
+
+ int nTry = 0;
+ int status =1;
+ while (status != 0 && (nTry++)<M24SR_MAX_I2C_ACCESS_TRY) {
+ status = dev_I2C.write(address, (char*) pBuffer, NbByte);
+
+ }
+ if (status == 0)
return M24SR_SUCCESS;
+
return M24SR_IO_ERROR_I2CTIMEOUT;
+
}
M24SR::StatusTypeDef M24SR::M24SR_IO_ReceiveI2Cresponse(uint8_t NbByte,
uint8_t *pBuffer) {
- int ret = dev_I2C.read(address, (char*) pBuffer, NbByte);
- if (ret == 0)
+
+ int nTry = 0;
+ int status =1;
+ while (status != 0 && (nTry++)<M24SR_MAX_I2C_ACCESS_TRY) {
+ status = dev_I2C.read(address, (char*) pBuffer, NbByte);
+ }
+ if (status == 0)
return M24SR_SUCCESS;
-
+
return M24SR_IO_ERROR_I2CTIMEOUT;
}
-M24SR::StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
-
- int status = 1;
- char buffer;
- while (status != 0) {
- status = dev_I2C.read(address, &buffer, 1, false);
- }
-
- if (status == 0)
- return M24SR_SUCCESS;
- //else
- return M24SR_IO_ERROR_I2CTIMEOUT;
-}
M24SR::StatusTypeDef M24SR::manage_event(void){
--- a/m24sr/M24SR.h Fri Apr 28 12:14:12 2017 +0000
+++ b/m24sr/M24SR.h Mon May 15 13:47:03 2017 +0000
@@ -1140,9 +1140,12 @@
virtual void on_verified(M24SR *nfc,StatusTypeDef status,
PasswordType_t,const uint8_t*){
+ printf("Verify %d\r\n",status);
if(status!=M24SR_SUCCESS)
return onFinishCommand(nfc,status);
+
+
if(mEnable){
nfc->disable_permanent_state(mType==WRITE? WritePwd : ReadPwd);
}else
@@ -1152,6 +1155,7 @@
virtual void on_disable_permanent_state(M24SR *nfc, StatusTypeDef status,
PasswordType_t type ){
+ printf("on_disable_permanent_state %d\r\n",status);
if(status!=M24SR_SUCCESS)
return onFinishCommand(nfc,status);
@@ -1160,10 +1164,12 @@
virtual void on_disable_verification_requirement(M24SR *nfc , StatusTypeDef status,
PasswordType_t ){
+ printf("on_disable_verification_requirement %d\r\n",status);
onFinishCommand(nfc,status);
}
virtual void on_enable_permanent_state(M24SR *nfc ,StatusTypeDef status,PasswordType_t ){
+ printf("on_enable_permanent_state %d\r\n",status);
onFinishCommand(nfc,status);
}
--- a/m24sr/NDefNfcTagM24SR.cpp Fri Apr 28 12:14:12 2017 +0000
+++ b/m24sr/NDefNfcTagM24SR.cpp Mon May 15 13:47:03 2017 +0000
@@ -122,7 +122,8 @@
bool NDefNfcTagM24SR::close_session() {
mDevice.set_callback(&mCloseSessionCallback);
- return mDevice.deselect() == M24SR::M24SR_SUCCESS;
+ M24SR::StatusTypeDef status = mDevice.deselect();
+ return status == M24SR::M24SR_SUCCESS;
}
void NDefNfcTagM24SR::WriteByteCallback::on_updated_binary(M24SR *nfc,

X-NUCLEO-NFC01A1 Dynamic NFC Tag