2024-11-21 04:46 PM - last edited on 2024-11-22 01:25 AM by Andrew Neil
Steps Taken So Far
1. Downloaded the X-CUBE-NFC6 expansion pack on the STM32CubeIDE (Have already set up the project for my dev board)
2. Configured the pins under platform settings for the expansion pack. I presume that this is where I have gone wrong. I can provide further information as required. But one thing I had verified is that the SPI communication between the dev board and the expansion pack works. (Will attach my entire project under the post)
3. When I try to run initialise the NFC using the MX_X_CUBE_NFC6_Init(); function. I am failing this condition and hence my code breaks (i found through debugging)
/* Check if IC Identity Register contains ST25R3916's IC type code */
#if defined(ST25R3916)
if( (ID & ST25R3916_REG_IC_IDENTITY_ic_type_mask) != ST25R3916_REG_IC_IDENTITY_ic_type_st25r3916 )
{
return false;
}
My Thoughts
I am sure that there are multiple steps I may have missed while setting this project up and that's why this whole thing has gone wrong but yeah.
I have skimmed through the internet and the community to find similar problems and solutions for those problems. One post in particular that I cam across which I know is very similar is this one
https://community.st.com/t5/st25-nfc-rfid-tags-and-readers/how-to-create-a-project-with-x-cube-nfc06/m-p/126232
Considering that this is my first time I am working with this dev board and expansion pack there may be a lot of mistakes that I have made along the way. It would be of great help if I was given some guidance on how I can get the NFC8 polling example working with the u575ZI-q board.
Please let me know if further information is required. (I have attached a zip file which consists my entire project below)
Solved! Go to Solution.
2024-11-25 04:52 AM
Hi Charan,
this part of the code demonstrates the ST25R3916B wakeup/tag detection functionality. If you you do not plan to use this functionality, you can simply undefine PLATFORM_USER_BUTTON_PIN. Otherwise, you can map the B1 button of the NUCLEO-U575ZI-Q onto the PLATFORM_USER_BUTTON. Note that compare to NUCLEO_L476RG, the B1 button has an inverted logic on NUCLEO-U575ZI-Q (I guess this is to optimize the power consumption), thus the platformGpioIsLow test should be replaced by platformGpioIsHigh. I will report this to the FW integration team to fix this in a future release of the X-CUBE package.
Rgds
BT
2024-11-22 01:22 AM - edited 2024-11-22 01:23 AM
Hi,
the SPI CPHA should be "2 Edge" as the device "have a standard serial peripheral interface with clock polarity of 0, a clock phase of 1" (see ST25R3916 datasheet).
Also, the interrupt for the line connected to the device interrupt should be enabled. If I am not wrong the device interrupt is connected through Arduino A0 to the PA3/Line3 of the MCU but the interrupt is not enabled:
I suggest to enable ST25R_SELFTEST compilation flag: this will help to investigate SPI communication and interrupt configuration issue. You can also connect a logic analyzer on SPI (CLK/MIO/MOSI/CS) + ST25 Interrupt and send us the trace file if you still face issues.
Rgds
BT
2024-11-22 03:52 PM
Hi,
Thank you for your response. After I posted that I went back and looked at what I might have done wrong and noticed whatever you said. Followed the necessary steps and got the example code working (NFC08A1 Polling).The NFC card is being read and the necessary output could be seen via the terminal. Your response just confirmed that that was indeed where I was going wrong and fixed it the right way :D (Thanks to your previous response on the community post that I had linked earlier)
However I had to change up the state machine given in that example code. The reason for this had to do with this piece of code
void demoCycle( void )
{
static rfalNfcDevice *nfcDevice;
rfalNfcWorker(); /* Run RFAL worker periodically */
#if defined(PLATFORM_USER_BUTTON_PORT) && defined(PLATFORM_USER_BUTTON_PIN)
/*******************************************************************************/
/* Check if USER button is pressed */
if( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN) && state!= DEMO_ST_DISCOVERY)
{
discParam.wakeupEnabled = !discParam.wakeupEnabled; /* enable/disable wakeup */
state = DEMO_ST_START_DISCOVERY; /* restart loop */
platformLog("Toggling Wake Up mode %s\r\n", discParam.wakeupEnabled ? "ON": "OFF");
/* Debounce button */
// while( platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN) );
}
#endif /* PLATFORM_USER_BUTTON_PIN */
switch( state )
{
/*******************************************************************************/
case DEMO_ST_START_DISCOVERY:
platformLedOff(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN);
platformLedOff(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN);
platformLedOff(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN);
platformLedOff(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN);
platformLedOff(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN);
platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN);
rfalNfcDeactivate( RFAL_NFC_DEACTIVATE_IDLE );
ReturnCode err = rfalNfcDiscover(&discParam);
if (err != RFAL_ERR_NONE) {
platformLog("Discovery Error: %d\r\n", err);
return false;
}
platformLog("Discovery Params - Techs2Find: 0x%x, TotalDuration: %d\r\n",
discParam.techs2Find, discParam.totalDuration);
rfalNfcDiscover( &discParam );
platformLog("Discovery Params - Techs2Find: 0x%x, TotalDuration: %d\r\n",
discParam.techs2Find, discParam.totalDuration);
multiSel = false;
state = DEMO_ST_DISCOVERY;
break;
/*******************************************************************************/
case DEMO_ST_DISCOVERY:
rfalNfcState state_1 = rfalNfcGetState();
// platformLog("Current RFAL NFC State: %d\r\n", state_1);
if( rfalNfcIsDevActivated( rfalNfcGetState() ) )
{
rfalNfcGetActiveDevice( &nfcDevice );
switch( nfcDevice->type )
{
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCA:
platformLedOn(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN);
switch( nfcDevice->dev.nfca.type )
{
case RFAL_NFCA_T1T:
platformLog("ISO14443A/Topaz (NFC-A T1T) TAG found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
break;
case RFAL_NFCA_T4T:
platformLog("NFCA Passive ISO-DEP device found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
demoAPDU();
break;
case RFAL_NFCA_T4T_NFCDEP:
case RFAL_NFCA_NFCDEP:
platformLog("NFCA Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
demoP2P( nfcDevice );
break;
default:
platformLog("ISO14443A/NFC-A card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
demoT2t();
break;
}
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCB:
platformLog("ISO14443B/NFC-B card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN);
if( rfalNfcbIsIsoDepSupported( &nfcDevice->dev.nfcb ) )
{
demoAPDU();
}
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCF:
if( rfalNfcfIsNfcDepSupported( &nfcDevice->dev.nfcf ) )
{
platformLog("NFCF Passive P2P device found. NFCID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ) );
demoP2P( nfcDevice );
}
else
{
platformLog("Felica/NFC-F card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ));
demoNfcf( &nfcDevice->dev.nfcf );
}
platformLedOn(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN);
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCV:
{
uint8_t devUID[RFAL_NFCV_UID_LEN];
ST_MEMCPY( devUID, nfcDevice->nfcid, nfcDevice->nfcidLen ); /* Copy the UID into local var */
REVERSE_BYTES( devUID, RFAL_NFCV_UID_LEN ); /* Reverse the UID for display purposes */
platformLog("ISO15693/NFC-V card found. UID: %s\r\n", hex2Str(devUID, RFAL_NFCV_UID_LEN));
platformLedOn(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN);
demoNfcv( &nfcDevice->dev.nfcv );
}
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_ST25TB:
platformLog("ST25TB card found. UID: %s\r\n", hex2Str( nfcDevice->nfcid, nfcDevice->nfcidLen ));
platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN);
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_AP2P:
case RFAL_NFC_POLL_TYPE_AP2P:
platformLog("NFC Active P2P device found. NFCID3: %s\r\n", hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
platformLedOn(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN);
demoP2P( nfcDevice );
break;
/*******************************************************************************/
case RFAL_NFC_POLL_TYPE_NFCA:
case RFAL_NFC_POLL_TYPE_NFCF:
platformLog("Activated in CE %s mode.\r\n", (nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? "NFC-A" : "NFC-F");
platformLedOn( ((nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? PLATFORM_LED_A_PORT : PLATFORM_LED_F_PORT),
((nfcDevice->type == RFAL_NFC_POLL_TYPE_NFCA) ? PLATFORM_LED_A_PIN : PLATFORM_LED_F_PIN) );
demoCE( nfcDevice );
break;
/*******************************************************************************/
default:
break;
}
rfalNfcDeactivate( RFAL_NFC_DEACTIVATE_IDLE );
#if !defined(DEMO_NO_DELAY_IN_DEMOCYCLE)
switch( nfcDevice->type )
{
case RFAL_NFC_POLL_TYPE_NFCA:
case RFAL_NFC_POLL_TYPE_NFCF:
break; /* When being in card emulation don't delay as some polling devices (phones) rely on tags to be re-discoverable */
default:
platformDelay(500); /* Delay before re-starting polling loop to not flood the UART log with re-discovered tags */
}
#endif /* DEMO_NO_DELAY_IN_DEMOCYCLE */
state = DEMO_ST_START_DISCOVERY;
}
break;
/*******************************************************************************/
case DEMO_ST_NOTINIT:
default:
break;
}
}
So if you notice, I've set up the states such that once it goes into the if condition on line 10, it never goes back into that condition again and just switches between the other two states. I do know that this is because I do not have the button configuration set up for that properly.
I was wondering what I have to do in order to get that same user button functionality working and if there's anything else that I might need to look at. Or if I do not want to use that user button functionality, how I can completely get rid of it? Because when I included the NFC application on the the .ioc file, I had to configure the button gpio external interrupt (BSP button) and I am pretty sure I have messed that up. I don't have access the dev board rn and won't until Monday, so anything to do with testing would have to wait until then. Thank you so much for your help and please do let me know if you need further clarification. Once again I have attached the updated project zip file below.
Cheers,
Charan
2024-11-25 04:52 AM
Hi Charan,
this part of the code demonstrates the ST25R3916B wakeup/tag detection functionality. If you you do not plan to use this functionality, you can simply undefine PLATFORM_USER_BUTTON_PIN. Otherwise, you can map the B1 button of the NUCLEO-U575ZI-Q onto the PLATFORM_USER_BUTTON. Note that compare to NUCLEO_L476RG, the B1 button has an inverted logic on NUCLEO-U575ZI-Q (I guess this is to optimize the power consumption), thus the platformGpioIsLow test should be replaced by platformGpioIsHigh. I will report this to the FW integration team to fix this in a future release of the X-CUBE package.
Rgds
BT