mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-25 18:34:30 +00:00
Use a more thorough NFC peripheral reset strategy.
This commit is contained in:
@@ -523,6 +523,43 @@ void nfc_tag_14a_data_process(uint8_t *p_data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy from nrf_nfct.c and modified for nrf52840 adapted(no verify on nrf52832)
|
||||
static inline void nrf_nfct_reset(void) {
|
||||
uint32_t fdm;
|
||||
uint32_t int_enabled;
|
||||
|
||||
// Save parameter settings before the reset of the NFCT peripheral.
|
||||
fdm = nrf_nfct_frame_delay_max_get();
|
||||
int_enabled = nrf_nfct_int_enable_get();
|
||||
|
||||
// Reset the NFCT peripheral.
|
||||
*(volatile uint32_t *)0x40005FFC = 0;
|
||||
*(volatile uint32_t *)0x40005FFC;
|
||||
*(volatile uint32_t *)0x40005FFC = 1;
|
||||
|
||||
// Restore parameter settings after the reset of the NFCT peripheral.
|
||||
nrf_nfct_frame_delay_max_set(fdm);
|
||||
|
||||
// Use Window Grid frame delay mode.
|
||||
nrf_nfct_frame_delay_mode_set(NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID);
|
||||
|
||||
/* Begin: Workaround for anomaly 25 */
|
||||
/* Workaround for wrong SENSRES values require using SDD00001, but here SDD00100 is used
|
||||
because it is required to operate with Windows Phone */
|
||||
nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_SENSRES_BIT_FRAME_SDD_00100);
|
||||
/* End: Workaround for anomaly 25 */
|
||||
|
||||
// Restore interrupts.
|
||||
nrf_nfct_int_enable(int_enabled);
|
||||
|
||||
// Disable interrupts associated with data exchange.
|
||||
nrf_nfct_int_disable(NRF_NFCT_INT_RXFRAMESTART_MASK |
|
||||
NRF_NFCT_INT_RXFRAMEEND_MASK |
|
||||
NRF_NFCT_INT_RXERROR_MASK |
|
||||
NRF_NFCT_INT_TXFRAMESTART_MASK |
|
||||
NRF_NFCT_INT_TXFRAMEEND_MASK);
|
||||
}
|
||||
|
||||
static inline void nfc_fdt_reset(void) {
|
||||
// STOP TX
|
||||
*(volatile uint32_t *)0x40005010 = 0x01;
|
||||
@@ -574,8 +611,7 @@ void nfc_tag_14a_event_callback(nrfx_nfct_evt_t const *p_event) {
|
||||
// Fix a bug where certain special conditions prevent triggering TX start events and actually transmit incorrect data to the card reader.
|
||||
// After more more more testing, I found that simply going into sleep mode and restarting can restore work.
|
||||
// Therefore, I suspect that there may be some issues with the NFC peripheral that require a reset to resolve.
|
||||
nrf_nfct_task_trigger(NRF_NFCT_TASK_DISABLE);
|
||||
nrf_nfct_task_trigger(NRF_NFCT_TASK_ACTIVATE);
|
||||
nrf_nfct_reset();
|
||||
|
||||
NRF_LOG_INFO("HF FIELD LOST");
|
||||
break;
|
||||
|
||||
@@ -818,29 +818,9 @@ void nrfx_nfct_irq_handler(void)
|
||||
|
||||
NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
|
||||
|
||||
/* Clear TXFRAMESTART EVENT so it can be checked in hal_nfc_send */
|
||||
nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMESTART);
|
||||
|
||||
NRFX_LOG_DEBUG("Rx fend");
|
||||
}
|
||||
|
||||
if (NRFX_NFCT_EVT_ACTIVE(TXFRAMEEND))
|
||||
{
|
||||
nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND);
|
||||
|
||||
nrfx_nfct_evt_t nfct_evt =
|
||||
{
|
||||
.evt_id = NRFX_NFCT_EVT_TX_FRAMEEND
|
||||
};
|
||||
|
||||
/* Disable TX END event to ignore frame transmission other than READ response */
|
||||
nrf_nfct_int_disable(NRFX_NFCT_TX_INT_MASK);
|
||||
|
||||
NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
|
||||
|
||||
NRFX_LOG_DEBUG("Tx fend");
|
||||
}
|
||||
|
||||
if (NRFX_NFCT_EVT_ACTIVE(SELECTED))
|
||||
{
|
||||
nrf_nfct_event_clear(NRF_NFCT_EVENT_SELECTED);
|
||||
@@ -913,6 +893,23 @@ void nrfx_nfct_irq_handler(void)
|
||||
m_nfct_cb.config.cb(&nfct_evt);
|
||||
}
|
||||
}
|
||||
|
||||
if (NRFX_NFCT_EVT_ACTIVE(TXFRAMEEND))
|
||||
{
|
||||
nrf_nfct_event_clear(NRF_NFCT_EVENT_TXFRAMEEND);
|
||||
|
||||
nrfx_nfct_evt_t nfct_evt =
|
||||
{
|
||||
.evt_id = NRFX_NFCT_EVT_TX_FRAMEEND
|
||||
};
|
||||
|
||||
/* Disable TX END event to ignore frame transmission other than READ response */
|
||||
nrf_nfct_int_disable(NRFX_NFCT_TX_INT_MASK);
|
||||
|
||||
NRFX_NFCT_CB_HANDLE(m_nfct_cb.config.cb, nfct_evt);
|
||||
|
||||
NRFX_LOG_DEBUG("Tx fend");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NRFX_CHECK(NRFX_NFCT_ENABLED)
|
||||
|
||||
Reference in New Issue
Block a user