nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Building C library with GCC, targeting nRF52832

Hello,

I have a pure-C library that I'd like to build, and then import into another project that targets the nRF52832 (nRF5 SDK v16.0.0).  The library has no dependencies on nRF5 SDK, meaning the code does not #include any files from the nRF5 SDK.  This library ends up being linked with a nRF5 SDK v16.0.0 project that is currently being built with SEGGER Embedded Studio.

Previously, I created a library project in SES and copied the source code files for the library into the project and built the project with SES.  That has been working, but now I'm wanting to build the library source code using CMake so I can target multiple platforms with ease, and not have to depend on SES.  I captured the build output from SES and was able to get a CMake project configured to build the library successfully, and my nRF5 SDK project successfully builds as well.

One thing I noticed is the SES library project uses gcc flag to use SEGGER standard C include files instead of gcc standard C, as well as some SES specific preprocessor definitions that end up affecting what gets included during the build:

-nostdinc "-isystemC:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 5.68/include"
-D__SIZEOF_WCHAR_T=4
-D__ARM_ARCH_7EM__
-D__SES_ARM
-D__ARM_ARCH_FPV4_SP_D16__
-D__SES_VERSION=54200
-D__GNU_LINKER

My question is, can I remove the SES-specific GCC flags from my CMake configuration and use purely GCC when compiling my library, or will this have ill effects? A specific example I can think of is, will it affect printf, in that if my library calls printf within the source code, and I debug my nRF5 SDK project via SES IDE, will the printf statements from my library source code print to the SES output window/debug terminal?

On a different note, for what it's worth, the output file size of the library when building with different configurations:

SEGGER Embedded Studio: 499KB
CMake with ARM Embedded Toolchain GCC, using same SES compiler flags (and SES stdc includes): 1245KB
CMake with ARM Embedded Toolchain GCC, removing SES-specific compiler flags: 2693KB

When I take the built library and then import it into my nRF5 SDK project, the output files for the target device is 345KB, 346KB, 346KB respectively (referencing library file build output size).  The file sizes are pretty drastic, so I'm not sure how confident I can be that everything is going to work properly if I remove SES specific build configuration flags when building my library.  Any advice?

  • Hi,

    I recommend referring to SES documentation for details about what these options control. Most of them are clearly SES specific though, and do not require a counterpart when you build your library with GCC. There are some things to consider when building libraries for different toolchains and ICs, though. Most importantly, toolchains have different wchar lengths. So for IAR 7 for instance, the wchar length is 2 bytes whereas for GCC and SES and IAR, it is 4. Also, you may want to enable hardware floating point for devices that use that.

    I suggest you refer to the Makefiles for different ICs and toolchains for micro-ecc, which lets you see how this can be done (<nRF5 SDK>/external/micro-ecc/).

Related