Debugging crashes after a few lines for every programm, even though pure execution works without issues

When I try to debug a programm (build with "optimize for debugging" and debugging started by pressing "Debug" in VSCode) I get to the debug-view and can also go one or a few lines further (using e.g. Step-Over or Continue), but then the program crashes and enters a restart-loop (as visible from the serial terminal).
The same programm executes without issues when just ran (pressing "Flash" instead of "Debug" in Visual Studio Code).

I'm building a more complex programm that also uses the secure partition etc, but for demonstration purposes I just build a very simple Hello-World programm without any of that consisting just of these three files:

main.c

int main(void)
#include <zephyr/kernel.h>
#include <stdio.h>

int main(void)
{
        
        printf("Begin \n");
      
        for (int i = 0; i < 3; i++) {
                printf("Hello World \n");
        }

        printf("End \n");
        
        return 0;
}

CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(helloworldtest)

target_sources(app PRIVATE src/main.c)


complete empty prj.conf


When executing by pressing "Flash" the terminal once prints the correct/expected output:
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
Begin
Hello World
Hello World
Hello World
End 


When instead pressing "Debug" i get to the Debug view, but can only get to until the first printf (whether i select "Step Over", "Step Into", or just "Continue"). Then the program enters a boot-loop:
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
Begin
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
Begin
*** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
Begin 

(and so on)

Similar behavior occurs in my actual programm (debugging crashes after first/first few lines), this simple Hello World programm is just for demonstration purposes.
(This is SDK v2.6.1 with a nRF9161.)

How might this be fixed?

Parents
  • Hi,

    It is common to see this kind of crash when you debug with time sensitive functions like BLE/Cellular IoT communication, but what you have seen for this hello world sample is unusual.

    I did a test with your codes on my setup, and I can successfully run it without crash. Just share my whole project here, could you test the following project and build for nrf9161dk_nrf9161_ns?

    hello_world_debug.zip

    Best regards,

    Charlie

  • Thanks for your reply.

    I still have the same problem when running the uploaded project.
    (I decompressed the zip and opened it using Open Folder. For debugging i built it for "nrf9161dk_nrf9161_ns" with "Optimize for debugging (-Og)" as Optimization level.)
    (For some projects debugging works somewhat (for many lines, but not until the end) when additionally adding the compiler-flags in the CMakeLists.txt, but that doesn't seem to make a difference for this project.)

    The serial terminal (when debugging the zipped project past first line) reads

    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Begin
    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Begin
    *** Booting nRF Connect SDK v3.5.99-ncs1-1 ***
    Begin 


  • Hi,

    I can repeated this issue if enable Optimize for debugging "-Og" option for building firmware then start Debug and run step over.

    The device will keep rebooting with following fatal error from TF-M debugging port.

    [Sec Thread] Secure image initializing!
    Booting TF-M v2.0.0
    [DBG][Crypto] Initialising Mbed TLS 3.5.2 as PSA Crypto backend library... complete.
    FATAL ERROR: Reserved Exception 0x0000000C
    [Sec Thread] Secure image initializing!
    Booting TF-M v2.0.0
    [DBG][Crypto] Initialising Mbed TLS 3.5.2 as PSA Crypto backend library... complete.
    FATAL ERROR: Reserved Exception 0x0000000C

    I have reported this error to our TF-M experts to see if this is a bug or not and will give you an update later.

    Best regards,

    Charlie

Reply
  • Hi,

    I can repeated this issue if enable Optimize for debugging "-Og" option for building firmware then start Debug and run step over.

    The device will keep rebooting with following fatal error from TF-M debugging port.

    [Sec Thread] Secure image initializing!
    Booting TF-M v2.0.0
    [DBG][Crypto] Initialising Mbed TLS 3.5.2 as PSA Crypto backend library... complete.
    FATAL ERROR: Reserved Exception 0x0000000C
    [Sec Thread] Secure image initializing!
    Booting TF-M v2.0.0
    [DBG][Crypto] Initialising Mbed TLS 3.5.2 as PSA Crypto backend library... complete.
    FATAL ERROR: Reserved Exception 0x0000000C

    I have reported this error to our TF-M experts to see if this is a bug or not and will give you an update later.

    Best regards,

    Charlie

Children
Related