This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nfc_t4t_response_pdu_send returns NRF_ERROR_INVALID_STATE

I am trying to use nfc_t4t_lib in NFC_T4T_EMUMODE_PICC mode. After receiving an APDU I am doing some calculations and sending reply with nfc_t4t_response_pdu_send. If calculations take some time, I am getting NRF_ERROR_INVALID_STATE as a result.

I have some questions:

  1. How can I enable some extra debugging or logging to find out a reason for NRF_ERROR_INVALID_STATE error.
  2. Can it be caused by too low FWI value? It seems that maximum value supported by the lib is 4, which corresponds to some ~5ms timeout. When calculation takes longer than 5ms, I am getting NRF_ERROR_INVALID_STATE error.
  3. Does nfc_t4t_lib support sending S(WTX) blocks to extend the timeout?

Here is the code I am talking about:

static void nfc_callback(void          * context,
                         nfc_t4t_event_t event,
                         const uint8_t * data,
                         size_t          dataLength,
                         uint32_t        flags)
{

    switch (event)
    {
        case NFC_T4T_EVENT_FIELD_ON:
            bsp_board_led_on(BSP_BOARD_LED_0);
            break;

        case NFC_T4T_EVENT_FIELD_OFF:
            bsp_board_leds_off();
            break;

        case NFC_T4T_EVENT_DATA_IND:
            if ((flags & NFC_T4T_DI_FLAG_MORE) == 0)
            {
                nrf_delay_us(6 * 1000);           // do some work

                err_code = nfc_t4t_response_pdu_send(resp, resp_len);
                APP_ERROR_CHECK(err_code);        // err_code = 8
            }
            break;

    }

}
    1. NRF_ERROR_INVALID_STATE is returned because the time for responding to the NFC command has expired. Enable debugging by enable HAL_NFC_CONFIG_LOG_ENABLED in sdk_config.h. You might also want to add a log event when S(WTX) is sent, i.e. after the TXFRAMEEND.

    2. Yes, the maximum value is 4. This is limited by the HW timer (on nRF52832 16bits) that count the interframe spacing. We will probably update the library in SDK 15 to utilize the larger timer (20 bits) on nRF52840 (this will be a conditional compilation in the library).

    3. The library sends S(WTX) blocks automatically when the application doesn't respond withing the ~5 ms timeout. So you should wait until you receive a S(WTX) response from the poller to continue communication. Notice that there is a log event that say "RX: S(WTX) response"

Related