You are here

S25FL127S - ASP Advanced sector protection - password method | Cypress Semiconductor

S25FL127S - ASP Advanced sector protection - password method

Summary: 1 Reply, Latest post by Bacem Daassi on 10 Nov 2016 05:09 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
anteo_c_1698921's picture
User
1 post

I have purchased a S25FL127S 128 Mbit (16 Mbyte) 3.0V SPI Flash Memory (here the Documentation link: http://www.cypress.com/file/177961/download) and wanted to make use of the password method in ASP. Before configuring anything i tested erase and program page and everything works fine.

Before doing anything i read the related registers:
PASS:             all values are 0xFFs
PPB Lock Bit:     0x01        (unprotected PPB bits)
ASP:             0xFF 0xFE    (no security method configured)
PPB Bit for first sector: 0xFF    (unprotected)   command 0xE2 with address 0
DYB Bit for first sector: 0xFF    (unprotected)   command 0xE0 with address 0

What i did is configured a password through 0xE8. When i read it again it shows what i configured. After that i changed the value of ASP reg to choose the software method so ASP reg[2] should be set to 0. So i used command 0x2F and sent 0xFB and 0xFE. Now i read the password again and everything is 0x00 which i expect to be correct since after configuring the password method the documentation states that is not possible to read the password again also if i read the PPB Lock bit the valus is 0x00 which means its protected. So the new values are now:

PASS:             all values are 0xFFs
PPB Lock Bit:     0x00        (protected PPB bits)
ASP:             0xFE 0xFE    (password security method configured)
PPB Bit for first sector: 0xFF    (unprotected)   command 0xE2 with address 0
DYB Bit for first sector: 0xFF    (unprotected)   command 0xE0 with address 0

Status registers is always 0x00.

Since the sector 0 is still unprotected i wanted to erase it but now it does not work anymore. And after starting erase sector i get the value of the status register to 0x23 which means Erase error.

What i also tried is run PASSU to unlock the password (0xE9) after which i get 
PPB Lock Bit:     0x01 (unprotected PPB bits)

and than try to erase again with same result.

My target is after configuring the password to be abel to protect the sectors setting their PBB bit to 0x00 but even that does not work. After issueing unlock password PASSU command i get 
PBB Lock Bit: 0x01 (unprotected PPB bits)

and now if i try to protect sector 0 through changing its PBB bit to 0 (command 0xE3 with the address parameter 0) nothing changes. i read again 

PPB Bit for first sector: 0xFF    (unprotected)

Here are the mothds i am using....what am i doing wrong?? Thanks

 

#define HIGH(x) ((x&0xff0000)>>16)
#define MID(x) ((x&0xff00)>>8)
#define LOW(x) (x&0xff)

void enableWrite(){
    _cs->write(0);
    wait_us(1);
    _spi->write(0x06);
    wait_us(1);
    _cs->write(1);
}

void waitForWrite() {
    while (true) {
        if (0==readStatus()&1)
            break;
        wait_us(10);
    }
}
int readStatus() {
    _cs->write(0);
    wait_us(1);
    _spi->write(0x5);
    int status=_spi->write(0x00);
    wait_us(1);
    _cs->write(1);
    return status;
}

void setPWD(char * pwd) {
    enableWrite();

    _cs->write(0);
    wait_us(1);

    _spi->write(0xE8);

    // do real write
    for (unsigned int i=0;i<8;i++) {
        _spi->write(pwd[i]);
    }
    wait_us(1);
    // disable to start physical write
    _cs->write(1);

    waitForWrite();
}

//on success the PPB Lock Bit is set to one
//The PPB Lock bit can only be set to 1 by the Password Unlock command.
void unlockPWD(char * pwd) {
    enableWrite();

    _cs->write(0);
    wait_us(1);

    _spi->write(0xE9);

    // do real write
    for (unsigned int i=0;i<8;i++) {
        _spi->write(pwd[i]);
    }
    wait_us(1);
    // disable to start physical write
    _cs->write(1);

    waitForWrite();
}

int readDYBSectorBit(unsigned int startAdr) {

    _cs->write(0);
    wait_us(1);
    _spi->write(0xE0);
    _spi->write(HIGH(startAdr));
    _spi->write(MID(startAdr));
    _spi->write(LOW(startAdr));
    int result =_spi->write(0x00);
    wait_us(1);
    _cs->write(1);
    return result;
}
//address should be the 0 address of the sector
int readPPBSectorBit(unsigned int startAdr) {

    _cs->write(0);
    wait_us(1);
    _spi->write(0xE2);
    _spi->write(HIGH(startAdr));
    _spi->write(MID(startAdr));
    _spi->write(LOW(startAdr));
    int result =_spi->write(0x00);
    wait_us(1);
    _cs->write(1);
    return result;
}

//address should be the 0 address of the sector
void protectPPBSector(unsigned int startAdr) {
    enableWrite();

    _cs->write(0);
    wait_us(1);

    _spi->write(0xE3);
    _spi->write(HIGH(startAdr));
    _spi->write(MID(startAdr));
    _spi->write(LOW(startAdr));
    _spi->write(0x0);

    wait_us(1);
    _cs->write(1);

    waitForWrite();
}

int readPPBLockBit() {

    _cs->write(0);
    wait_us(1);
    _spi->write(0xA7);
    int result =_spi->write(0x00);
    wait_us(1);
    _cs->write(1);
    return result;
}

void protectPPBLockBit() {
    enableWrite();

    _cs->write(0);
    wait_us(1);

    _spi->write(0xA6);

    wait_us(1);
    _cs->write(1);

    waitForWrite();
}

void readASPReg(char * response) {

    _cs->write(0);
    wait_us(1);
    _spi->write(0x2B);
    response[0] = _spi->write(0x00);
    response[1] = _spi->write(0x00);
    wait_us(1);
    _cs->write(1);
}

void setASPReg(char * value) {
    enableWrite();

    _cs->write(0);
    wait_us(1);

    _spi->write(0x2F);
    _spi->write(value[0]);
    _spi->write(value[1]);

    wait_us(1);
    _cs->write(1);

    waitForWrite();
}

void clearBlock(unsigned int addr) {

    enableWrite();
    _cs->write(0);
    wait_us(1);
    _spi->write(0xd8);
    _spi->write(HIGH(addr));
    _spi->write(MID(addr));
    _spi->write(LOW(addr));
    wait_us(1);
    _cs->write(1);
    waitForWrite();
}

bacd's picture
Cypress Employee
12 posts

Dear customer,

What is the exact OPN of the part you're using?

From the description you sent, after configuring the password method, you should read:

ASP: 0xFB 0xFE  and not 0xFE 0xFE as you mentioned. The first byte should be 0xFB and not 0xFE.

I see also in the code you included that the following commands are provided with 3 byte addressing while they require 4-byte addressing:

- Command E0h (DYB Read)

- Command E2h (PPB Read)

- Command E3h (PPB Write)

Using these commands in a wrong format might have set PPB protection for some sectors.

Please also change the following line in waitForWrite() from:

        if (0==readStatus()&1)

to:

        if (0==(readStatus()&1))

Please try unlocking the password and sending a PPB Erase command (E4h) which should remove all the PPB protections you might have inadvertently programmed.

Let me know how this will work for you!

Best regards,

Bacem Daassi

Cypress Application Engineering

Log in to post new comments.