Skip to main content
Visitor II
April 25, 2023
Solved

How can I connect STM32G071 board with ST25R3911B chip (X-NUCLEO-NFC05A1)?

  • April 25, 2023
  • 7 replies
  • 9812 views

Hello there, STM32 community!

I am new to the STM32 family and I am currently working on a project to read and write Mifare Classic and Desfire tags. For this, I am using an STM32G071-NUCLEO64 microcontroller and a X-NUCLEO-NFC05A1 (ST25R3911B) board connected via SPI. I have been trying to establish the SPI connection between the two devices and send/receive data, but so far, I have not been successful.

Initially, I tried to use the SPI example provided in STM32CubeIDE, but I was not able to receive data correctly.

Then, I followed a post on the ST community website to use the RFAL/NDEF libraries for my project. However, the post was for the 32f070RB board, and I had to make some modifications to make it work with my hardware.

Unfortunately, after copying the RFAL and NDEF libraries into my project, modifying the platform.h file, and adding the necessary modules, I am still unable to get it working.

The error I am receiving is:

#define ERR_HW_MISMATCH ((ReturnCode)36U) /*!< expected hw do not match */

after executing rfalNfcInitialize().

I am feeling lost and unable to find a suitable example for my specific case.

Can someone please guide me on how to initialize the connection between the STM32G071 and the ST25R3911B chip?

What is the best way to receive data and work with it?

