1
\$\begingroup\$

Here you can see functions I'm using to store data into Flash, but I'm getting data erased after power reset, so it's still in RAM not in Flash.

#define   OFFSET_ADDRESS                     0x00030000                                                                                        
#define   OFFSET_VERSION                     0x00030002
#define   OFFSET_SERIAL                      0x00030004  

    void read_from_flash (void)   {                     

        BYTE i, *pok_add, *pok_ver, *pok_serial_no;

        pok_add = (BYTE *)OFFSET_ADDRESS;
        display_address = *pok_add;
        delay_1_ms();
        if ((display_address > MAX_OUTDOOR_DISPLAY_ADDRESS) || (display_address < MIN_OUTDOOR_DISPLAY_ADDRESS))  display_address = UNI_ADDRESS;


        pok_ver = (BYTE *)OFFSET_VERSION;
        version = *pok_ver;
        delay_1_ms();
        if (version > MAX_FW_VERSION)        version = 0;                        

        for (i=0;i<8;i++)     {
            pok_serial_no = (BYTE *)OFFSET_ADDRESS;
            serial_no[i] = *pok_serial_no++;
            delay_1_ms();
        }
        for (i=0;i<8;i++)         if (serial_no[i] > 9)   serial_no[i] = 0;       

    }


    void write_to_flash (void)    {                     
    BYTE i;

        iap_copy_to_flash(&display_address, OFFSET_ADDRESS, 1);
        delay_1_ms();

        iap_copy_to_flash(&version, OFFSET_VERSION, 1);
        delay_1_ms();

        for (i=0;i<8;i++)     {
            iap_copy_to_flash(&serial_no[i], OFFSET_VERSION+i, 1);
            delay_1_ms();
            }

        }

Question is where I'm wrong? Sectors in a LPC178x/177x device http://www.nxp.com/documents/user_manual/UM10470.pdf on page 883. Maybe I don't write and read data properly so it's still located in RAM.

\$\endgroup\$
1
\$\begingroup\$

Have you seen the IAP flow mentioned in section 37.8 of the data sheet? Make sure you follow all the steps mentioned there. Also your flash can be written to only if the address does not contain any data currently. If it was previously written you need to erase the entire sector and then program it again.Read this application note for an example on IAP for LPC17xx series. You may have a certail level of write protection/security enabled by default.

\$\endgroup\$
  • \$\begingroup\$ So before every write I need to erase sector? Or I can just continue to fill it with new data? \$\endgroup\$ – Lazar May 6 '15 at 8:49
  • \$\begingroup\$ Solution is to divide all my variables I'm writing to flash into different sectors? \$\endgroup\$ – Lazar May 6 '15 at 8:52
  • 1
    \$\begingroup\$ I would recommend you store all your variables in a single sector itself but if you are going to edit any one of them you will have to erase the entire sector. Also look into the concepts of wear leveling to understand how many sectors you may need to use. Flash memory has a limited number of writes and if you are going to change your data very often then you could cross the maximum write cycles very soon. Usually it will be around 1 Million write-erase cycles for flash so be cautious. \$\endgroup\$ – caveman May 6 '15 at 9:37
  • \$\begingroup\$ I'm using flash write and read to store parameters I got from console which sends me: display_address, version and serial_no, so It needs to be stored only once when configuring devices on RS485 bus, later that parameters are just read everytime console sends device identification command packet. \$\endgroup\$ – Lazar May 6 '15 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.