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.

TMS570LC4357: Bootloader, Application and SafeTI Library

Part Number: TMS570LC4357

Hello all,

I'm implementing a Bootloader and an Application for the TMS570LC43x. In the application I want to use the SafeTI Library. According to the provided example, I'm calling the SL_Init_R5Registers() and SL_Init_StackPointers() routines from sl_asm_api.asm at the beginning of the Application. Whereas in the Bootloader, I'm calling _coreInitRegisters_() and _coreInitStackPointer_() from HL_sys_core.asm.

What I noticed is that the link register (LR) holds the wrong value for the return address when leaving SL_Init_R5Registers() in the Application. As a result, execution doesn't continue after the call of SL_Init_R5Registers(), which is wrong. As far as I understand, this happens because SL_Init_R5Registers() assumes that the controller is in supervisor mode although it is not because we have already switched to system mode in the Bootloader (in _coreInitRegisters_()).

  1. How should I deal with that issue? Should these routines only be called after reset, so only in the Bootloader?
  2. After reading the code of these routines, it's not clear to me what is the difference of the routines _coreInitRegisters_() and _coreInitStackPointer_() from HL_sys_core.asm and the routines SL_Init_R5Registers() and SL_Init_StackPointers() from sl_asm_api.asm?

Thank you for your help,

Simon

  • Hello Simon,

    1. This function is normally called after the device is powered up or after reset. If you want to call this function from other location, please add the following instruction at the beginning of the function:

            CPS    ARM_MODE_SVC 

    This will store the return address to R14 register in supervisor mode.

    2. Both those two functions is to initialize the MCU general registers and floating point registers. As you knew, the function in SL switches to SVC mode, but the first function switches to system mode. When you call SL_Init_R5Registers() in application, the return address (R14) is the value defined by coreInitRegisters_() in bootloader. SO the return address is not correct. 

  • Hello QJ,

    Thank you for your help. As you suggested, switching to supervisor mode before calling the routines work fine.

    QJ Wang said:

            CPS    ARM_MODE_SVC 

    It's still not 100% clear to me what the reason for having two versions of these functions which are almost the same (besides switching the mode) is. Do functions from the SafeTI library need to be executed in SVC mode?

    Thanks,

    Simon

  • Hi Simon,

    The SafeTi library needs to be executed in privilege mode (all no-user mode).

    The SVC mode is used by SafeTi Library by default. You can use system mode instead:

    comment out the line 264: