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.

[参考译文] MSPM0G3519:MSPM0G3519:应用在从 CSC 跳转后不启动#39;

Guru**** 2964790 points

Other Parts Discussed in Thread: MSPM0G3519

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1659497/mspm0g3519-mspm0g3519-the-application-doesn-t-start-after-jump-from-csc

器件型号: MSPM0G3519

您好:

我 →  应用手册“MSPM0 系列中的闪存多组功能“中报告的示例、在 MSPM0G3519、9 上实施 CSC μ 应用跳转:

static void start_app(uint32_t *vector_table)
{
/* Reset the SP with the value stored at vector_table[0] */
__asm volatile(
"LDR R3,[%[vectab],#0x0] \n"
"MOV SP, R3 \n" ::[vectab] "r"(vector_table));
/* Set the Reset Vector to the new vector table (Resets to 0x000) */
SCB->VTOR = (uint32_t) vector_table;
/* Jump to the Reset Handler address at vector_table[1] */
((void (*)(void))(*(vector_table + 1)))();
}

但是、此实现无法正常工作:设置 VTOR 后、MCU 卡在 CSC Default_Handler 中。

我尝试像这样改进代码:

void start_app(uint32_t *vector_table)
{
    uint32_t sp    = vector_table[0];
    uint32_t reset = vector_table[1];

    // Check if reset handler is valid (not empty flash)
    if (reset == 0xFFFFFFFF)
        mcubootFail();
    
    // Disable all interrupts globally
    __disable_irq();

    // Fully stop SysTick to avoid interrupts
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL  = 0;
    
    // Disable all NVIC interrupts
    NVIC->ICER[0] = 0xFFFFFFFF;

    // Clear all pending NVIC interrupts
    NVIC->ICPR[0] = 0xFFFFFFFF;
    
    // Clear pending system exceptions (PendSV and SysTick)
    SCB->ICSR |= SCB_ICSR_PENDSVCLR_Msk;
    SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;

    // Relocate vector table to applicat
    SCB->VTOR = (uint32_t)vector_table;
    __DSB();
    __ISB();
    
    // Set Main Stack Pointer to application's initial SP
    __set_MSP(sp);
    __DSB();
    __ISB();
   
   // Branch to application Reset_Handler
   ((void (*)(void))(reset))();
}

使用此版本时、似乎会跳转到应用程序、但应用程序的 行为不正确、因为断点未被命中、如果我重新启动调试、目标将断开连接、所以它似乎无法到达 main()。

如果我单独加载并运行应用(无 CSC)、则一切都按预期运行。

我还尝试 将 CSC 放置在专用闪存区域中、并 在 CSC 和应用程序之间分离 RAM 、但没有改进。  

有人能帮我吗?

谢谢你

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    这大概与切换堆栈 (SP) 有关、然后尝试使用旧堆栈。 这似乎发生在 CSC 示例 start_app () 的优化小于-O2。

    另一个主题(此处)有一个讨论;最后有几个对优化不敏感的替代编码。