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
Hi,
Unfortunately there are few issues in your code.
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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.
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!
-----------------------------------------------------------------------------------------------------------------------