Kirk Humphries

Flash Erase Problem for MC9S12C32

Discussion created by Kirk Humphries Employee on Jan 28, 2006

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

 

Posted: Fri Oct 7, 2005  7:48 pm

 

I am having a problem erasing FLASH by sector (FCMD = 40). I have C code that executes out of RAM at 0x800 and tries to erase Flash starting at 0x8000.

 

The problem is that if I let it run freely, it manages to erase from 0x8000 to 0x83FF and then the program counter mysterious ends up at 0x1050 and a messagebox appears saying 'Unknown or USER Breakpoint' appears. This is always repeatable.

 

If I step through the instructions in RAM on at a time, the code does erase each sector as expected. Also, if I set 3 breakpoint in the RAM code, a messagebox appears saying, ""Too many Breakpoints. Do you want to use Instruction Steps." I click 'Yes' and the code runs through the Flash erase loop correctly and erases Flash as intended.

 

I followed the procedure according to Freescale documentation. I am wondering if the non-Flash processor registers need to be in a certain state. The documentation doesn't really mention this.

 

I also tried adding 'nop' instructions to see if I simply needed to add a longer waiting period between each sector erase. This actually makes it worse so that only 0x8000 to 0x81FF erase before the code breaks.

 

Anyone else run into this problem? If so, how did you solve it?

 


 

Posted: Fri Oct 7, 2005  8:18 pm

 

> Anyone else run into this problem? If so, how did you solve it?

 

I did not have problem erasing sectors on the C32. But just curious is that $40 or 40. What was the PPAGE set at when sector erasing $8000 window and How many sectors are u trying erase?

 


 

Posted: Mon Oct 10, 2005  8:53 pm

 

That was 0x40 because I am doing it in C.

 

So far, I don't have to set PPAGE to anything. From the debugger, I notice that PPAGE initializes to zero. I just figured it out and I responded to Jasons reply if you wish to see what the solution turned out to be.

 

Now, onto the programming of words into Flash via the CAN bus. (Automotive). The amusement continues.

 


 

Posted: Fri Oct 7, 2005  8:48 pm

 

Do you have the watchdog timer running also? When you add the NOPs they eat up clock cycles and you do not get as much erased before the timer runs out and possibly generates an interrupt that is not defined.

 


 

Posted: Mon Oct 10, 2005  8:48 pm

 

Thank you for your help.

 

You pointed me in the right direction (timers). The exact problem was the (TSCR1) Timer System Control Register.

I needed to set TSCR1 = 0x60.

This sets the bit TSWAI - Timer Module Stops While in Wait and also the bit TSFRZ - Timer Stops While if Freeze Mode.

 

Once I did this, the erasing of sectors completed and the program counter stayed on track.

 

I love microprocessor documentation that gives code snippets on how to do something without explaining the required register settings in other modules. Geeeezz. Code snippets don't exist in a vacuum, but documentation acts like they do.

 


 

Posted: Mon Oct 10, 2005  9:39 pm

 

I wasn't going to say anything until you mentioned CAN, but, if this group will excuse a commercial advertisement, I offer a complete bootloader kit for RS232 or for CAN. The CAN package comes with the PC CAN-4-USB interface, the 9S12C32 hardware test board and every scrap of source code incuding the PC software for downloading across the CAN bus. The CAN bus package will be upgraded shortly to support paged memory as well.

Outcomes