Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Override SDK functions which are not declared as __WEAK__

Hi all,

In my project i'm using the nrf52840 SoC in my board. 
I'm currently working on the bootloader, and I would like to add additional logic to functions mentiond in the SDK (version 17.1.0) but not defined as __WEAK__,
i.e I can't create my own function using the same name and be sure my function will be called at runtime.

How can I override a function such as so?

For example - 
I want to modify the "nrf_dfu_transports_init" function declared & defined in "nrf_dfu_transport.c" file.
this is the function definition:


Do I have to copy the entire file, change its name and order the compiler to take my file instead of the SDK one (in the .emProject file)? Or is it a better way of doing that without copying the entire file for just one function I want to modify?

  • Hell Sharon,

    Yes, you essentially need to remove the original implementation from compilation and add in that of yours.

    There are several approaches. Replacing the file with your own copy is one way.

    Another one is to comment out just the function you want to replace and add the replacement function in one of your source files.

    Finally, you could just edit the original source file.

    All approaches work, and whether one fits or not depends on the specifics of your project like version controls or code organizations.

    Hieu

Related