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.

To load and run a program in RAM

Other Parts Discussed in Thread: TMS570LS3137

Dear all,

I have tried to follow instruction in this post but have not reached good results:

procedure A
1) to open "sys_core.asm" and to change "00800 0000" to "0x0000 0000 + sizeof(.text)" in

stackpointer definition
in my case sizeof(.text) from MAP file = 0x3408

     userSp:   .word 0x00004000+0x00000200

     svcSp:    .word 0x00004000+0x00000200+0x00002000

     fiqSp:    .word 0x00004000+0x00000200+0x00002000+0x00000200

     irqSp:    .word 0x00004000+0x00000200+0x00002000+0x00000200+0x00000200

     abortSp:  .word 0x00004000+0x00000200+0x00002000+0x00000200+0x00000200+0x00000100

     undefSp:  .word 0x00004000+0x00000200+0x00002000+0x00000200+0x00000200+0x00000100+0x00000100

2) to build the project

3) to establish a debug connection - click on "Debug" button (or press F11 key)

4) nothing is downloaded, this message is generated in the Console window:
"CortexR4: GEL Output:     Memory Map Setup for Flash @ Address 0x0
CortexR4: Loader: One or more sections of your program falls into a memory region that is not writable.  These regions will not actually be written to the target.  Check your linker configuration and/or memory map."
PC register = 0x2DF4 (the body of readmsg function linked in from rtsv7R4_T_be_v3D16_eabi.lib)

5) to select "Target_RAM_to_0x0" - error window pops up with a message:
"CortexR4: Trouble Writing Memory Block at 0xffffffcc on Page 0 of Length 0x4: Error 0x80001822/-1141 Fatal Error during: Memory, Execution, Timeout, Target,  Processor communication timeout. It is recommended to RESET EMULATOR. This will disconnect each target,   perform an emulation reset, and then reconnect each target. Power cycle the target board before continuing."

press on "Cancel" which leads to following error in the console log:
"Target_RAM_to_0x0() cannot be evaluated.
target access failed
    at *((int *) 0xffffffcc)=0x00000001 [tms570ls3137.gel:224]
    at swap_mem(1) [tms570ls3137.gel:277]
    at Target_RAM_to_0x0()
CortexR4: 17 other operation(s) were automatically canceled as a result "


6) to select "CCS_MemMap_RAM_at_0x0 - shown a message:
"CortexR4: GEL Output:     Memory Map Setup for RAM @ Address 0x0.CortexR4: GEL Output:     For Debugging Only!"


procedure B
1) sys_core.asm:
userSp:   .word 0x00000000+0x00000200
svcSp:    .word 0x00000000+0x00000200+0x00001200
fiqSp:    .word 0x00000000+0x00000200+0x00001200+0x00000200
irqSp:    .word 0x00000000+0x00000200+0x00001200+0x00000200+0x00000200
abortSp:  .word 0x00000000+0x00000200+0x00001200+0x00000200+0x00000200+0x00000100
undefSp:  .word 0x00000000+0x00000200+0x00001200+0x00000200+0x00000200+0x00000100+0x00000100

2) linker file:
/*----------------------------------------------------------------------------*/
/* Memory Map                                                                 */
MEMORY{
    VECTORS (X)  : origin=0x00000000 length=0x00000020
    STACKS (RW)  : origin=0x08000000 length=0x00001300
    RAM (RW)     : origin=0x08001300 length=0x00007000
}

/*----------------------------------------------------------------------------*/
/* Section Configuration                                                      */
SECTIONS{
    .intvecs : {} > VECTORS
    .text    : {} > RAM
    .const   : {} > RAM
    .cinit   : {} > RAM
    .pinit   : {} > RAM
    .bss     : {} > RAM
    .data    : {} > RAM
    .sysmem  : {} > RAM

}

The linker complains:
error #10099-D: placement fails for
   object ".intvecs", size 0x20 (page 0).  Available ranges:
   VECTORS      size: 0x20         unused: 0x20         max hole: 0x20

According to MAP file a length of the section .intvecs = 0x48.

To change a line in the linker file:
VECTORS (X)  : origin=0x00000000 length=0x00000050

3) to click on "Debug" which ends up with error message:
"CortexR4: GEL Output:     Memory Map Setup for Flash @ Address 0x0CortexR4: Loader: One or more sections of your program falls into a memory region that is not writable.  These regions will not actually be written to the target.  Check your linker configuration and/or memory map.
CortexR4: Flash operation timed out waiting for the algorithm to complete. Operation cancelled.
CortexR4: Trouble Writing Memory Block at 0x8001300 on Page 0 of Length 0x3130
CortexR4: GEL: File: C:\Users\jiri.janacek\workspace_v5_2\Hercules TMS570 Blinky Example\Debug\Hercules TMS570 Blinky Example.out: Load failed."

Do you have any idea what is going wrong? Did I understand the linked post wrongly?

Many thanks in advance,

