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
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
Diff: m24sr/m24sr_class.cpp
- Revision:
- 18:10def2fefa8a
- Parent:
- 17:c750fff4a096
- Child:
- 19:0b65a5813059
--- a/m24sr/m24sr_class.cpp Tue Jan 19 10:24:53 2016 +0000
+++ b/m24sr/m24sr_class.cpp Fri Jan 22 09:04:51 2016 +0000
@@ -354,9 +354,15 @@
*/
NFC_StatusTypeDef M24SR::M24SR_Init(M24SR_InitTypeDef *notUsed) {
(void) notUsed;
-
+ //until we don't set the gpo usage, just do a polling on the
+ //i2c read
+ M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_POLLING);
+ //force to open a i2c session
errchk(M24SR_KillSession())
+ //ask to set the gpo low when the answer is ready, so we can use
+ //the interrupt for polling
errchk(M24SR_ManageI2CGPO(I2C_ANSWER_READY))
+ //close the session
errchk(M24SR_Deselect())
return NFC_SUCCESS;
@@ -1043,25 +1049,25 @@
return NFC_IO_ERROR_PARAMETER;
}
- /* we must not be in interrupt mode for I2C synchro as we will change GPO purpose */
- M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_POLLING);
-
errchk(M24SR_SelectApplication());
errchk(M24SR_SelectSystemfile());
errchk(M24SR_ReadBinary(0x0004, 0x01, &GPO_config))
-
+ errchk(M24SR_Verify(I2C_PWD, 0x10, DEFAULT_PASSWORD));
+
/* Update only GPO purpose for I2C */
GPO_config = (GPO_config & 0xF0) | GPO_I2Cconfig;
-
- errchk(M24SR_Verify(I2C_PWD, 0x10, DEFAULT_PASSWORD));
-
+
errchk(M24SR_UpdateBinary(0x0004, 0x01, &(GPO_config)));
-
- /* if we have set interrupt mode for I2C synchro we can enable interrupt mode */
+
+ /* if we use the gpo for know when the asnwer is ready,
+ we can use the interrupt for do the polling, otherwise just wait on the
+ i2c read */
if (GPO_I2Cconfig == I2C_ANSWER_READY)
M24SR_IO_SetI2CSynchroMode(M24SR_INTERRUPT_GPO);
+ else
+ M24SR_IO_SetI2CSynchroMode(M24SR_WAITINGTIME_POLLING);
return NFC_SUCCESS;
}
@@ -1114,20 +1120,12 @@
return NFC_IO_ERROR_I2CTIMEOUT;
}
-#define M24SR_POLL_DELAY 10
-/* In case M24SR will reply ACK failed allow to perform retry before returning error (HAL option not used) */
-#define M24SR_I2C_POLLING 2000
-
NFC_StatusTypeDef M24SR::M24SR_IO_PollI2C(void) {
int status = 1;
- uint32_t nbTry = 0;
char buffer;
- //
- wait_ms(M24SR_POLL_DELAY);
- while (status != 0 && nbTry < M24SR_I2C_POLLING) {
+ while (status != 0) {
status = dev_I2C.read(address, &buffer, 1, false);
- nbTry++;
}
if (status == 0)
@@ -1137,49 +1135,17 @@
}
NFC_StatusTypeDef M24SR::M24SR_IO_IsAnswerReady(void) {
- uint32_t retry = 0xFFFFF;
- int8_t stable = 0;
- uint8_t PinState;
-
+
switch (syncMode) {
case M24SR_WAITINGTIME_POLLING:
return M24SR_IO_PollI2C();
- case M24SR_WAITINGTIME_TIMEOUT:
- // M24SR FWI=5 => (256*16/fc)*2^5=9.6ms but M24SR ask for extended time to program up to 246Bytes.
- // can be improved by
- wait_ms(80);
- return NFC_SUCCESS;
-
- case M24SR_WAITINGTIME_GPO:
- do {
- M24SR_IO_GPO_ReadPin(&PinState);
- if (PinState == GPIO_PIN_RESET) {
- stable++;
- }
- retry--;
- } while (stable < 5 && retry > 0);
- if (!retry)
- goto Error;
- return NFC_SUCCESS;
-
case M24SR_INTERRUPT_GPO:
- /* Check if the GPIO is not already low before calling this function */
- M24SR_IO_GPO_ReadPin(&PinState);
-
- if (PinState == GPIO_PIN_SET) {
-
- answerReadyInterrupt.disable_irq();
- interruptIsFired = false;
- answerReadyInterrupt.enable_irq();
-
- while (!interruptIsFired ){
- __WFE();
- }//while
- //disable the interrupt
-
- }//if
+ while (!interruptIsFired ){
+ __WFE();
+ }//while
+ interruptIsFired = false;
return NFC_SUCCESS;
@@ -1187,7 +1153,6 @@
return NFC_IO_ERROR_I2CTIMEOUT;
}
- Error: return NFC_IO_ERROR_I2CTIMEOUT;
}
////////////////////////hight level utility function //////////////////////////

X-NUCLEO-NFC01A1 Dynamic NFC Tag