HCS12 Bootloader

近两天调试HCS12G128 程序异常跑飞,百思不得其解,最后找出元凶,堆栈溢出了。




假设已回答

S12G128 P-Flash reading issue in bootloader

由  Wang Walter 于 2017-3-1 提出的问题
最新回复由Wang Walter于2017-4-18提供 

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

  • lama

    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

    附件

    • Wang Walter

      Hi Iama,

       

      Thanks for reply, unfortunately my issue still remains the same after adding these compilor options.

      But when I'm trying debugging into assembly codes, especially going through the routine _LOAD_FAR_8, the root cause seems found:

      The problem may be caused by wrong PPAGE address defined in datapage.c, it was defined 0x30 as below picture shows, but S12G128 PPAGE register is at 0x15.

      This bug in AN4258 based bootloader may cause codes cannot use "* far" or "*__far" to read banked data due to wrong PPAGE address.

       

      After modifying PPAGE_ADDR to correct address 0x15, data at Flash address 0x20000 (banked addr is 0xBBE00) can be read correctly.

       

      Thanks for your support, and it would be good if you can add this finding to AN4258 new revision.

       

       

      Walter

      • lama

        Hi,

        which version of the CW you use? (No IDE version but CW4.1, 4.2,.5.0, 5.1, 5.2)

        Could you please send me your project? You can use standard "support" way to nxp - just introduce email by hello Ladislav. (How to submit a new question for NXP Support )

        However, it would be better if you are able to send shortened, fuctional, issue highlighting version of the project.

        (Do not forget to pack entire project. I hope you have set the project paths relative to project. The best is if everything is placed in the project folder)

         

        Or you can send it to [email protected].

        I'll check and correct it.

         

        Best regards,

        Ladislav

        • Wang Walter

          Hi Lasislav,

           

          I'm using CW 5.1. We have done a lot of changes to bootloader to fit our application. Really sorry that I cannot send it due to RD policy.

           

          The issue is really simple and clear: the PPAGE_ADDR definition in datapage.c is not correct. Also, it is easy to re-produce, by just define a __far array in main.c and try to read it.

           

          Thanks

          Walter.


猜你喜欢

转载自blog.csdn.net/fz835304205/article/details/78677344