This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Can not debug with Keil !

Other Parts Discussed in Thread: HALCOGEN

Hi everybody, MerryChrismas !

I have a problem, with Keil.

I use HALCOGEN to generate code for RM48L950PGE and write a simple project to test clock on the MCU. 

I did successed on my TMS570 board ( debugging with Keil) but the RM48 did not work.

The MCU keeps in the _memoryInit_   mloop  of sys_memory.asm.

I can not firgure out the problem and I tried it on IAR, it works.

I use JlinkV8 for debugging. Is that a bug of HALCOGEN ?

By the way, why can't I get the program run with any optimization option in Keil ? With IAR, the optimization is not effective much, but it still works.

  • Hello:

    Just to let you know we received your post and will work on providing you an answer.

    Regards,

    Enrique Lizarraga

  • Hi Tan Dat Tran

    Are you using latest HALCoGen? 2.11.00 ? If not please download it from http://www.ti.com/tool/halcogen
    I remember this issue is been fixed from version 2.10.00.

    Note: RM48xx code cannot be run on TMS570xx target, hope it's taken care.

    Best Regards
    Prathap

  • Thank Prathap.

    Yes, it's taken care and I also use the latest HALCOGEN version. Here is the project: 6403.RM48_DCC.rar

    The drivers are all generate by HALCOGEN and for RM48L950PGE, I dont change anything. With TMS570, I do the same (certainly not the same target).

    If anyone can get it work, please try to build it with optimization options (OO1/OO2/OO3).

  • Tan Dat Tran said:

    Thank Prathap.

    Yes, it's taken care and I also use the latest HALCOGEN version. Here is the project: 6403.RM48_DCC.rar

    The drivers are all generate by HALCOGEN and for RM48L950PGE, I dont change anything. With TMS570, I do the same (certainly not the same target).

    If anyone can get it work, please try to build it with optimization options (OO1/OO2/OO3).

    HW: In CCS, it does not work with optimization too. The reason is in the startup code:

    With optimization:

    1. The compiler (code generation 4.9) will set R4 register to some value like: 0xFFFFF500 (sth like this)at the beginning of _c_int00().
    2. This R4 register is modified by the assamble functions like _coreInitRegisters_();
    3. The compiler does not know that R4 value is no longer valid. It access the VIM register using this R4. str Rx. [R4, #y]. vimREG->FIRQPR0 =  SYS_FIQ……
    4. At the end, the VIM register is not initilized and the interrupt is not enabled since the baseaddress is wrong

    My workaround is simple: delete the first 20 or 30 lines:

    /* USER CODE BEGIN (5) */

    /* USER CODE END */

     

          /* read the system exception status register */

    //    register uint32_t temp = systemREG1->SYSESR;

     

    /* USER CODE BEGIN (6) */

    /* USER CODE END */

     

          /* check for power-on reset condition */

    //    if (temp & 0x8000)

    //    {

                /* clear all reset status flags */

                //systemREG1->SYSESR = 0xFFFF;

     

    /* USER CODE BEGIN (7) */

    /* USER CODE END */

     

                /* continue with normal start-up sequence */

    //    }

    //    else if (temp & 0x4000)

    //    {

                /* Reset caused due to oscillator failure.

                Add user code here to handle oscillator failure */

     

    /* USER CODE BEGIN (8) */

    /* USER CODE END */

    //    }

    //    else if (temp & 0x2000)

    //    {

                /* Reset caused due to windowed watchdog violation.

                Add user code here to handle watchdog violation */

     

    /* USER CODE BEGIN (9) */

    /* USER CODE END */

    //    }

    //    else if (temp & 0x20)

    //    {

                /* Reset caused due to CPU reset.

                CPU reset can be caused by CPU self-test completion, or

                by toggling the "CPU RESET" bit of the CPU Reset Control Register.

                Add user code to handle CPU reset:

                check for selftest completion without any error and continue start-up. */

     

    /* USER CODE BEGIN (10) */

    /* USER CODE END */

    //    }

    //    else if (temp & 0x10)

    //    {

                /* Reset caused due to software reset.

                Add user code to handle software reset. */

     

    /* USER CODE BEGIN (11) */

    /* USER CODE END */

    //    }

    //    else

    //    {

                /* Reset caused by nRST being driven low externally.

                Add user code to handle external reset. */

     

    /* USER CODE BEGIN (12) */

    /* USER CODE END */

    //    }

    However, after this workaround, you need a PORRST to overcome the ESM errata.

    I am not sure if the problem in CCS and Keil are the same, but you can try.

  • This error is caused due to violation of the rules that apply when mixing C and assembly source files. A called function can use CPU registers R0 to R3 and R12 without first having to save them. If called from a C source file, the compiler will automatically save these registers on entry to the function and restore these registers upon exit. Any other registers used by the called function need to be manually saved and restored by the called function.

    One possible workaround to this issue is to initialize the CPU registers before performing the reset check.

    Regards, Sunil

  • Hi, I tried not to call _memoryInit_() in sys_startup.c and the system work very well with all optimization option and run stable, can be reset ...

    Before that, my system sometimes can not be reset.

  • I checked HALCOGEN 3.00 and thing seems not to change. I build a Keil project and MCU still got stuck with mloop in  _memoryInit_().

    The system works well with IAR.

    Is it a bug of Keil or Halcogen ?

  • Hi Tan,

    I have raised a ticket to address this in next HALCoGen release.

    Mean while Can you try replacing the sys_memory.asm in the "C:\ti\Hercules\HALCoGen\v03.00.00\drivers\TMS570LS3137ZWT\SYSTEM570v000" with the attached sys_memory.asm.. I just did minor changes in the assembly function. Sorry I do not have KEIL installed in my machine to test, please let us know your comments after testing. 6765.sys_memory.asm

    - Prathap

  • Still cant get it run. Stuck in the same place. I think there will no problem if we dont call memory_init() when I use previous HALCOGEN version.

    And now, I have another problem : the system cant not reach the main(). I tried changing __main() in sys_startup.c into main() and it works ????

    In Keil, the CPU keeps waiting for a valid value of MSTCGSTAT but it never get althought I try to read it in some other ways. So I guess that the process can be done for a reason I dont know. I can see that the auto memory init process is the same for both rm4 and tms570, but I have no idea why it cant work on rm4. Additional, with any optimization options, tms570 also stuck somewhere if we call memory_init().

  • I have the same problem with HalCoGen 3.00 when the optimization is enabled in CCS4.

    The rootcause is that: R4 and R12 are used in memory_init() function and it is also used in somewhere else. memory_init() changes the register value and the compiler does NOT know that. The worst thing is: Since it is memory_init, you can NOT save the register into stack! What I did is: I look into the asm generated, finding that I can use R11 and R12 without impact the other programs, then I changed the R4 in memory_init() to R11 to solve the problem. In CCS, you can also to force the compiler to free the usage of R4 and R12 to avoid this problem.

    I am not sure if it is the same problem as you and if Keil can free the usage of R4 and R12 by some settings.

    Regards,

    Haixiao

  • Thank Haixiao Weng!

    But that is not my problem. My problem is the memory_init() cant be done because the CPU can not get the valid value of MSTCGSTAT, so it keeps in the mloop.

  • Can you publish the .out, .ELF or .HEX whatever execute file that generated with Keil tool?

    Regards,
    Haixiao

  • Check the value that is written to the system module MSIENA register inside the memory_init() function. You can read the value in the MSIENA register when the code is stuck inside the memory_init routine. This function must not set any other bit in the MSIENA register other than those included in the 32-bit value 0x1C57F.

    Regards, Sunil

  • @ Haixiao:

    Here are the entire projects I built with Keil:

    This one is generated by 2.11 version and not working:

    3678.RM48_DCC.rar

    This one is generated by 3.00 version, memory_init() is modified by Prathap, not working:

    3247.rm48_dcc1.rar

    And this one can be run, without the memory_init() calling, with highest optimization options, working:

    1307.RM48_DCC.rar

    Sunil:

    Thank you, I knew that number meaning. I did not change it.

  • I can not find the instruction TST R2, #0x100 or TST R5,#0x100 (in the sys_memory.asm) in the generated HEX file.

    It should be sth like: E3150C01 (R5) and E3120C01(R2) (ARM mode). 

    Can you debug your code in KEIL and find out what the compiler translate the

    tst r5, #0x100

    TO machine code?

    By the way, can you upload the HEX file using intel HEX format?

    Thanks,

    Haixiao

     

  • I cant not find it in the hex file either althought I called memory_init() . What the problem with Keil ??? Very strange behavior !

    How to generate Intel hex file with Keil ?