FLASH erase code problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

FLASH erase code problem

3,633件の閲覧回数
JamesPev
Contributor I
 I am using the MC9S12NE64 microcontroller and trying to write code to allow my device to reflash itself over ethernet.  For the actual flash writing portion of the code I am basically just using the code from AN2720, but it doesn't seem to be working properly.  I can erase and write to sectors that are already blank, but an attempt to erase a sector that already contains data gets an ACCERR.  All protection is turned off (and besides it seems that protection problems would cause a PVIOL instead of ACCERR).

 I am using the BDM to monitor the operation, but I am careful not to put any breakpoints in the flashing portion of the code so I don't believe this would cause an issue.  After I started having problems I moved all the flashing code to a sandbox application that just consists of the flashing code (ie no ISR's or any other code), but this didn't improve things.

 Any ideas?  I read through AN2400 (HCS12 NVM guidelines) and I can't figure out which of the 12 invalid FLASH operations could be causing my ACCERR.  Any help would be greatly appreciated.

James

ラベル(1)
0 件の賞賛
返信
5 返答(返信)

1,435件の閲覧回数
TaB
Contributor I
I used the same app note as the basis for my boot loader on an MC9S12DG128.  It wouldn't erase the last sector where the ISR vectors and security bits were.  Where are you trying to write?  Is the page number correct?

How about the clock frequency of the flash block?  I think that there is an error in the code for frequencies below 12MHz with an extra divide by 8 in the equation.  Make sure that the FCLK frequency calculates out to be between 150 and 200 kHz.

As far as writing the last sector, I used redirection, pointing the ISR vectors to RAM.  My application code fills this space with jumps to the real interrupt code.  That way the last sector didn't need to be reflashed.

Since you were using the debugger, you might try ensuring that the memory window isn't looking at the address space that you are trying to flash.  I had problems with that.  Also page 3F was for 8000 thru FFFF.  For some reason with page = 3F I saw the flash erased in the 8000 - BFFF area, but not in C000 through FFFF.

TaB
 

0 件の賞賛
返信

1,435件の閲覧回数
JamesPev
Contributor I
 It doesn't seem to matter so much which area of flash I try to write... just that I can't write to any area where I have already placed data.  Right now I am just trying to write to 0x4000.  When I map a constant to this area, I can't alter this segment.  If I comment out this constant, the erasing and programming works fine in this area.  I can even re-erase it and program again.

 I am concerned the debugger might be playing tricks on me after you mentioning the memory window.  It doesn't seem to matter much though how I use it.  Even closing all the monitoring components (memory window etc) while the code is running and disabling triggers doesn't seem to change the operation.  Does the BDM access memory even when these components are closed?

 Thanks for your reply!

James
0 件の賞賛
返信

1,435件の閲覧回数
JamesPev
Contributor I
I think I have my current issues figured out.  For one, the BDM does not refresh flash memory locations all the time.  I created code to copy areas out of flash and verified that the writes were in fact working even though through the debugger it didn't appear that they were.

Second issue was that the routines in datapage.c (to set PPAGE etc for far memory access) were in FLASH, as were the (long) math functions (comparison, multiplication etc) which were being used by the code to manipulate pointers.

These fixed, it appears it is all working now.

Now I need to figure out how to get all this working in my real application.


James


0 件の賞賛
返信

1,435件の閲覧回数
KarelAd
Contributor I
I agree with James, I have spent lot of time to solve this issue. In the CW Debugger the FLASH changes made by code does not appear immediately. To close all the debug window does not help to let the debugger to read the FLASH mem. I don't know why Refresh doesn't help.

Open the "HCS08 Open Source BDM/Flash..." window helps to refresh the content of the FLASH mem. But it causes the reset of the system.

Copy content of the FLASH to the RAM for debug purposes. So you can see what happened in the FLASH.

Does anybody have another approach?
0 件の賞賛
返信

1,435件の閲覧回数
kef
Specialist I

After you connect, in HC12MultilinkCyclonePro menu select Debugging Memory Map..., then select flash region of interrest and modify it to "refresh memory when halting"=checked.

0 件の賞賛
返信