Skip to main content
Super User
June 22, 2022
Solved

[RESOLVED] Why IAR EWARM debugger resets STM32F7 in a weird way

  • June 22, 2022
  • 3 replies
  • 4832 views

Apologize for IAR specific question, hope someone here can shed some light on my problem. I've tried to ask IAR support, but looks like they have a long weekend or whatever.

I have a bootloader at 0x08000000 and main app at 0x08008000.

The bootloader initializes something for the main app so it must execute every time before the app.

Pretty common thing, done many times with Atollic and CubeIDE.

But I cannot debug this with the EWARM debugger.

When I set the main app as active and start debugger, it enters the main app directly from its reset handler, without going thru the bootloader. No matter how I define the reset method - "system", "core" "connect under reset".

More to this - the reset button on the debugger toolbar has similar options - and none of these goes to the bootloader.

Unchecked run to main - does not help.

I tried to debug the bootloader instead, and load the main app as extra image.

This properly starts the bootloader, but after entering the main app source navigation ("find definition" or "find declaration") fails randomly. Both images share many common files, maybe this confuses the search. Thus I want to have the main app the active one.

Any advise how to force the IAR debugger to obey the "system" or "hardware" or "connect under reset" ?

The debugger probe is ST-LINK v3 mini with latest firmware, in SWD mode.

STM32F767.

EWARM version 8.40

    This topic has been closed for replies.
    Best answer by Pavel A.

    Final variant: removed user prompt, works silently.

    Tested with EWARM 8.40

    // This script ensures that bootloader always executes before the app
    __var seenReset;
     
    // This executes after the debugger resets the system
    execUserReset()
    {
     seenReset= 1;
    }
    execUserExecutionStarted()
    {
     // This executes when the debugger stops at main() of the main app
     // We must execute the bootloader first, so move to the BL start addr and let the BL jump to the app.
     if (seenReset) {
     __var BL_reset_PC, BL_SP;
    	seenReset = 0;
     BL_reset_PC = *((unsigned long*)0x08000004);
     BL_SP = *((unsigned long*)0x08000000);
     
     __message "BL_PC : 0x", BL_reset_PC:%X, "SP=", BL_SP:%X, "\n";
     #PC = BL_reset_PC;
     #SP = BL_SP;
     __message("execUserExecutionStarted -- after move");
     } else {
     __message("Continuing to main...\n");
     }
    }

    3 replies

    Technical Moderator
    June 22, 2022

    Hello,

    I'm not sure this is related to a reset method.

    If you uncheck the "Run To" "main" option in the debug options, maybe that can help you to see what is actually happening ?

    0693W00000NsSG2QAN.png

    Pavel A.Author
    Super User
    June 22, 2022

    Thank you @Mike_ST​ . If "run to main" unchecked, the debugger stops in the assembly startup at reset handler of the main app. No way to reset to the boorloader, unless the bootloader itself is the active project.

    Technical Moderator
    June 23, 2022

    When debugging,

    the Reset_Handler will call the __iar_program_start routine that will initialize

    some stuff and then __iar_program_start will branch to the main() of the active project.

    if you're confident enough, you can edit the startup_stm32f767.s Reset_Handler of your app to jump to the bootloader address:..

           LDR    R0, ="your bootloader address"

           BX     R0

    but you have to configure the bootloader project to jump to the iar_program_start address of your app...

    Please check the IAR technical note here:

    https://www.iar.com/knowledge/support/technical-notes/general/creating-a-bootloader-for-cortex-m/

    Maybe that can help you.

    Pavel A.AuthorAnswer
    Super User
    June 26, 2022

    Final variant: removed user prompt, works silently.

    Tested with EWARM 8.40

    // This script ensures that bootloader always executes before the app
    __var seenReset;
     
    // This executes after the debugger resets the system
    execUserReset()
    {
     seenReset= 1;
    }
    execUserExecutionStarted()
    {
     // This executes when the debugger stops at main() of the main app
     // We must execute the bootloader first, so move to the BL start addr and let the BL jump to the app.
     if (seenReset) {
     __var BL_reset_PC, BL_SP;
    	seenReset = 0;
     BL_reset_PC = *((unsigned long*)0x08000004);
     BL_SP = *((unsigned long*)0x08000000);
     
     __message "BL_PC : 0x", BL_reset_PC:%X, "SP=", BL_SP:%X, "\n";
     #PC = BL_reset_PC;
     #SP = BL_SP;
     __message("execUserExecutionStarted -- after move");
     } else {
     __message("Continuing to main...\n");
     }
    }

    Pavel A.Author
    Super User
    July 8, 2022

    I have to add that IAR support replied and pointed me to a helpful AN.

    The IAR debugger can handle two images with duplicate symbols. Very nice. Though could be a bit faster.

    Graduate II
    July 9, 2022
    Pavel A.Author
    Super User
    July 9, 2022

    yes, --drv_vector_table_base