Thank you very much for your time and help!

    This topic has been closed for replies.
    Best answer by Kamil Duljas

    Hahah, It was good journey :D I think that manual of NFC board is customized for few boards with the same pins .e.q F401, L476 etc. .... and You on other board must check and correct eventually differences. For example:


    _legacyfs_online_stmicro_images_0693W00000biwh9QAA.pngMCU_LED3 on dedicated boards is PB0, look on F401:


    _legacyfs_online_stmicro_images_0693W00000biwhEQAQ.pngbut on G0xx you have PB1:


    _legacyfs_online_stmicro_images_0693W00000biwhTQAQ.png 

    I'm happy that works. Mark some answer as best please :)

    7 replies

    Graduate
    April 25, 2023

    Coud you share your code or some links to ST example?

    EElec.2Author
    Visitor II
    April 25, 2023

    Hello, yea!

    My main function in main.c is like this:

    int main(void)
    {
     /* USER CODE BEGIN 1 */
     
     /* USER CODE END 1 */
     
     /* MCU Configuration--------------------------------------------------------*/
     
     /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
     HAL_Init();
     
     /* USER CODE BEGIN Init */
     
     /* USER CODE END Init */
     
     /* Configure the system clock */
     SystemClock_Config();
     
     /* USER CODE BEGIN SysInit */
     
     /* USER CODE END SysInit */
     
     /* Initialize all configured peripherals */
     MX_GPIO_Init();
     MX_SPI1_Init();
     MX_USART1_UART_Init();
     /* USER CODE BEGIN 2 */
     
     spiInit(&hspi1);			// Initialize driver
     logUsartInit(&huart1);	// Initialize log module
     
     platformLog("Welcome to X-NUCLEO-NFC05A1\r\n");
     
     
     /* Initalize RFAL */
     if( !demoIni() )
     {
     /*
     * in case the rfal initalization failed signal it by flashing all LED
     * and stoping all operations
     */
     platformLog("Initialization failed..\r\n");
     while(1)
     {
     platformLedToogle(PLATFORM_LEDG_PORT, PLATFORM_LEDG_PIN);
     platformDelay(100);
     }
     }
     
    	platformLog("Initialization succeeded..\r\n");
    	for (int i = 0; i < 6; i++)
    	{
    		platformLedToogle(PLATFORM_LEDG_PORT, PLATFORM_LEDG_PIN);
    		platformDelay(200);
    	}
     
    	platformLedOff(PLATFORM_LEDG_PORT, PLATFORM_LEDG_PIN);
     
     
     /* USER CODE END 2 */
     
     /* Infinite loop */
     /* USER CODE BEGIN WHILE */
     while (1)
     {
    	/* Run Demo Application */
    	demoCycle();
     
     /* USER CODE END WHILE */
     
     /* USER CODE BEGIN 3 */
     }
     /* USER CODE END 3 */
    }

    and the rest of project it's almost an exact copy of the the one you can donwload here: https://www.st.com/en/embedded-software/x-cube-nfc5.html#get-software

    And in the first question, I add a link in the words "post on the ST community website" but in case it is not working, the link to the post I followed is: https://community.st.com/s/question/0D53W000006G1H9SAK/how-to-start-with-st25r3911b-and-is-it-really-necessary-to-use-rfal-and-st25r3911-libraries-for-simpel-project

    Thanks!

    Graduate
    April 25, 2023

    Probably some wrong in your modified code (platform.h). coud you share file? What files did you change ?

    EElec.2Author
    Visitor II
    April 25, 2023

    Of course.

    This is my platform.h. And the only files that I changed are the platform.h and the main.c.

    You will see that there are "UNKOWN_PIN and UNKOWN_PORT" that's because I don't need those PORT-PINS and I assigned a random one...

    Graduate
    April 25, 2023

    OK, so show also main.c :)

    Graduate
    April 25, 2023

    Yours PB4 that repleace IRQ_3911_Pin is wrong:

    /*Configure GPIO pin : PB4 */

    GPIO_InitStruct.Pin = GPIO_PIN_4;

    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

    GPIO_InitStruct.Pull = GPIO_PULLDOWN;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

     /*Configure GPIO pin : IRQ_3911_Pin */

     GPIO_InitStruct.Pin = IRQ_3911_Pin;

     GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;

     GPIO_InitStruct.Pull = GPIO_NOPULL;

     HAL_GPIO_Init(IRQ_3911_GPIO_Port, &GPIO_InitStruct);

    My advice. Undo all changes. Start from beginning and change only main.h:

    ```

    /* Private define ------------------------------------------------------------*/

    #define B1_Pin GPIO_PIN_13

    #define B1_GPIO_Port GPIOC

    #define IRQ_3911_Pin GPIO_PIN_0

    #define IRQ_3911_GPIO_Port GPIOA

    #define IRQ_3911_EXTI_IRQn EXTI0_IRQn

    #define LED_F_Pin GPIO_PIN_1

    #define LED_F_GPIO_Port GPIOA

    #define LED_B_Pin GPIO_PIN_4

    #define LED_B_GPIO_Port GPIOA

    #define LED_A_Pin GPIO_PIN_0

    #define LED_A_GPIO_Port GPIOB

    #define LED_FIELD_Pin GPIO_PIN_8

    #define LED_FIELD_GPIO_Port GPIOA

    #define TMS_Pin GPIO_PIN_13

    #define TMS_GPIO_Port GPIOA

    #define TCK_Pin GPIO_PIN_14

    #define TCK_GPIO_Port GPIOA

    #define SWO_Pin GPIO_PIN_3

    #define SWO_GPIO_Port GPIOB

    #define LED_V_Pin GPIO_PIN_4

    #define LED_V_GPIO_Port GPIOB

    #define LED_AP2P_Pin GPIO_PIN_5

    #define LED_AP2P_GPIO_Port GPIOB

    #define SPI1_CS_Pin GPIO_PIN_6

    #define SPI1_CS_GPIO_Port GPIOB

    EElec.2Author
    Visitor II
    April 25, 2023

    So, you're telling me to start a new project from start and don't add the RFAL/NDEF libraries nor the other modules?

    Just a connection with SPI functions like HAL_SPI_TransmitReceive_DMA, HAL_SPI_TransmitReceive_IT, HAL_SPI_TransmitReceive...?

    Graduate
    April 25, 2023

    No, I mean about revert changes in platform.h and main.c , At first changing main.h and them trying customize main.c

    EElec.2Author
    Visitor II
    April 27, 2023

    IT WORKS!!!!!! THANK YOU VERY MUCH :loudly_crying_face:

    Why did I have to use the port-pins from the NFC05A1 and now I had to use the port-pins for the STM32G071 board?????

    Graduate
    April 27, 2023

    Hahah, It was good journey :D I think that manual of NFC board is customized for few boards with the same pins .e.q F401, L476 etc. .... and You on other board must check and correct eventually differences. For example:


    _legacyfs_online_stmicro_images_0693W00000biwh9QAA.pngMCU_LED3 on dedicated boards is PB0, look on F401:


    _legacyfs_online_stmicro_images_0693W00000biwhEQAQ.pngbut on G0xx you have PB1:


    _legacyfs_online_stmicro_images_0693W00000biwhTQAQ.png 

    I'm happy that works. Mark some answer as best please :)

    EElec.2Author
    Visitor II
    April 27, 2023

    Thank you for everything,

    I hope I can keep up now with the project.

    Have a nice day :)