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.

CCS/TMS570LS1224: How to copy a piece of code to the specified RAM area and trigger MPU operation protection?

Part Number: TMS570LS1224

Tool/software: Code Composer Studio

There is no related tutorial or code in this regard, because our MPU configures a certain area to be unexecutable, and wants to run the protection of the MPU by copying a function to this RAM area.

Based on the above ideas, I want to test whether flash can implement MPU execution protection. As shown in the following figure, I configured 32 bytes after the start address of 0x6220 (25120) as unexecutable permission, and then executed “ tr1++(25112)” in the program.  when starting MPU protection, then the program jumps to "b prefetchEntry". Then I want to ask is that the program has been stuck in the "b prefetchEntry" at this time, how to enter the relevant interrupt function?

 Flash Mpu Configuration:

  • Hello,

    The linker has features which support allocating a section at one address for loading, and a different address for execution.  This make it easy to perform the copy from the load address to the run address.  Please refer to the source code of CAN bootlader which copies flashAPI section to SRAM, and execute flash APIs from SRAM.

    1. Linker CMD file: define a section for flash API

    MEMORY

    {

       VECTORS    (X)   : origin=0x00000000 length=0x00000020

       FLASH_API  (RX)  : origin=0x00000020 length=0x000014E0

       FLASH0    (RX)  : origin=0x00001500 length=0x00000500   //LS04x and RM42 Flash size is 0x60000

       SRAM       (RW)  : origin=0x08002000 length=0x00005000   //LS04x and RM42 SRAM size is 0x8000

       .... ....

    }

    SECTIONS

    {

      .intvecs : {} > VECTORS

      flashAPI :

      {

        bl_flash.obj (.text)

        ... ...

      } load = FLASH_API, run = SRAM, LOAD_START(api_load), RUN_START(api_run), SIZE(api_size)

      .text  > FLASH0

      ... ...

    }

    2. Copy flashAPI section from flash to SRAM:

    ;-------------------------------------------------------------------------------
    ;
    ; Copy the Flash API from flash to SRAM.
    ;

    .def _copyAPI2RAM_
    .asmfunc

    _copyAPI2RAM_

    .ref api_load
    flash_load .word api_load
    .ref api_run
    flash_run .word api_run
    .ref api_size
    flash_size .word api_size

    ldr r0, flash_load
    ldr r1, flash_run
    ldr r2, flash_size
    add r2, r1, r2
    copy_loop1:
    ldr r3, [r0], #4
    str r3, [r1], #4
    cmp r1, r2
    blt copy_loop1
    bx lr

    .endasmfunc

  • Hello, thank you very much for your reply.
    There are still a few questions:


    1. Where is the CAN bootlader source code you mentioned?


    2. Does bl_flash.obj (.text) refer to the bi_flash.c file?


    3. At present, we want to put a function (not a c file) into a certain RAM to run, what needs to be done?


    4, I want to perform mpu trigger protection in a certain area of the flash (RO) I set, how do I need to test? How to write data to the flash of the specified address?

    Or what is your email address? Can we ask you questions by email?

  • Hello,

    1. The link for the source code is included in the user guide:
    www.ti.com/.../spna186.pdf

    2. Yes, bl_flash.obj is the object file of bi_flash.c

    3. You can place a function to RAM and execute the function from RAM.
    processors.wiki.ti.com/.../Placing_functions_in_RAM

    4. You have to use the flash API to erase/program the flash. The user guide is located in the API installation folder:
    www.ti.com/.../F021FLASHAPI
  • Thank you very much for your reply
    For the third question, can you give an example:
    For example, I now have a function in main.c that is void Fun_test(void){...}, then how do I copy the function(Only need this function,Because your previous recovery seems to be copying the entire .c file into RAM, I only need a function now.) to the address with the RAM address 0x08003CFC to start running?
    look forward to your reply!

  • Hi BJ,

    In C function:

    #pragma SET_CODE_SECTION(".blinky_section")
    void blinky()
    {
    int i;
    gioSetDirection(hetPORT1, 1);
    while(1)
    {
    gioToggleBit(hetPORT1, 0);
    for(i=0;i<1000000;i++);
    }
    }
    #pragma SET_CODE_SECTION()

    In linker cmd file:

    --retain = "*(.blinky_section)"

    .blinky_section : RUN=SRAM, LOAD=FLASH0
    LOAD_START(bkstart), LOAD_END(bkend), LOAD_SZIE(bksize),
    RUN_START(runstart), RUN_END(runend).