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?

  • 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...

  • Yes I think this is the reason. If I run "mon reset" in gdb and then continue, I hit the breakpoint. Can I get JLinkGDBServer to do this when running?

  • Maybe you can try to append --noir ("Do not initialize the CPU registers on startup.") to the list of GDB server argument to see if that helps. 

Related