cancel
Showing results for 
Search instead for 
Did you mean: 

Is the X-CUBE-NFC3 library what I should be using?

ADoug.1
Associate II

Hello,

I am currently working on a project with the CR95HF chip. The chip has to be controlled over UART (by a STM32L4S7ZITx) and I would like a library which provides basic functions, such as being able to read a presented tag's UID and be able to read from and write to the presented tag.

Does the X-CUBE-NFC3 library provide this functionality?

If so, how exactly do I integrate it into my existing STM32CubeIDE project? I am aware it cannot be added through STM32CubeMx so of the whole download provided at https://www.st.com/en/embedded-software/x-cube-nfc3.html#overview what part needs integrated into my project to get the functionality described above and how do I do this?

Thanks!

Amy

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

  • in your project, replace st25r95_com_spi.c by st25r95_com_uart.c (this file is located in STM32CubeExpansion_NFC3_V2.1.0\Drivers\BSP\Components\ST25R95-
  • add #define ST25R95_INTERFACE_UART  true in GLOBAL DEFINES section of platform.h
  • initialize the UART in main.c and stm32f1xx_hal_msp.c, make sure to have the UART interrup being enabled
  • populate HAL_UART_TxCpltCallback, HAL_UART_RxCpltCallback and HAL_UART_ErrorCallback to call st25r95UartTxCpltCallback (resp. st25r95UartRxCpltCallback, st25r95UartErrorCallback). See code below or attached files.
  • add #include "st25r95_com.h" in main.c
  • make sure to have SSI_0 selecting UART communication mode in you initialization
  • Make sure to power cycle the X-NUCLEO-NFC03A1 the first time after you have donwloaded the FW with UART support (otherwise SPI interface will still be selected...)

/* USER CODE BEGIN 4 */
 
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
    if (huart->Instance == USART1)
    {
        st25r95UartTxCpltCallback();
    }
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    if (huart->Instance == USART1)
    {
        st25r95UartRxCpltCallback();
    }
}
 
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
    if (huart->Instance == USART1)
    {
        st25r95UartErrorCallback();
    }
}
 
/* USER CODE END 4 */

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

24 REPLIES 24
Brian TIDAL
ST Employee

Hi Amy,

 X-CUBE-NFC3 provides

  • a hardware independent NFC communication stack. This NFC stack provides NDEF support and read write support for the various tag technologies
  • a ST25R95/CR95HF driver. This driver enables the communication between the MCU and the CR95HF. By default, this driver supports SPI communication but support of UART can be provided on demand. Anyway, I would recommend to use the SPI communication mode rather than the UART communication mode
  • 2 applications:
    • simple polling application: this application polls for the various technologies and once a tag is discovered, its UID is displayed on the serial port
    • NDEF application: this application reads or writes NDEF from/to a tag.
    • those applications come with full project files for main IDEs including STM32CubeIDE.

For you application, you can use the polling application as a starting point and you can open STM32CubeExpansion_NFC3_V2.1.0\Projects\STM32L476RG-Nucleo\Applications\PollingTagDetect\STM32CubeIDE\STM32L476RG-Nucleo_PollingTagDetect project to have an example.The files you need to integrate in your own project are:

  • the files in Middleware/ST group
  • the files in BSP/Components group
  • demo.c and logger.c from Application/User group

In you main.c, you need to add the code from the main.c from the polling example:

  • includes between /* USER CODE BEGIN Includes */ and /* USER CODE END Includes */
  • code between /* USER CODE BEGIN 2 */ and /* USER CODE END 2 */
  • code between /* USER CODE BEGIN WHILE */ and /* USER CODE END WHILE */

In you Inc folder, copy the platform.h from the example and update the pin assignment accordingly.

i would suggest you first start to integrate in SPI mode and then follow the instruction in https://community.st.com/s/question/0D50X0000B7YwL7SQK/how-to-use-uart-interface-instead-of-spi-with-xnucleonfc03a1-and-xcubenfc3-polling-demo to add the support of UART.

By the way, just for my information why do you prefer to use UART communication rather than SPI?

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.
ADoug.1
Associate II

Hi BT,

Thank you very much for your response!

Unfortunately the way our board has been designed means that we only have the UART lines of communication between our STM and CR95HF so that's why I can't use SPI.

I have started trying to test the library using the M24LR discovery board though as this gives me access to trying the library with SPI. My hope is that once I know how to use the library with SPI then it will be easier for me to convert it and work with UART on my final board.

Unfortunately though I cannot get past initialisation using this board. I have used the STM32F103RB-Nucleo project as a basis for the discovery board as this was the closest match and have changed the values defined in platform.h to match the connections shown in the M24LR discovery board schematic. I have set the interface pin high too so SPI should be selected on the CR95HF. Is there something else I'm missing?

Otherwise I may just have to convert the library to use UART and try it straight away on my other board. What all is involved in changing the library to use UART instead of SPI?

Thanks again!

Amy

Brian TIDAL
ST Employee

Hi Amy

" M24LR discovery board" ==> do you mean RF Transceiver demonstration board MB1054B?

Have you properly reassigned the IRQ_IN/UART_RX pin to PA3 and and IRQ _OUT/UART_TX pin to PA2? IRQ_IN is needed as part of the startup sequence (see CR95HF datasheet §3.2)

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.
ADoug.1
Associate II

Hi BT,

Yes sorry I mean the RF Transceiver demonstration board MB1054B.

Yes I have reassigned the IRQ_IN/UART_RX and IRQ_OUT/UART_TX pins. Should IRQ_IN/UART_RX pin not be reassigned to PA2 and IRQ_OUT/UART_TX pin to PA3? I have tried the pins either way round anyway and unfortunately neither way works so is there anything else I should try?

Thanks!

Amy

Brian TIDAL
ST Employee

Hi,

I guess you have already checked that the board is functional with the default FW (STSW-M24LR007)? STSW-M24LR007 also includes the source code so that you can check the proper pin assignment or reuse the MCU initialisation part for your tests

Can you check the board is properly powered? Can you blink the LED1 through PB5? Is your JTAG asserting NRESET?

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.
ADoug.1
Associate II

Hello,

Yes I have checked the board is functional with the default FW and checked the pin assignment.

The board must be powered properly as when I run the demo LED1 blinks on and off to show the STM has been unable to initialise the CR95HF chip. I am unsure about JTAG asserting NRESET, I will double check this as well but the board does seem to be programmed ok and I can step through the code using the debugger.

Thanks.

Amy

Brian TIDAL
ST Employee

Hi,

can you step into rfalInitialize() and investigate to find whether the failure comes from st25r95Initialize(), st25r95CheckChipID or st25r95CalibrateTagDetector()?

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.
ADoug.1
Associate II

Yes, it appears to be st25r95Initialize(). When I step through it appears to be a timeout error due to the STM not receiving a response from sending the ECHO command.

The exact line which returns ERR_TIMEOUT is "retCode = st25r95SPIPollRead(ST25R95_CONTROL_POLL_TIMEOUT);" - line 246 in st25r95_com_spi.c.

Thanks.

Amy

ADoug.1
Associate II

Hello Brian,

I am unsure why but when I programmed my STM32 with another program then reprogrammed it again with the demo software it now works!

The initialisation works and I can see tags being detected. Sorry to have wasted your time!

Could you please tell me how I can alter the library so as to use it with UART instead of SPI?

Thanks again for all your help.

Amy