Jiri

  • Hello Jin,

    I believe all you are missing is to modify your linker file memory map so that nothing is placed in the old RAM location. Update the lines in red as shown and let me know if this helps.

    /*----------------------------------------------------------------------------*/
    /* Memory Map                                                                 */
    MEMORY{
        VECTORS (X)  : origin=0x00000000 length=0x00000020
        STACKS (RW)  : origin=0x00000000 length=0x00001300
        RAM (RW)     : origin=0x00001300 length=0x00007000
    }

    /*----------------------------------------------------------------------------*/
    /* Section Configuration                                                      */
    SECTIONS{
        .intvecs : {} > VECTORS
        .text    : {} > RAM
        .const   : {} > RAM
        .cinit   : {} > RAM
        .pinit   : {} > RAM
        .bss     : {} > RAM
        .data    : {} > RAM
        .sysmem  : {} > RAM

    }

  • Hello Chuck,

    thanks for your hint! One minor remark - in your above example vectors segment overlaps stacks one. I guess that is not intended, just typing mistake.

    Anyway, it seems there still remains another issue - below applied changes are listed:

    Attached simple example (slightly modified) available on the TI website as well.
    5658.Hercules TMS570 Blinky Example.zip

    I am using Code Composer Studio  Version: 5.2.1.00018


    -----------------
    linker file:
    MEMORY{
        VECTORS (X)  : origin=0x00000000 length=0x00000050
        STACKS (RW)  : origin=0x00000050 length=0x00001300
        RAM (RW)     : origin=0x00001350 length=0x00007000
    }

    -----------------
    sys_core.asm:
    userSp:   .word 0x00000050+0x00000200
    svcSp:    .word 0x00000050+0x00000200+0x00001200
    fiqSp:    .word 0x00000050+0x00000200+0x00001200+0x00000200
    irqSp:    .word 0x00000050+0x00000200+0x00001200+0x00000200+0x00000200
    abortSp:  .word 0x00000050+0x00000200+0x00001200+0x00000200+0x00000200+0x00000100
    undefSp:  .word 0x00000050+0x00000200+0x00001200+0x00000200+0x00000200+0x00000100+0x00000100

    -----------------
    tms570ls3137.gel:
    Switch function calls added at the beginning of the

    OnTargetConnect() body:

    OnTargetConnect(){
        
        swap_mem(RAM);
        memmap(RAM, EMIF);

    -----------------
    Project Explorer -> right click on the selected project -> Debug  as...

    Error message:
    CortexR4: Trouble Writing Memory Block at 0xffffffcc on Page 0 of Length 0x4: Error 0x80001822/-1141 Fatal Error during: Memory, Execution, Timeout, Target,  Processor communication timeout. It is recommended to RESET EMULATOR. This will disconnect each target,   perform an emulation reset, and then reconnect each target. Power cycle the target board before continuing.  
    CortexR4: GEL: Error while executing OnTargetConnect(): target access failed     at *((int *) 0xffffffcc)=0x00000000 [tms570ls3137.gel:228]     at swap_mem(1) [tms570ls3137.gel:69]     at OnTargetConnect() .

    It looks like a register MMUGCR has not been initialized properly, does not it?

    -----------------
    View -> Memory Browser:

    beginning of the .text section (@0x2B50) as defined / listed in MAP file -> seems to be OK.

    -----------------

    Debugger is waiting on a usual enter point __c_int00. If a program run is launched, then the program goes/jumps behind address limits of the code where all zeroes are.
    Breakpoints are set at the lines where LEDs (hetREG->DOUT       = snake[i];) are toggled - BP are never reached.

    Another case:
    Debugger resume (F8) is not started, just "Run to Line" (64 in sys_main.c, run_LED_StartUp()) is launched and then press on the "Resume".
    Breakpoints are set at the lines where LEDs (hetREG->DOUT       = snake[i];) are toggled - execution is halted just at the BPs.

    But this is only one tested point ("Run to Line") - there could be others. By the way, such procedure is not 100% reproducable.

    -- sometimes if "Run to Line" is selected, then window with neverending progress bar appears (GEL Expression: GEL_Go(0x3C0C) - hope that is the address where the run_LED_StartUp() is called from - it gets frozen - debug session must be restarted.

    -- sometimes the code does not reach any BP and goes/jumps behind address limits of the code where all zeroes.

  • Hello Jiri,

    I am not 100% sure where the error is coming from when the memory swap is performed but this is expected as was mentioned in the other thread you linked to originally. This should not cause the problem. Also, you are correct that I missed the starting point of stacks being at 0x00000020 instead of zero. This was a simple oversight. Also, I don't know if setting the size of the vectors region to 0x50 has anything to do with the issues you  are seeing, but for the R4, it will never exceed 0x20 so you should use this value.

    Also, I normally leave the gel script as is and simply run the scripts from the script menu once you are connected to the device. The only caveate is that you will need to re-run the memory swap script anytime you have a system reset since the memory swap bit will be reset to its default during a system reset. It will stay unchanged during a CPU reset though.

    Once the map is changed to RAM Start = 0x00000000 and the memory swap completed, the code will load to RAM using the normal Load function. From there, debug and execution should be the same as long as there is no code that generates a system reset in the device.

  • Hello Chuck,

    a root cause of this weird behaviour is probably a fact that already mentioned rule (by in the lined thread) has not been fulfilled:

    • When going through the initialization of the microcontroller, be careful with steps such as CPU RAM auto-initialization or CPU RAM self-test using PBIST. These must be disabled for the CPU RAM, else they will cause the application to crash (run NOPs).

    In other words, a call of function _memoryInit_() in sys_startup.c (Hercules TMS570 Blinky Example) has been removed and then the program runs in a debug session correctly. Not verified yet (with datasheet,...) which side effects could occur due to this dirty removal.

    Anyway, thank for your advices, Chuck!

    Cheers, Jiri

  • Hello Jiri,

    Good catch with the memory init call. Yes this will cause the RAM to be over written and your program corrupted. This will primarily be an issue if there is an uninitialized variable in SRAM. You could still modify the init routine to only initialize the peripheral RAMs since this would not impact your debug code.

  • Note that since you have successfuly resolved the issue, I will close the thread. I have marked your final resolution verified since it was key to getting this working.