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?

Parents
  • Hi, what do you mean by "comment out" just the function you want to replace?

    Eventually the compiler builds the image according to sdk_config and .emProjec files.
    if I will tell guide him to include the nrf_Dfu_transport.c file in the compilation process it will also copile the "nrf_dfu_transport_init()" function.

    My goal is to remove copied files we have in the project which are 90%+ copy-pasted from the SDK.
    My wish is to use only the SDK functions s much as possible

  • By comment out, I mean using the comment syntax to remove the code section but still leaving trace of it.

    void func_to_be_built(void)
    {
    
    }
    
    // void func_not_to_be_built(void)
    // {
    // 
    // }

    It is an idea independent of changing which file is built in .emProject.

    I think it is reasonable to try to use SDK functions as much as possible; but it is also fine to sometimes modify them if necessary. What kind of issue are you trying to resolve here that necessitates modifying the function?

Reply
  • By comment out, I mean using the comment syntax to remove the code section but still leaving trace of it.

    void func_to_be_built(void)
    {
    
    }
    
    // void func_not_to_be_built(void)
    // {
    // 
    // }

    It is an idea independent of changing which file is built in .emProject.

    I think it is reasonable to try to use SDK functions as much as possible; but it is also fine to sometimes modify them if necessary. What kind of issue are you trying to resolve here that necessitates modifying the function?

Children
No Data
Related