近两天调试HCS12G128 程序异常跑飞,百思不得其解,最后找出元凶,堆栈溢出了。
S12G128 P-Flash reading issue in bootloader
Dears,
I'm working on S12G128 bootloader, it is based on AN4258.
Some certain chars have been written to P-Flash global address 0x2FE00, so after reset, bootloader will read address 0x2FE00 and decide how to go. A far pointer Upg_Cmd defined for this operation. See below code for more details.
#define Upg_Cmd_Addr 0x2FE00 //Global address 0x2FE00, store the chars
UINT8 * far Upg_Cmd;
#define GlobalToLocal(Address) (((Address) & 0x3FFFU) | (((Address) & 0x003FC000UL) << 2U) | 0x8000U)
UINT8 cc;
UINT8 const far upg_cmd_array[] @0x0BBE00 = "54600856"; //For debugging, test if bootloader can read these chars.
In main program, I'm using Upg_Cmd pointer to get the content in 0x2FE00 (Local paged address 0xBBE00) but always get 0xFF. I checked in BDM debugger interface and the actual content of 0x2FE00 (Local paged address 0xBBE00) is correct and not corrupted, also, Upg_Cmd can be correctly assigned 0xBBE00.
Upg_Cmd= (UINT8 * far) GlobalToLocal(Upg_Cmd_Addr);
cc= *Upg_Cmd++;
When code executed, cc is 0xFF which suppose to be '5'.
Any hints are apppreciated.
Walter
Hi,
see attached example project and read the main.c file:
//------------------------------------------------------------------------------
// for space creation see prm file. Search for keyword "NXP support"
// the cons is also added into entries and added feature "volatile" to be sure
// it is not revomed by optimization. You should check the address in debugger
// or S19 record to be sure the data is there
// Be sure you are using correct routine to get data from flash :
// press Alt F7-> Compiler for HCS12 -> Options -> Code generation ->
// -> Match PPAGE register is used for paging
// Write Runtime in the cell which appears.
// ..or write -CpPPAGE=RUNTIME into compiler option
// The compiler command line is also adjusted to be compiler informed we will
// use paged variables. The option "-D__FAR_DATA" is added into
// the compiler command line (Alt F7->Compiler for HC12 ->
// ->Add -D__FAR_DATA in the Command Line Arguments)
//------------------------------------------------------------------------------
..or write -CpPPAGE=RUNTIME into compiler option…
When debug you use see:
I hope this will lead you to solve your issue.
Best regards,
Ladislav