FTM mailbox message length
Project : STM32L476RG-Nucleo\Applications\X-NUCLEO-NFC04A1\FTM
For read, you always add one to the result of the length read:
*msg_len = mblength + 1;
Seems reasonable when mblengh is 255 , and you add one to read 256 bytes , which is the max mailbox size.
But not after Init. As I clear the mailbox, and read it, mblength is 0, as expected. But I still read 1 byte ( = 0xFF)
What is this byte? kinda confusing!
Using you package code:
ST25FTM_MessageStatus_t ST25FTM_ReadMessage(uint8_t *msg, uint32_t* msg_len)
{
int ret = NFCTAG_OK;
uint16_t mblength = 0;
/* Read length of message */
ret = NFC04A1_NFCTAG_ReadMBLength_Dyn(0, (uint8_t *)&mblength );
if( ret != NFCTAG_OK )
{
return ST25FTM_MSG_ERROR;
}
*msg_len = mblength + 1;
/* Read all data in Mailbox */
ret = NFC04A1_NFCTAG_ReadMailboxData( 0, msg, 0, *msg_len );
if(ret == NFCTAG_OK)
{
mailboxStatus = ST25FTM_MESSAGE_EMPTY;
/* Trick to automatically detect the max frame length of the reader
To have this auto detection working, the reader must send a long command
before receiveing a long response.
*/
ST25FTM_Ctrl_Byte_t ctrl;
ctrl.byte = msg[0];
if((!ST25FTM_CTRL_HAS_PKT_LEN(ctrl)) && !(msg[0] & ST25FTM_STATUS_BYTE))
{
ST25FTM_SetRxFrameMaxLength(*msg_len);
ST25FTM_SetTxFrameMaxLength(*msg_len);
}
return ST25FTM_MSG_OK;
}
return ST25FTM_MSG_ERROR;
}
