Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

calling nfc_t2t_setup is failing if the NFC has already been initialized

Hello,

I'm using the nfr52840 with SD140 and the SDK 17.0.2

I'm facing an issue where calling nfc_t2t_setup is failing when it called a second time.

I'm wonder the following should work but it doesn't:

nfc_init();
nfc_register_tag("foo");
nfc_deinit();

// renable nfc will fail here
nfc_init();

With the following definitions:

uint32_t nfc_init() {
    /*.....*/
    ret_code_t ret = nfc_t2t_setup(nfc_callback, NULL);
    /*.....*/
    return ret;
}

uint32_t nfc_deinit() {

    ret_code_t ret = nfc_t2t_emulation_stop();
    if (ret != NRF_SUCCESS) {
        LOG_ERR("nfc t2t emulation cannot be stopped properly '%s'", nrf_strerror_get(ret));
        return nrf_to_s7l_err(ret);
    }

    ret = nfc_t2t_done();
    if (ret != NRF_SUCCESS) {
        LOG_ERR("nfc_t2t_done has failed! '%s'", nrf_strerror_get(ret));
    }

    return ret;
}

uint32_t nfc_register_tag(const char *tag) {

    /*encoding message is skipped here...*/

    return nfc_t2t_emulation_start();
}

After digging the issue I've found the nfc_t2t_setup return NRFX_ERROR_INVALID_STATE and the error code is coming from the following call stack:

As we can see, m_nfct_cb.state has not been cleared and nrfx_nfct_init just fail...

I can quick fix this by calling nrfx_nfct_uninit() right after nfc_t2t_done().

I think it should be handled properly in the nfc_t2t_lib instead. Or maybe I've missed something.

Let me know.

Best,

Joël

Related