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

Pure NRFX RTC code - how to?

Hi,

I'm trying to adopt my nRF52832 projects to the nRF5 SDK version 15.2.0 and the NRFX drivers framework. I'm using a short app_config.h with NRFX_RTC_ENABLED and NRFX_RTC0_ENABLED only. Unfortunately, it won't work because it's locked on the legacy stuff from the integration/nrfx/legacy/apply_old_config.h. Particularly, the following chunk of defs in the apply_old_config.h are enforced to redefine my NRFX_RTC0_ENABLED because sdk_config.h has the default RTC_ENABLED value (defined as 0):

#if defined(RTC_ENABLED)

#undef NRFX_RTC_ENABLED
#define NRFX_RTC_ENABLED  RTC_ENABLED

#if defined(RTC0_ENABLED)
#undef NRFX_RTC0_ENABLED
#define NRFX_RTC0_ENABLED  RTC0_ENABLED
...

What would be the recommended way to enable the pure NRFX RTC without legacy code involved?

Thanks!

  • Okay, here are more details on what happens:

    Compiling file: sys_rtc.c
    In file included from /Users/mishka/my/l.a.b./src/sdk/modules/nrfx/nrfx.h:45:0,
                     from /Users/mishka/my/l.a.b./src/sdk/modules/nrfx/drivers/include/nrfx_rtc.h:44,
                     from sys_rtc.c:2:
    /Users/mishka/my/l.a.b./src/sdk/modules/nrfx/drivers/include/nrfx_rtc.h:86:39: error: 'NRFX_RTC0_INST_IDX' undeclared here (not in a function)
         .instance_id      = NRFX_CONCAT_3(NRFX_RTC, id, _INST_IDX), \
                                           ^
    /Users/mishka/my/l.a.b./src/sdk/modules/nrfx/drivers/nrfx_common.h:117:37: note: in definition of macro 'NRFX_CONCAT_3_'
     #define NRFX_CONCAT_3_(p1, p2, p3)  p1 ## p2 ## p3
                                         ^~
    /Users/mishka/my/l.a.b./src/sdk/modules/nrfx/drivers/include/nrfx_rtc.h:86:25: note: in expansion of macro 'NRFX_CONCAT_3'
         .instance_id      = NRFX_CONCAT_3(NRFX_RTC, id, _INST_IDX), \
                             ^~~~~~~~~~~~~
    sys_rtc.c:9:24: note: in expansion of macro 'NRFX_RTC_INSTANCE'
     const nrfx_rtc_t rtc = NRFX_RTC_INSTANCE(0);
                            ^~~~~~~~~~~~~~~~~
    make: *** [obj/dhrystone/sys_rtc.c.o] Error 1
    

    The NRFX_RTC_INSTANCE macro refers to NRFX_RTC0_INST_IDX which should be "initialized" by the enum in the modules/nrfx/drivers/include/nrfx_rtc.h (see below), but it fails to do so because the NRFX_RTC0_ENABLED will always be reset to 0 due to the integration/nrfx/legacy/apply_old_config.h defs (please see the originating post).

    enum {
    #if NRFX_CHECK(NRFX_RTC0_ENABLED)
        NRFX_RTC0_INST_IDX,
    #endif
    #if NRFX_CHECK(NRFX_RTC1_ENABLED)
        NRFX_RTC1_INST_IDX,
    #endif
    #if NRFX_CHECK(NRFX_RTC2_ENABLED)
        NRFX_RTC2_INST_IDX,
    #endif
        NRFX_RTC_ENABLED_COUNT
    };

    Perhaps the SDK should not always include legacy defs, but rather make it optional.

  • Hi,

    I would recommend that you completely remove the legacy RTC config from sdk_config.h if switching to NRFX drivers. 

    Alternatively, you can also make modify apply_old_config.h by only overwriting the settings if the legacy drivers was enabled:

    #if defined(RTC_ENABLED) && (RTC_ENABLED == 1)
    
    #undef NRFX_RTC_ENABLED
    #define NRFX_RTC_ENABLED  RTC_ENABLED

    Best regards,
    Jørgen

  • Hi Jørgen,

    thanks for your reply! I'm using standard unmodified SDK 15.2 config from the config/nrf52832/config/sdk_config.h. All overrides are going into a local app_config.h (-DUSE_APP_CONFIG) - it allows me to keep my codebase clean and portable, and don't bother about changes in the SDK (for example when upgrading it). Therefore there is no legacy configs - only the new shiny NRFX defs.

    Your patch will definitely do its job. Of course I can walk through the apply_old_config.h and patch all definitions. Or is it better to eliminate old definitions with something like this:

    #if defined(NRF_DEV_LEGACY_COMPAT) && (NRF_DEV_LEGACY_COMPAT==1)
    #include <legacy/apply_old_config.h>
    #endif

    In any case hope to see it addressed in the next SDK release :-)

    Thanks!

  • Yes, that is also an alternative if you do not use legacy drivers for any peripherals.

  • Uhm, libraries are still dependent on nrf_drv_* stuff. Patched the apply_old_config.h as you've suggested above:

    sed -E 's/^(#if defined\(([A-Z_0-9]+_ENABLED)\))/\1 \&\& (\2 == 1)/' integration/nrfx/legacy/apply_old_config.h

    Thanks!

Related