5 years, 2 months ago.

Debugging NRF52 in Visual Studio Code results in segmentation fault

Debugging results with a segmentation fault on the nrf52840. Execution does not even reach Main. Not sure what about my configuration has changed to cause this. I can flash the board in regular run mode, and it seems to run as expected. I can connect to the board via BLE in nRF Connect on Android and see characteristics output data.

My setup: nrf52840 on Makerdiary MDK board mbed os 5 Visual Studio Code on Mac High Sierra C/CPP 0.25.0 plugin Cortex Debug 0.3.1 plugin

After clicking on debug and having the firmware load to memory, I get this in the debugging console:

1: (19989) <-1015-thread-info 1: (20019) ->1015^done,threads=[{id="1",target-id="Thread 1",frame={level="0",addr="0x0004d628",func="Reset_Handler",args=[],file="./mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/startup_NRF52840.S",fullname="/Users/ben/nrf52840-mdk/examples/mbedos5/pool/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/startup_NRF52840.S",line="141",arch="armv7e-m"},state="stopped"}],current-thread-id="1" 1: (20020) ->(gdb) 1: (20020) 1015: elapsed time 30 1: (20031) <-1016-stack-list-frames 0 1000 1: (20032) ->1016^done,stack=[frame={level="0",addr="0x0004d628",func="Reset_Handler",file="./mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/startup_NRF52840.S",fullname="/Users/ben/nrf52840-mdk/examples/mbedos5/pool/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/device/TOOLCHAIN_GCC_ARM/startup_NRF52840.S",line="141",arch="armv7e-m"}] 1: (20032) ->(gdb) 1: (20033) 1016: elapsed time 2 1: (20037) Send Event AD7ProcessInfoUpdatedEvent 1: (20037) Send Event AD7ThreadCreateEvent 1: (20045) <--exec-continue 1: (20046) ->^running 1: (20046) ->*running,thread-id="all" 1: (20055) ->(gdb) <-- C (threads-7): {"command":"threads","type":"request","seq":7} 1: (20246) ->=thread-created,id="2",group-id="i1" 1: (20246) ->"[New Thread 2]\n" 1: (20247) <-1017-thread-info 2 [New Thread 2] 1: (20278) ->=thread-exited,id="1",group-id="i1" 1: (20279) ->=thread-created,id="3",group-id="i1" 1: (20279) ->"[New Thread 536902832]\n" 1: (20279) ->=thread-created,id="4",group-id="i1" 1: (20279) ->"[New Thread 536905524]\n" 1: (20279) ->=thread-created,id="5",group-id="i1" 1: (20279) ->"[New Thread 536902900]\n" 1: (20280) ->"\nThread " 1: (20280) ->"2 \"Handler mode\" received signal SIGSEGV, Segmentation fault.\n" 1: (20280) ->"[Switching to Thread 2]\n" 1: (20281) Send Event AD7ThreadDestroyEvent 1: (20282) <-1018-thread-info 3 [New Thread 536902832] 1: (20282) <-1019-thread-info 4 [New Thread 536905524] 1: (20283) <-1020-thread-info 5 [New Thread 536902900] Thread 2 "Handler mode" received signal SIGSEGV, Segmentation fault. [Switching to Thread 2] 1: (20389) ->"0x000008c4 in ?? ()\n" 0x000008c4 in ?? () 1: (20390) ->*stopped,reason="signal-received",signal-name="SIGSEGV",signal-meaning="Segmentation fault",frame={addr="0x000008c4",func="??",args=[],arch="armv7e-m"},thread-id="2",stopped-threads="all"

Any help is very appreciated! I cannot be the only one having this issue.

Enclosing the launch.json config file in case it is relevant. My launch.json was generated with the mbed-vscode-generator tool.

{ "version": "0.2.0", "configurations": [ { "name": "Debug Mbed", "type": "cppdbg", "request": "launch", "program": "/Users/ben/nrf52840-mdk/examples/mbedos5/app/BUILD/NRF52840_MDK/GCC_ARM-DEBUG/application.elf", "args": [], "stopAtEntry": false, "cwd": "/Users/ben/nrf52840-mdk/examples/mbedos5/app", "environment": [], "externalConsole": false, "debugServerArgs": "", "serverLaunchTimeout": 20000, "filterStderr": true, "filterStdout": false, "serverStarted": "GDB
server
started", "preLaunchTask": "Build Mbed OS application", "setupCommands": [ { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false }, { "text": "-file-exec-and-symbols /Users/ben/nrf52840-mdk/examples/mbedos5/app/BUILD/NRF52840_MDK/GCC_ARM-DEBUG/application.elf", "description": "load file", "ignoreFailures": false }, { "text": "-interpreter-exec console \"monitor reset\"", "description": "none", "ignoreFailures": false }, { "text": "-interpreter-exec console \"monitor halt\"", "description": "none", "ignoreFailures": false }, { "text": "-target-download", "description": "flash target", "ignoreFailures": false } ], "logging": { "moduleLoad": true, "trace": true, "engineLogging": true, "programOutput": true, "exceptions": true }, "linux": { "MIMode": "gdb", "MIDebuggerPath": "/Users/ben/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gdb", "debugServerPath": "/usr/local/bin/pyocd-gdbserver" }, "osx": { "MIMode": "gdb", "MIDebuggerPath": "/Users/ben/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gdb", "debugServerPath": "/usr/local/bin/pyocd-gdbserver" }, "windows": { "MIMode": "gdb", "MIDebuggerPath": "/Users/ben/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gdb", "debugServerPath": "/usr/local/bin/pyocd-gdbserver", "setupCommands": [ { "text": "-environment-cd /Users/ben/nrf52840-mdk/examples/mbedos5/app/BUILD/NRF52840_MDK/GCC_ARM-DEBUG", "description": "adsf" }, { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false }, { "text": "-file-exec-and-symbols application.elf", "description": "load file", "ignoreFailures": false }, { "text": "-interpreter-exec console \"monitor reset\"", "description": "asdf", "ignoreFailures": false }, { "text": "-interpreter-exec console \"monitor halt\"", "description": "asdf", "ignoreFailures": false }, { "text": "-target-download", "description": "flash target", "ignoreFailures": false } ] } } ] }

I am having the same issue with the Nordic NRF52 Development Kit ( nRF52832, nRF52810) and a different debugger version (GNU Tools ARM Embedded\6 2017-q2-update\bin\arm-none-eabi-gdb.exe).

I set up vs code for mbed following the instructions on mBed and set up my local debug toolchain.

I can build, flash and run my application but once I start a debugging session I receive a segmentation fault before entering main.

Have you found a solution yet? Any help is appreciated.

posted by Anna K 06 Sep 2019

Same problem on a Seedstudio ARCH_MAX, code runs ok but starting debug gives me segamentation fault on 'gpio_write' before main.

posted by Ibiltari Nora 10 Oct 2019

1 Answer

5 years, 1 month ago.

Same problem on a Seedstudio ARCH_MAX, code runs ok but starting debug gives me segamentation fault on 'gpio_write' before main.