Using Nordic's SDKs with the GNU G++ Compiler

A persistant problem that people using the C++ compiler from the "GNU Tools for ARM Embedded Processors" toolchain has been the way that G++ handles the inline-assembly for the SVC instruction.

Specifically, you get an impossible constraint in 'asm' error when trying to use any softdevice header.

There have been a few questions about this here on the Nordic Developer Zone, here for example, with putative answers on StackOverflow.

However, myself and others have found that the "insert a cast" answer on StackOverflow does not work with the latest (4.9) G++ under the -Os optimization mode. Digging into the issue, it appears that different code generation and optimization options make it hit-and-miss with being able to use the GNU G++ compiler.

Note that often GCC will work even though G++ does not because the rules of type-inference for enumdiffer substantially between C and C++. For the current GNU compilers, even explicitly setting the type via enum : unsigned char { ... } does not work (and might be a compiler bug).

Therefore, I've created a tool on GitHub that automagically translates Nordic's enum header files into Keil-compatible #define constants.

Since I can't release the modified Nordic SDKs, I've opted to release the tool, enum2define.py and just the patch files under the MIT license.

Comments and suggestions (and better yet, patches) are gratefully accepted.

Parents
  • I got through all this and the application compiles and can be downloaded. BUT, when I use g++ to compile the application, the bootloader (compiled by gcc or Keil) starts and it appears that the application never gets to line 1 of main(). When I simply switch to gcc and add -std=gnu99, compile, download, it downloads, and the bootloader starts, and then vectors nicely to the app which runs.

    Why would simply changing gcc to g++ cause the app to not run? It compiles just fine (and yes, I did a few things to get compile success such as reorder some initializers and the stuff above). To be clear, the same exact code compiles fine on both g++, gcc, and Keil, but will not run when compiled by g++.

    BTW, I'm using the hrs_with_dfu example app.

Comment
  • I got through all this and the application compiles and can be downloaded. BUT, when I use g++ to compile the application, the bootloader (compiled by gcc or Keil) starts and it appears that the application never gets to line 1 of main(). When I simply switch to gcc and add -std=gnu99, compile, download, it downloads, and the bootloader starts, and then vectors nicely to the app which runs.

    Why would simply changing gcc to g++ cause the app to not run? It compiles just fine (and yes, I did a few things to get compile success such as reorder some initializers and the stuff above). To be clear, the same exact code compiles fine on both g++, gcc, and Keil, but will not run when compiled by g++.

    BTW, I'm using the hrs_with_dfu example app.

Children
No Data