MFRC522 RFID Library Stopped Working

Hi all,

I’ve used the MFRC522 library from Workbench for a year or two without issue. I tried to compile an old (working) project, and I’m suddenly getting compile issues.

lib/MFRC522/src/MFRC522.cpp: In member function 'bool MFRC522::MIFARE_UnbrickUidSector(bool)':
lib/MFRC522/src/MFRC522.cpp:1631:1: error: control reaches end of non-void function [-Werror=return-type]
 1631 | }
      | ^

I know this project has been unchanged since it last worked, and I also tried compiling one of the code examples, which also failed. Has anyone run into this? Is this something with a firmware change, or am I just missing something obvious?

Thanks,
Rob

DeviceOS 3.1.0
Argon
Win10 + Workbench

In Device OS 3.1, the compiler is set to enforce that all non-void functions (in this case, bool) return a value. This is necessary because in 3.0 and later, it’s quite likely that the code will SOS+1 hard fault if you don’t return a value. Since you’re using Workbench you could just add the missing return value to the library. Or you can roll back to 2.x versions where the compiler generates code that won’t fault for missing return values.

1 Like

Ah thanks @rickkas7 ! That is very helpful.

I hope this isn’t getting into the weeds of this library too much, but I thought I tried that and it still didn’t work.
This is the method is question

bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
    MIFARE_OpenUidBackdoor( logErrors );
    
    byte block0_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    // Write modified block 0 back to card
    byte status = MIFARE_Write((byte)0, block0_buffer, (byte)16);
    if (status != STATUS_OK) {
        if ( logErrors ) {
            Serial.print("MIFARE_Write() failed: ");
            Serial.println(GetStatusCodeName(status));
        }
        return false;
    }
}

I updated the last couple lines as follows, but it still crashes with the same message

bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
    MIFARE_OpenUidBackdoor( logErrors );
    
    byte block0_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    // Write modified block 0 back to card
    byte status = MIFARE_Write((byte)0, block0_buffer, (byte)16);
    if (status != STATUS_OK) {
        if ( logErrors ) {
            Serial.print("MIFARE_Write() failed: ");
            Serial.println(GetStatusCodeName(status));
        }
        return false;
    } else {
		return true;
	}
}

Any suggestions?

If you’re cloud compiling, be sure to remove the MFRC522 entry from the project.properties file. If that is present, the cloud compiler will use the official version instead of your modified version.

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.