Skip to main content
Visitor II
September 19, 2016
Solved

RF Mode Sector Security Status

  • September 19, 2016
  • 2 replies
  • 819 views
Posted on September 20, 2016 at 00:41

I am trying to change the sector security status of my RF sectors in I2C mode using the provided m24lr drivers, but it’s not working. Below is my code:

M24LR_SECTOR_SEC sss_write;
M24LR_SECTOR_SEC sss_read;
// unlock sector
sss_write.SectorLock = 0;
// use first password
sss_write.PassCtrl = 1;
// cannot write without password
sss_write.RW_Protection = 0;
NFCTAG_StatusTypeDef status = NDEF_OK;
uint32_t password = 0;
// present password
status = BSP_NFCTAG_GetExtended_Drv()->PresentI2CPassword(password);
wait_ms(1000);
for (int i = 0; i < 
4
; i++)
{
status
= 
BSP_NFCTAG_GetExtended_Drv
()->WriteSSSx((uint8_t)i, &sss_write);
BSP_NFCTAG_GetExtended_Drv()->ReadSSSx((uint8_t) i, &sss_read);
}

I first present the I2C password, which should be 0 because I haven’t changed it since receiving it. Afterward, I use the m24lr functions to write/read each sector’s SSS. However, even though the code runs and the status is always NDEF_OK, the sector security statuses never change. How can I fix this? I am using the Nucleo-NFC02A1 tag, which uses M24LR04E-R.

    This topic has been closed for replies.
    Best answer by Rene Lenerve
    Posted on September 20, 2016 at 14:12

    Hello on.brian,

    There is a bug in the

    PresentI2CPassword

    function (located in Drivers/BSP/Components/M24LR/m24lr.c)

    NFCTAG_StatusTypeDef M24LR_i2c_PresentI2CPassword( const uint32_t PassWord )

    {

    uint8_t ai2c_message[9] = {0};

    uint8_t i;

    /* Build I2C Message with Password + Validation code 0x09 + Password */

    ai2c_message[4] = 0x09;

    i = 0;

    while( i <

    4

    )

    {

    ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;

    ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;

    i++;

    };

    /* Present password to M24LR */

    return M24LR_i2c_WriteRegister( ai2c_message, M24LR_I2C_PWD_REG, 9 );

    }

    th

    e M24LR_i2c_WriteRegister function is used to write data to a register. To fix your problem you just have to replace the last line of this function with:   return M24lr_IO_MemWrite( ai2c_message, M24LR_ADDR_SYST_I2C, M24LR_I2C_PWD_REG, 9 );

     and the present password function should work.

    We will fix it in a next release.

    Second point, you need to initialize the driver pointer by using the init function before using any M24LR functions: (for example)

    /* Init M24LR driver */

    while( BSP_NFCTAG_Init( ) != NFCTAG_OK );

    I hope this will help you,

    kind regards.

    2 replies

    ST Employee
    September 20, 2016
    Posted on September 20, 2016 at 14:12

    Hello on.brian,

    There is a bug in the

    PresentI2CPassword

    function (located in Drivers/BSP/Components/M24LR/m24lr.c)

    NFCTAG_StatusTypeDef M24LR_i2c_PresentI2CPassword( const uint32_t PassWord )

    {

    uint8_t ai2c_message[9] = {0};

    uint8_t i;

    /* Build I2C Message with Password + Validation code 0x09 + Password */

    ai2c_message[4] = 0x09;

    i = 0;

    while( i <

    4

    )

    {

    ai2c_message[i] = ( PassWord >> (i * 8) ) & 0xFF;

    ai2c_message[i + 5] = ( PassWord >> (i * 8) ) & 0xFF;

    i++;

    };

    /* Present password to M24LR */

    return M24LR_i2c_WriteRegister( ai2c_message, M24LR_I2C_PWD_REG, 9 );

    }

    th

    e M24LR_i2c_WriteRegister function is used to write data to a register. To fix your problem you just have to replace the last line of this function with:   return M24lr_IO_MemWrite( ai2c_message, M24LR_ADDR_SYST_I2C, M24LR_I2C_PWD_REG, 9 );

     and the present password function should work.

    We will fix it in a next release.

    Second point, you need to initialize the driver pointer by using the init function before using any M24LR functions: (for example)

    /* Init M24LR driver */

    while( BSP_NFCTAG_Init( ) != NFCTAG_OK );

    I hope this will help you,

    kind regards.

    bonAuthor
    Visitor II
    September 20, 2016
    Posted on September 20, 2016 at 19:26

    That fixed it! Thank you.