This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using IAR, nRF52810, and C++

I am trying to get a project working with a main.cpp file, some C++ modules, and the 16.0.0 SDK using the IAR compiler. However, using the nrfx/mdk startup files, it never actually reaches my main function, instead hanging before it even reaches it. If I debug before main, I see that it seems to jump to a very random spot when loading __iar_program_start. I used the provided linker file (from the SDK, not from IAR).

Does anyone know what I need to do to get my main.cpp::main file linked in as the main file? IAR has an 8 year old example, but it doesn't do anything with SDKs or the like and they have a C++ startup file, but it's seems to assume pure C++ instead of a mix.

Parents
  • So I'm gonna answer my own question. Big thanks to for pointing me in the direction he went.

    Basically, you have to define your own startup file because you need to make sure the interrupts are provided with C linkage (so they need 'extern "C"' prefixed before the forward declarations. If you do this you can also overwrite any of the handlers you want with a class and static member functions if you so desire.

    The starting point I used is here:

    https://www.iar.com/support/tech-notes/compiler/cortex-m-interrupt-vector-in-c-ewarm-6.21/

    I also used the latest (as of posting) CMSIS v5.6.0 compiler abstraction macros to make things more portable. They define things like __PROGRAM_START and __VECTOR_TABLE so you can write one startup file and use it for any compiler (in theory).

    Overall a bit of a pain, but hopefully this helps people so they don't have to go through this hunting.

  • Well, the library I pointed to you have done all that for you already.  The only thing you need to do is replace the Vector_xxx.c for the 810, only the vector table and the linker script with correct memory size. 

  • It was, but I wanted to be able to define some interrupt handlers in C++, so I just went down the full CPP startup file route.

Reply Children