'NRF_RTC2' undeclared

Hello,

I am trying to port a project from the NRF52840 DK to a custom board where I am using the NRF52820. The code compiles fine when the project is using the settings for NRF52840 but when I adjust the settings under 'Code generation' to match that of the NRF82820 it complains that NRF_RTC2 is undeclared which it first comes across in nrfx_rtc.h at:

#define NRFX_RTC_INSTANCE(id)                                   \
{                                                               \
    .p_reg            = NRFX_CONCAT_2(NRF_RTC, id),             \
    .irq              = NRFX_CONCAT_3(RTC, id, _IRQn),          \
    .instance_id      = NRFX_CONCAT_3(NRFX_RTC, id, _INST_IDX), \
    .cc_channel_count = NRF_RTC_CC_CHANNEL_COUNT(id),           \
}

I suspect this has to do with the fact that NRF52840 has three real time counters while 52820 only has two, but I don't understand how I can work around this problem. I am not enabling RTC2 in the config file. Any ideas? Thank you.

  • Hi,

    I suspect this has to do with the fact that NRF52840 has three real time counters while 52820 only has two

    Yes, that would be the correct assumption. 

    but I don't understand how I can work around this problem. I am not enabling RTC2 in the config file. Any ideas?

    It looks like NRFX_RTC_INSTANCE() (or NRF_DRV_RTC_INSTANCE()) is called with 2 as the argument somewhere in your project. Please check if you can find any reference to one of these macros. This macro is defined in the header file, which is included regardless of the RTC instance being enabled in your sdk_config.h file or not.

    Best regards,
    Jørgen

  • Hi Jorgen,

    Like you suggested, a file that I am not using anymore was calling that function with 2 as the argument. Thanks!

    Now I am however getting the error "multiple definitions of `RTC1_IRQHandler'". Why does this happen? 

    #if NRFX_CHECK(NRFX_RTC1_ENABLED)
    void nrfx_rtc_1_irq_handler(void)
    {
        irq_handler(NRF_RTC1, NRFX_RTC1_INST_IDX, NRF_RTC_CC_CHANNEL_COUNT(1));
    }
    #endif

    I read somewhere that the RTC0 is used by the softdevice and that RTC1 is used by the app_timer library (which I use in the project) - how to find out which other library is trying to use RTC1? 

  • oskarbjo said:
    Now I am however getting the error "multiple definitions of `RTC1_IRQHandler'". Why does this happen? 

    Multiple files can't define a function with the same name, as the application then does not know which of the function implementations should be called.

    oskarbjo said:
    I read somewhere that the RTC0 is used by the softdevice and that RTC1 is used by the app_timer library (which I use in the project)

    That is correct.

    oskarbjo said:
    how to find out which other library is trying to use RTC1? 

    The compiler will normally tell you which two files defines the function. If not, you just needs to search your project for references to RTC1_IRQHandler.

  • Segger EMStudio only appears to show me where the first definition occurs - is there any way to see where the other definitions are?

    After looking around a bit I have the impression that the problem might be linked to the use of the UART used for the log backend or alternatively to using an SPI library - do these services rely on the RTC as well? 

  • Part of the error message should give you hints to where the multiple definitions are originating from, e.g.:

    Here main.c and nrfx_rtc.c holds the definition.

    You can also press "Ctrl+Shift+F" in SES to search the entire project for text.

    oskarbjo said:
    I have the impression that the problem might be linked to the use of the UART used for the log backend

    I can't think of anything UART logging backend related that will use RTC. The closest would be the libUARTE async library, with RTC used for timeouts. This can be used for the CLI library, which can be used as a backend for the logger module.

    oskarbjo said:
    or alternatively to using an SPI library

    I'm not aware of any SPI library that uses the RTC. Most libreries in the SDK that requires RTC will use it through the app_timer library.

Related