8 Replies Latest reply on Apr 26, 2019 6:31 AM by vivc_4156156

    erasing and programming page of secured regions in S25FL256L flash memory using SPI

    vivc_4156156

      Hi ,

          I'm developing code for accessing the flash for read and write using SPI .I'm using mpc5777c nxp chip to interface

          with SPI nor flash. I need to program some data on the secured region

         need to use secure region erase and secure region program. No need of password protection.

      My doubt can this be done as normal sector erase 21h where we erase sectors of 4k bytes one by one from start address till the required address.

      barring one change here only 1024 bytes can be erased and done as boundaries of 256 bytes(4 regions)

      Same for programming also .similar to page programming but max 1024 bytes (as boundaries of 256 bytes).

      Is my understanding correct?

      Any examples for the same

      Thanks in Advance

      Vignesh.V

        • 1. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
          SudheeshK_26

          Hi Vignesh,

           

          You have to use SECRE (44h, Security region erase) command to erase security region. Please read section "9.7 Security Regions Array Commands" in datasheet for details about the commands related to security region. Datasheet: https://www.cypress.com/file/192131/download, page 115.

           

          Thanks and Regards,

          Sudheesh

          • 2. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
            vivc_4156156

            Hi sudeesh,

                              Thanks. I saw the datasheet ..I m posting the code may be not full code a pseudo stuff with comments could u just guide me whether this is right..

            uint8_t status, dummy_var;
            uint8_t addr0, addr1;
            addr0 = (uint8_t) (address & 0x000000FF);
            addr1 = (uint8_t) ((address & 0x0000FF00) >> 8);

             

              PUSH_ENQ(WREN);   // write enable command
            WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
            POP(dummy_var);

             

            PUSH(SE); // Sector erase command - 44h
            WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
            POP(dummy_var); // discard one RxFIFO item

             

            PUSH(addr1); // most-significant byte of address
            WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
            POP(dummy_var);

             

            PUSH_ENQ(addr0); // least-significant byte of address
            WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
            POP(dummy_var);

            do
            {
              status = spi_flash_read_status_register();
            }
            while (status & WIP); // wait here until sector erase is done

            • 3. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
              SudheeshK_26

              Hi Vignesh,

               

              Like normal erase command SECRE (44h) also expects 3 bytes of address after command. It is mentioned in the datasheet as below.

              "The Security Region Erase command erases data in the Security Region, which is in a different address space from the main array data. The Security Region is 1024 bytes so, the address bits (A24 to A10) must be zero for this command."

               

              Address of security regions

              • Security Region 0: A23-16 = 00h; A15-8 = 00h; A7-0 = byte address
              • Security Region 1: A23-16 = 00h; A15-8 = 01h; A7-0 = byte address
              • Security Region 2: A23-16 = 00h; A15-8 = 02h; A7-0 = byte address
              • Security Region 3: A23-16 = 00h; A15-8 = 03h; A7-0 = byte address

               

              If you want to erase security region 1, then the command sequence will be as below.

              1. CS# LOW
              2. Send WREN command
              3. CS# HIGH
              4. CS# LOW
              5. Send SECRE command
              6. Send Addr2 (0x00)
              7. Send Addr1 (0x01)
              8. Send Addr0 (0x00)
              9. CS# HIGH
              10. Poll SR to check completion status of erase command.

               

              Please feel free to ask if you need any clarifications.

               

              Thanks and Regards,

              Sudheesh

              • 4. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
                vivc_4156156

                Thanks got the idea.

                Few More Clarifications .

                1.The status register to read the can be RDSR (SR1V) for both main flash and secured region flash right.

                2.The secured region program 42h can be used like normal page program command as 256 byte regions except for the fact in secure region program maximum of 1024 bytes can be programmed which means 4 regions - is my understanding right.

                 

                And finally regarding reading 9f ID for flash pl tell me whether this approach is correct.

                 

                uint8_t dummy_var;
                uint8_t manufacturer_ID, device_ID_high,device_ID_low;
                uint32_t device_ID;
                (void)(dummy_var);

                #define dummy_byte 0

                 

                ALLOW_TRANSFER; // if previous command has set EOQ

                PUSH(RDID);  // read ID - 9F
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(dummy_var); // discard one RxFIFO item

                 

                PUSH(0x00); // most-significant byte of address
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(dummy_var); // discard one RxFIFO item

                 

                PUSH(0x01); // middle byte of address
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(dummy_var); // discard one RxFIFO item

                 

                PUSH(0x02); // least-significant byte of address
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(dummy_var); // discard one RxFIFO item

                 

                PUSH(dummy_byte); // dummy byte for generating CLK to slave
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(manufacturer_ID); // read useful data

                 

                PUSH(dummy_byte); // dummy byte for generating CLK to slave
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                POP(device_ID_high); // read useful data

                 

                PUSH_ENQ(dummy_byte); // dummy byte for generating CLK to slave
                WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;


                POP(device_ID_low); // read useful data

                device_ID = (device_ID_low << 24) | (device_ID_high << 16) | (manufacturer_ID << 8) | dummy_byte;

                return device_ID;

                 

                Thanks,

                Vignesh.V

                • 5. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
                  SudheeshK_26

                  Hi Vignesh,

                   

                  Please find the answer for your queries below.

                   

                  1. Yes. SR1 can be used to check completion status of both secure region program and normal program operation.

                  2. Yes, you are correct. Please see section "9.7.2 Security Region Program (SECRP 42h)" on page 116 of the datasheet for more information.

                  3. RDID command does not need address bytes. Our device will output device ID after the command. Please see section "9.2.1 Read Identification (RDID 9Fh)" on page 81 of the datasheet.

                   

                  Datasheet: https://www.cypress.com/file/192131/download

                   

                  Thanks and Regards,

                  Sudheesh

                  • 6. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
                    vivc_4156156

                    Hi,

                    Thanks for the comments . one query if address bytes are not required is this appraoch right?

                    uint8_t dummy_var;
                    uint8_t manufacturer_ID, device_ID_high,device_ID_low;
                    uint32_t device_ID;
                    (void)(dummy_var);

                    #define dummy_byte 0

                     

                    ALLOW_TRANSFER; // if previous command has set EOQ

                    PUSH(RDID);  // read ID - 9F
                    WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                    POP(dummy_var); // discard one RxFIFO item

                     

                     

                    PUSH(dummy_byte); // dummy byte for generating CLK to slave
                    WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                    POP(manufacturer_ID); // read useful data

                     

                    PUSH(dummy_byte); // dummy byte for generating CLK to slave
                    WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;
                    POP(device_ID_high); // read useful data

                     

                    PUSH_ENQ(dummy_byte); // dummy byte for generating CLK to slave
                    WAIT_UNTIL_RxFIFO_IS_NOT_EMPTY;


                    POP(device_ID_low); // read useful data

                    device_ID = (device_ID_low << 24) | (device_ID_high << 16) | (manufacturer_ID << 8) | dummy_byte;

                    return device_ID;

                     

                    Thanks in Advance,

                    Vignesh.V

                    • 7. Re: erasing and programming page of secured regions in S25FL256L flash memory using SPI
                      SudheeshK_26

                      Hi Vignesh,

                       

                      Yes, the command sequence to read ID looks good in your latest response.

                       

                      Thanks and Regards,

                      Sudheesh