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

The Openthread and TWI interface does not merge in GitHub openthread source OT-nRF52840.

Hello Team,

I am using the OT-nRF52840 source and working on the end device. I want to add the I2C(TWI) support in my end application, but as soon as I add any API it shows an error like the undefined reference to `nrfx_twi_init'. However, the TWI's driver is available in the source code. Can someone point me out how can I the driver file to my code? Please check below code snippet for more details:

Downloaded and using the code from https://github.com/openthread/ot-nrf528xx

I am using the file openthread/examples/apps/cli/main.c

#include "../../../../third_party/NordicSemiconductor/nrfx/drivers/include/nrfx_twi.h"

static nrfx_twi_t m_twi;

void twi_handler(nrfx_twi_evt_t const * p_event, void * p_context)
{

}
extern nrfx_err_t nrfx_twi_init(nrfx_twi_t const *        p_instance,
                         nrfx_twi_config_t const * p_config,
                         nrfx_twi_evt_handler_t    event_handler,
                         void *                    p_context);

void twi_init()
{
    const nrfx_twi_config_t twi_config = {
       .scl                = 26,
       .sda                = 27,
       .frequency          = 100,
       .interrupt_priority = 1,
       //.clear_bus_init     = false
    };

    m_twi.drv_inst_idx=0;
    nrfx_twi_init(&m_twi, &twi_config, twi_handler, NULL);
}

And the error I am getting while compiling:

/opt/gcc-arm-none-eabi-9-2020-q2-update/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld: openthread/examples/apps/cli/CMakeFiles/ot-cli-ftd.dir/main.c.obj: in function `twi_init':
main.c:(.text.twi_init+0x26): undefined reference to `nrfx_twi_init'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Thanks,

Hardik

  • Hello Hardik, 

    Have you looked at the nrfx documentation? In the Introduction and configuration it states:

    The purpose of nrfx is to make it possible to use the same set of peripheral drivers in various environments, from RTOSes to bare metal applications. Hence, for a given host environment, a light integration layer must be provided that implements certain specific routines, like interrupt management, critical sections, assertions, or logging. This is done by filling a predefined set of macros with proper implementations (or keeping some empty if desired) in files named:

    Templates of these files are provided in the templates subfolder. Their customized versions can be placed in any location within the host environment that the used compiler can access via include paths.

    In addition, the following locations should be specified as include paths ([nrfx] stands for the nrfx root folder location):

    [nrfx]/
    [nrfx]/drivers/include
    [nrfx]/mdk

    Let me know how that works for you. 

    Kind regards,
    Øyvind

Related