Erase, Write operations on a specific block of flash in MC9S12XEP100 is throwing error

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

Erase, Write operations on a specific block of flash in MC9S12XEP100 is throwing error

2,142 Views
PrashantKulkar1
Contributor I
Hi all,
 
I am working on MC9S12XEP100 microcontroller. This has 1MB of Flash memory. It starts from address 0x70_0000 and ends at 0x7F_FFFF. This flash memory is divided into 5 blocks. Block 0 (0x7C_0000 - 0x7F_FFFF), Block 1N (0x7A_0000 - 0x7B_FFFF), Block 1S (0x78_0000 - 0x79_FFFF), Block 2 (0x74_0000 - 0x77_FFFF), Block 3 (0x70_0000 - 0x73_FFFF).
 
I am able to read, write, erase any portion of data on flash in only 4 blocks. When I try to erase or write any location of flash from Block 3 (0x7C_0000 - 0x7F_FFFF), the code gets jumped to some other location. The code gets executed correctly if I execute it in single step. But if I run through the code(Command Write Sequence), the control gets jumped to some other location.
 
Kindly suggest me any idea to overcome this problem.
 
Regards,
Prashant Kulkarni
Labels (1)
0 Kudos
Reply
3 Replies

725 Views
Lundin
Senior Contributor IV
The behavior you describe occurs when you are trying to program the same flash bank as the routines are running from. It isn't possible to do so on S12 devices.

A bank is a chunk of 64k, as decribed in the flash manual (I think that the size may vary on different S12 devices). Every bank contains a number of pages that you access through the page register. If you try to program the same flash bank as your code is executed from, the program will crash just as you describe, though the programming will indeed work if you single-step in a debugger, though only then.

To solve this, you need to run the code from another flash bank or from RAM.

Almost everyone writing their own flash programming routines seem to run into this problem. Probably because the manual only mentiones that you can't program the same bank in one place: hidden in the middle of the text of some introduction chapter in the flash manual.

Message Edited by Lundin on 2007-09-19 01:28 PM
0 Kudos
Reply

725 Views
PrashantKulkar1
Contributor I
If I load the code onto other flash block, the operations like erase, write can be performed on the remaining blocks of flash. But with interrupts ON, The code always hangs up when I try to write or erase from flash block 0x7C_0000 - 0x7F_FFFF. What is the reason for this.
0 Kudos
Reply

725 Views
mke_et
Contributor IV
If interrupts are on, what's going to happen if an interrupt occurs and the code for the vector table is not there? Any and ALL interrupts!

Choose how you place your routines wisely. You could place a copy of your routines in TWO banks, and depending on where you want to erase/program, you execute from the safe one. The other alternative is to write your routines so they copy to RAM and then execute from there. Just make sure that the FLASH page you called from is back and in place before you return from your routines.
0 Kudos
Reply