Arm Mbed OS support forum

NFC M24SR to read UID from STM32L475

I am currently trying to access the unique identifier found in the system file layout on the M24SR64 of the STM32L475 Discovery Kit.

I use the M24SR library and according to the doc, the UID is accessible at offset 8.
Below is a portion of main.cpp

#define NFC_I2C_SDA_PIN        PB_11              
#define NFC_I2C_SCL_PIN        PB_10         
#define NFC_GPO_PIN            PE_4                                           
#define NFC_RF_DISABLE_PIN     PE_2                    
#define M24SR_ADDR             0xAC

nfcTag.init(NULL); // no call back needed, default behavior is sync
uint8_t uid[7];
uint16_t ret;
ret = nfcTag.read_binary(0x0008, 0x07, uid);
printf("%04x init %02x %02x %02x %02x %02x %02x %02x\n\r", ret, uid[6], uid[5], uid[4], uid[3], uid[2], uid[1], uid[0]);

Unfortunately, the code above yields error 0x0011 which indicates M24SR_IO_ERROR_I2CTIMEOUT.

Any ideas how I can address this? Did I miss an obvious step with i2c and timeout?



I do not have this hardware, but did you verified the connection with ST example - HelloWorld_Async_M24SR - M24SR NFC example. Simple application to asynchro… | Mbed ?

BR, Jan

Thank you Jan! I saw this but it’s mbed 2 and I am on 6. I should check the code to see if there’s something I can pick up from there.

Sorry - this has little to do with the mbed version :slight_smile: in fact the M24S driver seems to be incorporated in recent versions…
I still could not find a way to use the example for my project. I am struggling with the use of the API I guess. Could it be with lack of async function? I keep searching.
Studying this Arduino example at the moment.

I added a call to get_session but the result is FILE_NOT_FOUND (0x6a82)

nfcTag.read_binary(0x0008, 7, uid);

Currently looking into verify() call - but no luck yet

Ye, it is for Mbed2 but for verification of function it is OK. You can also try to remove Mbed2 and import newest version of MbedOS. I think with MbedOs 5.15.7 it can be OK. With MbedOs6+ probably not and some work can be necesarry.

Maybe we can try to ask…
Hello @apalmieri (I do not know if you are the right one), is it possible to update the example of X-NUCLEO-NFC01A1 Dynamic NFC Tag | Mbed for MbedOS6, please? Thank you

BR, Jan

target M24SR is part of mbed-os nfc connectivity and fully supported. Please, refer to the mbed-os-example-nfc on github.

Kind Regards

1 Like

Thank you both! I had seen this but still could not figure out how to read the UID from the system file. I am still on the error above file not found and wondering if I have to call verify…

@apalmieri I am still not able to work out an approach to read the UID. I am booting my Discovery board and would like to read the UID via I2C which can be done in blocking mode.
Any pointers & hints would be great.
I am still using M24SR - STMicroelectronics' M24SR NFC Dynamic Tag Library. | Mbed and the functional description from M24SR64-Y
Not sure if @paulszczepanek is around - wouldn’t mind switching to the modern approach outlined in Andrea’s reference example but I just cannot wrap my head around using it to read the UID…
Thank you for the time& support!!

Any hint would help! If something is unclear, please let me know…

Hello Jean-Paul,

Unfortunately, I don’t have a DISCO_L475VG_IOT01A board neither any experience with NFC yet. So take this as my tip based on digging a bit into the Mbed’s mbed-os-example-nfc recommended above by Andrea Palmieri.

In the NFC_EEPROM example try to modify the main.cpp as follows:

class EEPROMExample : mbed::nfc::NFCEEPROM::Delegate
    // define a structure for nfc_info
    struct parsed_value_t {
       Span<nfc_info_t> nfc_info;


    // modify the parse_ndef_message function
    virtual void parse_ndef_message(const Span<nfc_info_t> &buffer) {
        printf("Received an ndef message of size %d\r\n", buffer.size());

        if (buffer.size() <= sizeof(nfc_info_t)) {

        parsed_value_t  parsed_value;

        parsed_value.nfc_info = buffer.first(sizeof(nfc_info_t));

        nfc_info_t* nfc_info =;

        if (nfc_info->type.nfc_nfc_dep_a) {
            for (uint8_t i = 0; i < nfc_info->nfcA.uidLength; i++) {
                printf("uid[%d] = %d\r\n", i, nfc_info->nfcA.uid[i]);

Good luck,


Thank you! Will give this a try later and let you know!