Debugging using QtCreator on Mac

This post started as a question, but got the suggestion to post this as a blog post. Here it is.

I have been trying to get QtCreator configured such that I can use it as my IDE for the nrf51822 on Mac OSX. I use the NRF51DK as hardware, but also had it working using my own board and a Jlink Lite.

As a starting point I have been reading this post: https://devzone.nordicsemi.com/questi...

Here's what I did in a nutshell:

  1. Installed latest version ofQtCreator (3.4.1) image description
  2. Enabled the Baremetal plugin and restarted QtCreator image description
  3. Configured the bare metal plugin (in preferences->baremetal) to point to the right gdb server on port 2331 (the default port on the jlink gdb server): Add>default, renamed it to Jlink GDB server, and added necessary commands for programming (load) and resetting, and also for redirecting stderr and stdout to the gdb terminal port - these commands will make sure that the software is uploaded to the flash before debugging image description
  4. Added a bare metal device (in preferences->Devices) and named it nrf51822, pointed to the gdb server provider added in previous step image description
  5. Added the compiler - installed the arm gcc toolchain ( https://launchpad.net/gcc-arm-embedded) and point to it in preferences>build&run>compilers: Add>GCC, renamed to ARM GCC, pointed compiler path to the arm-none-eabi-gcc executable, left everything else as default image description
  6. Added debugger (preferences>build&run>Debuggers), renamed it to gdb, pointed to executable arm-none-eabi-gdb-py image description
  7. Added a kit (preferences>build&run>kits), named it nrf51822 also, selected device type Bare Metal Device, selected the Device made in step 4, idem for Compiler (step 5) and Debugger (step6), left Sysroot empty, set Qt version to none, left Qt mkspec empty image description
  8. Changed default projects directory and default build director in preferences>build&run>General, the latter because I do not like the default location for the build files, but this is not really necessary, just personal preference image description
  9. Saved the content of the QBS file as found in answer of question in above mentioned link (https://devzone.nordicsemi.com/questi...) in myproject.qbs and opened that file in QtCreator
  10. In the projects view: add kit - nrf51822, and removed the default desktop kit which was created on opening of the qbs file image description
  11. Adapted the qbs file to my project's content
  12. Built my project
  13. From that I got a build error on Mac OSX. Apparently when compiling using a gcc based toolchain on MacOSX, it adds a build step automatically called dsymutil. Up till now I found no way to solve this other then this trick: copied /usr/bin/dsymutil to arm-gcc-none-eabi-dsymutil in the arm gcc bin directory (same directory as the xxx-gcc an xxx-gdb-py). Compilation goes fine then.
  14. Debug: I installed the jlink tools from segger and started the gdb server from a terminal window, using command JLinkGDBServer -device nrf51822 -if swd -speed 4000. GDB server then starts on localhost port 2331. Then add breakpoints and start debugging (with the green 'play' button) in Qt Creator. Joehoe! :-)

One note: in the qbs script, the output file has extension .out. In fact this an .elf file.

Addition: I used to do printf to a UART port, but got a tip (thanks mmulder) that this can also be redirected to the jlink interface. Here's what I needed to do for that:

  1. Added some commands in the bare metal gdb configuration: image description

  2. Add following to the linker options in the qbs script:

    "--specs=rdimon.specs"

  3. Then I got a compile error, still not sure why: image description

  4. Solved my compilation problem, by defining a new compiler (see step 5 above), not pointing to gcc but to g++, everything else the same, image description and switch to that compiler in the kit definition image description With g++, compilation went fine.

To get the stdout, connect a telnet session to port 2333 after starting gdb.

Anonymous