S12DP512 Flash Erase problem

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

S12DP512 Flash Erase problem

1,005 Views
007
Contributor II

Hello,

 

My project is based on S12DP512 MCU, my issue is that the flash erasing was always failed, the 0x40 erase cmd returned completely with no error (FSTAT=0xC0), but the flash area 0x4000 was still the data burned in when BDM download, the deadline is coming, hope some big guy can help me! attached is my project

Original Attachment has been moved to: S12DP512_Flash.zip

Labels (1)
0 Kudos
4 Replies

809 Views
RadekS
NXP Employee
NXP Employee

Hi,

Unfortunately there are few issues in your code.

  1. You should avoid commands like “PPAGE = 0x3E;”. If you want use that command, you have to be sure, that your code runs from non-banked memory and it will not cause code crash. I would like to recommend do not modify PPAGE manually and leave it only on compiler/linker.
  2. Command for start of sector erase is commented out (//FSTAT_CBEIF = 1;        // issue cmd.).
  3. There is high probability that you want erase the same flash block from which you already execute this code. Unfortunately this is not allowed operations. You have to execute at least critical section of code from different flash block or rather from RAM.

In attachment you can find example code which will show how to erase and write flash at S12DP512 MCU.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

809 Views
007
Contributor II

Thank you Radek,

I have found the cause. Indeed my erase and program operation was already successful, yet in the debug window of codewarrior5.1 debugger hiwave.exe, the flash value was not updated after erase or program, it's still the value burned in when BDM download. After the flash data copied to a buffer to check, it's alreay the value programmed in. I do not know it's Hiwave's restriction or the flash memory refresh can be enabled by certain register or setting.

I'm sorry the code I attached is a temporary test version, there was several bugs in it. I re-attached the flash operation code for DP512 which is used in our BCU (Battery controller unit) CAN bootloader, it's tested worked well in last week end on our BMS (Battery management system) product.

In addition, reading through the S12DP512 flash specification, the erase or program should have no limitaion on same block of the execution code and target flash, below is copied from S12FTS512K4V1.pdf

"All Flash blocks can be programmed or erased at the same time. However, it is not possible to read from

a Flash block while it is being erased or programmed "

also in your code, your execution code is on 0xc000, and your target flash is on 0x398000, Flash_Erase_Sector(0x398000), which are sectors of block 0 of DP512.

In my bootloader code, the flash driver is on RAM to run, it should be safe.

0 Kudos

809 Views
RadekS
NXP Employee
NXP Employee

Hi,

Thank you for clarification and more details.

Please go to debugger menu->HC12MultilinkCyclonePro->Debugging Memory map->select Banked flash (could have different name according your MCU family)->Modify/Details->check refresh memory when halting.

refresh memory when halting2.PNG.png

In fact, by execution from flash block I thought that code is read from flash block and executed. I am sorry for inaccuracy.

You are right, example code from me erases the same flash block from which code is executed. However example code contains small code section which runs from RAM (please look at WaitForFlash[] in flash.h file), therefore you can use it for any flash block.

According your explanation, I suppose that PROGRAM_SEG is in RAM.

Note: I would like to recommend use placement #pragmas as complementary inside one file. For example:

#pragma CODE_SEG PROGRAM_SEG

//your code

#pragma CODE_SEG DEFAULT

Settings of these pragmas are not limited per file and in your case code placement will depends on linking order how they will be applied. So, it is good habit to revert these settings back to default at least at end of every file where these #pragmas are used. This is valid also for #pragmas CONST_SEG and DATA_SEG.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

809 Views
007
Contributor II

Hi Radek, thanks a lot for the help. I have seen the refreshed memory window after the setting checked. Thanks for the knowledge!

Regards,

dp

0 Kudos