How to protect specific page from being erased while programming flash on MC9S08QE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to protect specific page from being erased while programming flash on MC9S08QE

1,397 Views
Timor
Contributor I

Hi,

I have an application which stores data on the flash and i need this data to be kept when updating the firmware (programming the microcontroller with new firmware). I am allocating the first page of flash for this purpose in the prm file (page 0xC000-0xC1FF):

    SEGMENTS
        ROM2     =  READ_ONLY    0xC000 TO 0xC1FF;         // keep first page free for Saving data
        ROM       =  READ_ONLY    0xC200 TO 0xFFAD;  

    END

All the firmware code is placed in the ROM section (defined in the PLACMENT section of the prm file) so that actual code lies only from the second page and above (0xC200-0xFFAD). No coed is placed in the ROM2 page but despite that, when i am downloading firmware to the microcontroller it erases also the first page. I believe it keeps performing "mass erase" instead of  multiple "page erase" commands.

I am using MC9S08QE and i am programming it using the USBDMLT pod (www.TechnologicalArt.com) which runs the open source USBDM files. I am programming the microcontroller using Freescale's "True-Time Simulator & Real-Time Debugger" (hiwave) but i also tried the BDM Flash Programmer.

 

I am doing the same thing (keeping one page from being erased during firmware update) on a different device, the MC9S08QG, with freescale's USBSPYDER and it works perfectly just by allocating the pages in the prm file as described above. The USBSPYDER does not support the MC9S08QE devices so i can't use it here.

 

How can i erase only the needed flash pages when updating firmware and the entire flash?

 

Thanks in advance.

Timor

Labels (1)
Tags (1)
0 Kudos
Reply
5 Replies

1,019 Views
kef
Specialist I

Maybe you can use SAVE and SREC commands in preload.cmd to save-restore some addresses, like "eric LGC" suggests here:

 

https://community.freescale.com/message/38517#38517

 

You may need to adapt the script. Hope it will be as simple as removing FLASH ERASE 3 line.

 

Also check the following thread. Using multilink adapter, looks like there IDE controls in debugger to save/restore some parts of flash.

https://community.freescale.com/message/59864#59864

 

0 Kudos
Reply

1,019 Views
Timor
Contributor I

I followed your link and came up with this:

1. In the Preload command file i added the following command to store the data that i need:

        save 0xc000..0xc1ff page0.s19

2. In the Postload command file i added the following commands to restore that data to the flash:

        flash
        flash arm
        srec page0.s19
        flash disarm
        reset

This works fine. Thanks.

It is descibed best in http://www.freescale.com/webapp/sps/utils/SingleFaq.jsp?FAQ-28898.xml

 

The problem with this solution is that it will fail if the process is not completed successfully. If it failed to store the data and you start the process again it will erase the data (you need to save a copy of the page0.s19 file before restarting the programming).

In order to solve it i still prefer keeping this page from erase. I spent some time searching the option of erasing page by page instead of performing mass erase. I know how to prevent the mass erase but didn't find how and where to issue page erase commands. This option is mentioned in the links but it is not described how to actually do it. Do you know if that is possible and how to do that?

 

Thanks,

Timor

 

 

0 Kudos
Reply

1,019 Views
rocco
Senior Contributor II

Hi Timor,

 

If all you need is to have an .S19 file's data restored in the flash when you reprogram your code, I may have a simpler solution.

 

I had the same problem as you seem to have, because my flash contained DSP code as data to be downloaded to the DSP on power-up. Everytime I updated the firmware, the DSP code would be erased.

 

I played arround with the skip-erase and other manual commands for a while, and then stumbled upon a solution (from this forum) that simply required adding one line to the end of the .PRM file:

 

HEXFILE    ..\DSPv3\Core1.s19

Now, after programming the updated code in the flash, the programming software reloads the dsp code into the flash as well. I think that might work for you.

0 Kudos
Reply

1,019 Views
bigmac
Specialist III

Hello Timor,

 

Maybe a modified programming algorithm (.S8P) file would be requred for the device in question.  These are text files, and I assume that the ones within the CW installation are used by your programmer.  It might be worthwhile posing your question directly to the P&E forum.

 

It would seem that the algorithm file is automatically selected when the CW debugger is run.  However, when using the P&E standalone programming software, you get to choose the specific programming file required, allowing multiple alternatives for a single device.  So this may be an avenue worth investigation.

 

P&E have previously very helpful in explaining to me the file modifications necessary to provide a custom trim frequency for the internal reference.  So perhaps the erase range might also requre only a simple modification.

 

Regards,

Mac

 

0 Kudos
Reply

1,019 Views
kef
Specialist I
I would tell you if I knew how to make debugger using sector erase commads instead of  (block/array) mass erase commands. On S12 it is possible to use AEFSKIPERASE debuggers command to not erase EEPROM or specific flash arrays (on derivatives that have more than 1 flash array). But arrays are big, like 64kB. There's no known command to erase or skip erasing specific sectors (512/1024 bytes).
0 Kudos
Reply