This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SIGTRAP on sd_softdevice_enable

I'm compiling a custom application using the CMake scripts in the nRF mesh SDK. The first time I flash to the nRF52832 a SIGTRAP occurs on sd_softdevice_enable. I cannot continue from this. If I flash again, it does not occur. Any idea what might be happening, or how I can prevent this?

See also related issue https://devzone.nordicsemi.com/f/nordic-q-a/50709/breakpoints-not-being-hit

I'm wondering if when this SIGTRAP occurs, it is because the softdevice is missing, but breakpoints work because the breakpoint address is being set relative to flash start. When the softdevice is present the SIGTRAP does not occur but breakpoints do not work because they are still relative to flash start not to application start, so land somewhere in the softdevice.

So if I'm correct, that leads to two questions: Why is the softdevice not being written on first flash, and how do I offset breakpoints by the softdevice length?

Parents
  • Hi,

    The Softdevice must be programmed at least partially for the program execution to reach the main app. I remember seeing similar issues before with Segger embedded Studio where a fault exception gets triggered on sd_ enable, but then it has been related to debugger configuration. Maybe you can try to just reset the device instead of flashing it again, then read out the CPU registers to see if the fault also gets triggered when you're not debugging with GDB. 

    The "nrfjprog --readregs" command will read out the CPU registers where the last byte of xPSR will tell you the current interrupt number (=3 if hardfault =0 if none).  

  • This also happens in Ozone:

    When in this state, running the command gives:

     

    $ nrfjprog --readregs
    R0:   0x00000010
    R1:   0x2000FFB0
    R2:   0xA801BE2C
    R3:   0xA801BE00
    R4:   0x2000445C
    R5:   0x00000000
    R6:   0x00000000
    R7:   0x00000000
    R8:   0x00000000
    R9:   0x00000000
    R10:  0x20000000
    R11:  0x00000000
    R12:  0x00000000
    SP:   0x2000FF90
    LR:   0xFFFFFFF1
    PC:   0x00000A64
    xPSR: 0x81000003
    MSP:  0x2000FF90
    PSP:  0x00000000

    Resetting and running again:

    $ nrfjprog --reset
    Applying system reset.
    Run.
    $ nrfjprog --readregs
    R0:   0x00000000
    R1:   0x00000001
    R2:   0x00000000
    R3:   0x01010001
    R4:   0x00004001
    R5:   0x2000FFC8
    R6:   0x00027D7D
    R7:   0x00040001
    R8:   0x00000004
    R9:   0x00000000
    R10:  0x20000000
    R11:  0x00000000
    R12:  0x00000000
    SP:   0x2000FFA0
    LR:   0x0002EBE5
    PC:   0x00029D14
    xPSR: 0x21000000
    MSP:  0x2000FFA0
    PSP:  0x00000000

    Does this mean the hardfault is not occurring when running without the debugger?

  • I was able to replicate this here. Ozone use debugger commands to manually set the SP and PC register with the values from the application's vector table. This breaks the normal startup sequence and the Softdevice's reset handler will not get executed.

    Please try to comment out the declaration of AfterTargetReset() and AfterTargetDownload() in your ozone project file (*.jdebug). That should fix the problem. 

  • Yes! That worked. Is there a similar solution for GDB?

  • I haven't had this problem with GDB. Are there some GDB scripts included in the Mesh SDK? 

    How I usually start a debug session with GDB without .gdbinit:

    1. Start the Jlink GDB server

    2. Open a new terminal and run "arm-none-eabi-gdb <app>.elf

    (gdb) target remote localhost:2331

    (gdb) b main

    (gdb) c

  • Ah, turns out the default in CLion 2019.2 uses JLinkGDBServer to download the firmware image when changes are made, and it seems to set the PC register after doing that:

    /usr/local/bin/JLinkGDBServer -device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little
    SEGGER J-Link GDB Server V6.44h Command Line Version
    
    JLinkARM.dll V6.44h (DLL compiled May  3 2019 17:40:32)
    
    Command line: -device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little
    -----GDB Server start settings-----
    GDBInit file:                  none
    GDB Server Listening port:     2331
    SWO raw output listening port: 2332
    Terminal I/O port:             2333
    Accept remote connection:      yes
    Generate logfile:              off
    Verify download:               off
    Init regs on start:            off
    Silent mode:                   off
    Single run mode:               off
    Target connection timeout:     0 ms
    ------J-Link related settings------
    J-Link Host interface:         USB
    J-Link script:                 none
    J-Link settings file:          none
    ------Target related settings------
    Target device:                 nrf52
    Target interface:              SWD
    Target interface speed:        1000kHz
    Target endian:                 little
    
    Connecting to J-Link...
    J-Link is connected.
    Error during pretty printers setup: Undefined info command: "pretty-printer".  Try "help info".
    
    Some features and performance optimizations will not be available.
    
    Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan  7 2019 14:07:15
    Hardware: V1.00
    S/N: 682644303
    Checking target voltage...
    Target voltage: 3.30 V
    Listening on TCP/IP port 2331
    Connecting to target...Connected to target
    Waiting for GDB connection...Connected to 127.0.0.1
    Reading all registers
    Reading 64 bytes @ address 0x00029CC0
    Read 2 bytes @ address 0x00029D4A (Data = 0x481A)
    Reading 64 bytes @ address 0x00027D40
    Read 2 bytes @ address 0x00027D98 (Data = 0x4A39)
    Read 4 bytes @ address 0x00029D38 (Data = 0x462ABE00)
    Reading 64 bytes @ address 0x2000FFC0
    Read 4 bytes @ address 0x00029A22 (Data = 0xBD00B003)
    Downloading 16144 bytes @ address 0x00026000
    Downloading 15968 bytes @ address 0x00029F10
    Downloading 16016 bytes @ address 0x0002DD70
    Downloading 16016 bytes @ address 0x00031C00
    Downloading 16080 bytes @ address 0x00035A90
    Downloading 16080 bytes @ address 0x00039960
    Downloading 15936 bytes @ address 0x0003D830
    Downloading 16096 bytes @ address 0x00041670
    Downloading 16336 bytes @ address 0x00045550
    Downloading 16352 bytes @ address 0x00049520
    Downloading 2580 bytes @ address 0x0004D500
    Downloading 104 bytes @ address 0x0004DF14
    Downloading 16 bytes @ address 0x0004DF7C
    Downloading 8 bytes @ address 0x0004DF8C
    Downloading 8 bytes @ address 0x0004DF94
    Downloading 16 bytes @ address 0x0004DF9C
    Downloading 184 bytes @ address 0x0004DFAC
    Downloading 20 bytes @ address 0x0004E064
    Downloading 16 bytes @ address 0x0004E078
    Downloading 8 bytes @ address 0x0004E088
    Downloading 2132 bytes @ address 0x0004E090
    Downloading 20 bytes @ address 0x0004E8E4
    Comparing flash   [....................] Done.
    Verifying flash   [....................] Done.
    Writing register (PC = 0x   298ec)
    Reading 64 bytes @ address 0x00029CC0
    Read 2 bytes @ address 0x00029D4A (Data = 0x481A)
    Reading 64 bytes @ address 0x00027D40
    Read 2 bytes @ address 0x00027D98 (Data = 0x4A39)
    Debugger connected to tcp:localhost:2331
    Setting breakpoint @ address 0x00027D98, Size = 2, BPHandle = 0x0001
    Setting breakpoint @ address 0x00029D4A, Size = 2, BPHandle = 0x0002
    Starting target CPU...
    ...Target halted (DBGRQ, PC = 0x00000A64)
    Reading all registers
    Removing breakpoint @ address 0x00027D98, Size = 2
    Removing breakpoint @ address 0x00029D4A, Size = 2
    Read 4 bytes @ address 0x00000A64 (Data = 0x471868DB)
    Read 2 bytes @ address 0x00000A64 (Data = 0x68DB)
    Signal: SIGTRAP (Trace/breakpoint trap)
    Reading 64 bytes @ address 0x00000A40
    Read 4 bytes @ address 0x2000FFCC (Data = 0x61000000)
    Reading 64 bytes @ address 0x2000FFC0
    Read 4 bytes @ address 0x0002A1FA (Data = 0xDF114770)
    Read 4 bytes @ address 0x0002A310 (Data = 0xFAB04604)
    Read 4 bytes @ address 0x000276D4 (Data = 0x2300B968)
    Read 4 bytes @ address 0x0002831E (Data = 0xFC07F7FE)
    Read 4 bytes @ address 0x000262EA (Data = 0xBD082000)
    Read 4 bytes @ address 0x0002628E (Data = 0xFF05F01D)
    Reading 64 bytes @ address 0x00026240
    Read 4 bytes @ address 0x00026298 (Data = 0x20010000)
    Read 4 bytes @ address 0x00026296 (Data = 0x00000008)
    Read 4 bytes @ address 0x000262A4 (Data = 0x20003B58)
    Read 4 bytes @ address 0x000262AA (Data = 0x00002000)
    Reading 64 bytes @ address 0x2000FF80
    Reading 64 bytes @ address 0x0002A1C0

    So now after disabling that (because I'm using the CMake flash_ target to write the firmware) it doesn't happen. However, breakpoints I set are not being hit:

    /usr/local/bin/JLinkGDBServer -device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little
    SEGGER J-Link GDB Server V6.44h Command Line Version
    
    JLinkARM.dll V6.44h (DLL compiled May  3 2019 17:40:32)
    
    Command line: -device nrf52 -strict -timeout 0 -nogui -if swd -speed 1000 -endian little
    -----GDB Server start settings-----
    GDBInit file:                  none
    GDB Server Listening port:     2331
    SWO raw output listening port: 2332
    Terminal I/O port:             2333
    Accept remote connection:      yes
    Generate logfile:              off
    Verify download:               off
    Init regs on start:            off
    Silent mode:                   off
    Single run mode:               off
    Target connection timeout:     0 ms
    ------J-Link related settings------
    J-Link Host interface:         USB
    J-Link script:                 none
    J-Link settings file:          none
    ------Target related settings------
    Target device:                 nrf52
    Target interface:              SWD
    Target interface speed:        1000kHz
    Target endian:                 little
    
    Connecting to J-Link...
    J-Link is connected.
    Error during pretty printers setup: Undefined info command: "pretty-printer".  Try "help info".
    
    Some features and performance optimizations will not be available.
    
    Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Jan  7 2019 14:07:15
    Hardware: V1.00
    S/N: 682644303
    Checking target voltage...
    Target voltage: 3.30 V
    Listening on TCP/IP port 2331
    Connecting to target...Connected to target
    Waiting for GDB connection...Connected to 127.0.0.1
    Reading all registers
    Reading 64 bytes @ address 0x00027D40
    Read 2 bytes @ address 0x00027D98 (Data = 0x4A39)
    Read 4 bytes @ address 0x00029D38 (Data = 0x462ABE00)
    Reading 64 bytes @ address 0x2000FFC0
    Read 4 bytes @ address 0x00029A22 (Data = 0xBD00B003)
    Debugger connected to tcp:localhost:2331
    Setting breakpoint @ address 0x00027D98, Size = 2, BPHandle = 0x0001
    Starting target CPU...
    Reading all registers
    Removing breakpoint @ address 0x00027D98, Size = 2
    Read 4 bytes @ address 0x00029D38 (Data = 0x462ABE00)
    Reading 64 bytes @ address 0x2000FFC0
    Read 4 bytes @ address 0x00029A22 (Data = 0xBD00B003)
    Signal: SIGTRAP (Trace/breakpoint trap)
    Read 4 bytes @ address 0x00029A22 (Data = 0xBD00B003)
    Reading 64 bytes @ address 0x00029CC0

    Here a breakpoint is set at a point before a SIGTRAP occurs, but it is not hit. Do you have any suggestions?

  • Perhaps it is because JLinkGDBServer is not actually resetting the target so the SIGTRAP has already occurred...And breakpoints do work when JLinkGDBServer downloads the firmware image, until the SIGTRAP in the softdevice enable. So if correct, either I need to make JLinkGDBServer reset the target or I use JLinkGDBServer to download the image but somehow prevent it setting the PC register...

Reply
  • Perhaps it is because JLinkGDBServer is not actually resetting the target so the SIGTRAP has already occurred...And breakpoints do work when JLinkGDBServer downloads the firmware image, until the SIGTRAP in the softdevice enable. So if correct, either I need to make JLinkGDBServer reset the target or I use JLinkGDBServer to download the image but somehow prevent it setting the PC register...

Children
Related