cancel
Showing results for 
Search instead for 
Did you mean: 

Payload size not correctly written NDEF file

PierreL
Associate II

Ask your question
Why is the payload size not correctly written on my NDEF file?

Environment :

  • Target: STM32WB55rg
  • Target OS: baremetal
  • Host OS: Windows
  • Toolchain: STM32cubeIDE

Logs and console output if applicable
I use it in my project NFC tag, which I read and write. I use the NDEF format for my tag. The content is something like this :
Color: red
Size: 2.5
Length: 200.0

I use X-cube-NFC-6  with the NDEF library.
I have no problem reading the NFC tag. My main issue is with writing. Sometimes the library does not write the payload size in the header.
Here is what I got for the correct header:
E1 40 0E 01 03 29 D1 01 25 54 02
And here is what I got for the wrong header :
E1 40 0E 01 03 00 D1 01 25 54 02

What is stranger, is that the content is correctly written.
(for example, the length goes from 200.0 to 199.8 )

What bothers me the most is that the writing of the header part is inside the ST library; I only pass content I went to write.

Here the function to write that I use :

GlobalErrorInfoCodes ST25R3916Driver_ndefWrite(ST25R3916Handle * st25)
{
    GlobalErrorInfoCodes      err;
    ndefConstBuffer bufTextLangText;
    ndefConstBuffer8 bufTextLangCode;
    ndefType        text;
    ndefRecord      record;
    ndefMessage     message;
    static uint8_t ndefTextLangCode[] = "en";

    /*
     * Message creation
     */

    err  = ndefMessageInit(&message); /* Initialize message structure */
    bufTextLangCode.buffer = ndefTextLangCode;
    bufTextLangCode.length = strlen((char *)ndefTextLangCode);

    bufTextLangText.buffer = (uint8_t *) st25->bufferOutFifo;
    bufTextLangText.length = strlen((char *)st25->bufferOutFifo);
    err  = ndefMessageInit(&message);  /* Initialize message structure */
    err |= ndefRtdTextInit(&text, TEXT_ENCODING_UTF8, &bufTextLangCode, &bufTextLangText); /* Initialize Text type structure */
    err |= ndefRtdTextToRecord(&text, &record); /* Encode Text Record */
    err |= ndefMessageAppend(&message, &record); /* Append Text record to message */
    if( err != ERR_NONE )
    {
        //platformLog("Message creation failed\r\n", err);
        return err;
    }


	rfalNfcWorker();
	if( rfalNfcIsDevActivated(rfalNfcGetState()) )
	{
		/*
			* Retrieve NFC device
			*/
		rfalNfcGetActiveDevice(&nfcDevice);

		/*
			* Perform NDEF Context Initialization
			*/
		err = ndefPollerContextInitialization(&ndefCtx, nfcDevice);
		if( err != ERR_NONE )
		{
			return err;
		}

		/*
			* Perform NDEF Detect procedure
			*/
		err = ndefPollerNdefDetect(&ndefCtx, NULL);
		if( err != ERR_NONE )
		{
			return err;
		}

		/*
			* Perform NDEF write procedure
			*/
		{
			err = ERR_BUSY;
		}
		err = ndefPollerWriteMessage(&ndefCtx, &message);
		if( err != ERR_NONE )
		{
			return err;
		}
		return err;
	}
	err = ERR_WRITE_NOT_DONE;
    return err;
}
1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

The NFC Digital Technical Specifications defines a retry mechanism in case of so called transmission errors. In our implementation, RFAL_ERR_FRAMING, RFAL_ERR_CRC, RFAL_ERR_PAR and RFAL_ERR_TIMEOUT are considered as transmission error. I would suggest to modify the rfalT5TIsTransmissionError macro in ndef_t5t_rf.c to add RFAL_ERR_RF_COLLISION:

#define rfalT5TIsTransmissionError(err)      ( ((err) == RFAL_ERR_FRAMING) || ((err) == RFAL_ERR_CRC) || ((err) == RFAL_ERR_PAR) || ((err) == RFAL_ERR_TIMEOUT) || ((err) == RFAL_ERR_RF_COLLISION) )

You can also increase the number of retries (default value is 2, you can increase up to 5) by defining NDEF_T5T_N_RETRY_ERROR=<yourValue> as compilation switch.

Anyway, if the tag is moving and reaching the limit of the operating volume, the NDEF write is likely to fail.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
Ulysses HERNIOSUS
ST Employee

Hi PierreL,

what is the tag that you are using for writing? Which type and exact model?

When writing NDEF it starts by first writing the NDEF size to 0 and after having written all the payload bytes it will write the length to the expected value. So possibly something wrong with the last step.

You are saying it sometimes doesn't work. So possibly some race. Can you try adding a delay of e.g. 20ms after the write of the NDEF message and see if it improves?

BR, Ulysses

Brian TIDAL
ST Employee

Hi,

according to NFC T2T, T3T, T4T and T5T Technical Specifications, the L-field (length) has to be set to 0 before writing the V-field (the NDEF content) and once the V-field has been properly updated, the L-field is set to the actual NDEF length. So, it is likely that the communication is lost during the L-field update.

Can you share more details about your tag (manufacturer, model)? Also, what is the return code of ndefPollerWriteMessage when this error occurs? If the return code of ndefPollerWriteMessage is different from RFAL_ERR_NONE, make sure to retry to update the tag.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

When I put a delay of 20 ms after

err = ndefPollerWriteMessage(&ndefCtx, &message); 

It improves a bit but I still got error some time to times

Here's the tag info (when not working)

 

For tag info I answer above.

I got this error :
RFAL_ERR_RF_COLLISION


So yes,I possibly move the tag when writing, that's why I got the problem... But in my application tag will be moving...

Brian TIDAL
ST Employee

Hi,

The NFC Digital Technical Specifications defines a retry mechanism in case of so called transmission errors. In our implementation, RFAL_ERR_FRAMING, RFAL_ERR_CRC, RFAL_ERR_PAR and RFAL_ERR_TIMEOUT are considered as transmission error. I would suggest to modify the rfalT5TIsTransmissionError macro in ndef_t5t_rf.c to add RFAL_ERR_RF_COLLISION:

#define rfalT5TIsTransmissionError(err)      ( ((err) == RFAL_ERR_FRAMING) || ((err) == RFAL_ERR_CRC) || ((err) == RFAL_ERR_PAR) || ((err) == RFAL_ERR_TIMEOUT) || ((err) == RFAL_ERR_RF_COLLISION) )

You can also increase the number of retries (default value is 2, you can increase up to 5) by defining NDEF_T5T_N_RETRY_ERROR=<yourValue> as compilation switch.

Anyway, if the tag is moving and reaching the limit of the operating volume, the NDEF write is likely to fail.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks,

Now I got this error ERR_TIMEOUT But I saw that this error is already in the rfalT5TIsTransmissionError macro. I will try to add a flag to write only once to avoid writing multiple times and write when a tag is in motion

Brian TIDAL
ST Employee

Hi,

"I will try to add a flag to write only once to avoid writing multiple times " ==> Once your tag has been written, you can check for the presence of the tag in the field by for example sending a 1 slot inventory command (rfalNfcvPollerInventory) until you receive a RFAL_ERR_TIMEOUT. There is one example in the ndef_demo.c  (see /* Loop until tag is removed from the field */ for RFAL_NFC_LISTEN_TYPE_NFCV case).

Rgds

BT

 

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.