diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 3854b589..b3d14f72 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -310,6 +310,8 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) } } + #define MFU_MAX_CRC_RETRIES 5 + unsigned int retries = 0; for (int i = 0; i < blocks; i++){ if ((i*4) + 4 >= CARD_MEMORY_SIZE) { Dbprintf("Data exceeds buffer!!"); @@ -320,15 +322,22 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) if (len) { if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error",i); - // if no blocks read - error out - if (i==0){ - OnError(2); - return; + + if (retries >= MFU_MAX_CRC_RETRIES) { + // if no blocks read - error out + if (i==0) { + OnError(2); + return; + } else { + //stop at last successful read block and return what we got + break; + } } else { - //stop at last successful read block and return what we got - break; + retries++; + i--; } } else { + retries = 0; countblocks++; } }