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

SPIM3 initialization issue

Hello guys,

I am using nRF52840 and SDK 15.3.0. Trying to use SPIM3 device because of the speed.

In my sdk_config.h file, I set both NRFX_SPIM_ENABLED and NRFX_SPIM3_ENABLED.

However, when I try to initialize SPIM3 with

err_code = nrfx_spim_init(&_spi_handle, &spi_config, NULL, NULL);

I get the error "undefined reference to `nrfx_spim_init`". This error comes because in nrfx_spim.c file, this pre-processor check returns false:

#if NRFX_CHECK(NRFX_SPIM_ENABLED)

I wonder why NRFX_CHECK(NRFX_SPIM_ENABLED) returns false when NRFX_SPIM_ENABLED is set inside sdk_config.h? Do you guys have any idea?

Thanks in advance for your time and effort.

Sincerely,

Bojan.

Parents
  • Hello Bojan,

    If NRFX_CHECK(NRFX_SPIM_ENABLED) returns false, then it means that NRFX_SPIM_ENABLED is defined to 0. Although you have defined it to 1 in sdk_config.h, it may be redefined in apply_old_config.h, which is a backwards compatibility header file. 

    Basically, if you define NRFX_SPIM_ENABLED 1 and NRF_SPIM_ENABLED 0, then NRFX_SPIM_ENABLED will be set to 0. So either:

    1: Define NRFX_SPIM_ENABLED to the same as NRF_SPIM_ENABLED

    2: Delete the NRF_SPIM_ENABLED define (not just set it to 0, but remove it). 

    3: Remove the apply_old_config.h file from your project. 

    Best regards,

    Edvin

  • Hello ,

    Just checked my apply_old_config.h file (located at integration/nrfx/legacy)... there is no NRF_SPIM_ENABLED there. Moreover, the whole content of the file is grayed.

    I think is right, this is really the source of confusion and stress... real attack on our common sense, making us feel bad and doubting our programming skills! Nerd

    I did not know until now that the file like apply_old_config.h exists. Anyway, good thing is that you are really responsive and helpful there. I hope we will all make Nordic environment even better in the future.

    Cheers,

    Bojan.

  • Sorry. I meant SPI_ENABLED, not NRF_SPIM_ENABLED. 

    I also agree that most of apply_old_config.h is greyed out, but I believe that this is just the IDE's not interpreting the defines correctly. So if SPI_ENABLED is defined, then NRFX_SPI_ENABLED is undefined, and defined as 

    define NRFX_SPI_ENABLED \
        (SPI_ENABLED && (NRFX_SPI0_ENABLED  || NRFX_SPI1_ENABLED  || NRFX_SPI2_ENABLED))

    I agree that this is very confusing, and you are by far not the only person facing this issue, as points out. 

    We have reported it to our SDK team, and I hope that it is fixed in the next release of the SDK.

  • I'm not sure that it's the SDK code that needs to be fixed - maybe just the documentation so that users can understand it, and know how to debug it when it goes wrong...

    It certainly doesn't help when the IDE conspires against you.

    SES (sometimes) seems to cope poorly.

    Disappointed

  • WOW!!!

    You want to say that we should doubt the behaviour of IDE as well (I am using SES, by the way)!? Scream

    God, save our souls!

    There is no #define SPI_ENABLED inside apply_old_config.h file. There is such a define inside sdk_config.h though. I tried there to set it to 1 or remove it but with no success!

    If I remove apply_old_config.h from the project like you suggested as 3rd possibility then the whole set of new errors emerge and everything starts to fall like the card tower.

    I found a workaround for the moment but I don't think this is a long-term solution: instead of NRFX_CHECK(NRFX_SPIM_ENABLED) I am checking NRFX_CHECK(NRFX_SPIM3_ENABLED) and this check passes successfully.

Reply
  • WOW!!!

    You want to say that we should doubt the behaviour of IDE as well (I am using SES, by the way)!? Scream

    God, save our souls!

    There is no #define SPI_ENABLED inside apply_old_config.h file. There is such a define inside sdk_config.h though. I tried there to set it to 1 or remove it but with no success!

    If I remove apply_old_config.h from the project like you suggested as 3rd possibility then the whole set of new errors emerge and everything starts to fall like the card tower.

    I found a workaround for the moment but I don't think this is a long-term solution: instead of NRFX_CHECK(NRFX_SPIM_ENABLED) I am checking NRFX_CHECK(NRFX_SPIM3_ENABLED) and this check passes successfully.

Children
  • bojan said:
    I found a workaround for the moment but I don't think this is a long-term solution: instead of NRFX_CHECK(NRFX_SPIM_ENABLED) I am checking NRFX_CHECK(NRFX_SPIM3_ENABLED) and this check passes successfully.

     I see. That will probably work, but it may cause some issues if someone wants to use your version of the SDK later (someone from the same company), and they want to use SPIM2 instead.

     

    bojan said:
    There is no #define SPI_ENABLED inside apply_old_config.h file. There is such a define inside sdk_config.h though. I tried there to set it to 1 or remove it but with no success!

     Yes. You may be right, it may cause some other defines to not be set properly. 

    There is an:

    #if defined(SPI_ENABLED) in apply_old_config.h on line 811.

    SPI_ENABLED is defined in sdk_config.h as you say, not in apply_old_config.h. If SPI_ENABLED is defined (e.g. in sdk_config.h), it doesn't matter whether it is set to 0 or 1, it will still overwrite the SPI defines in apply_old_config.h.

    NRFX_SPI_ENABLED will be set to SPI_ENABLED && (NRFX_SPI0_ENABLED  || NRFX_SPI1_ENABLED  || NRFX_SPI2_ENABLED)

    Also, on line 820 in apply_old_config.h, there is a check for #if defined(SPI_PRESENT) && !defined(SPIM_PRESENT), which by default, I don't believe will return true, but check what these are defined as in your project. 

    So if your project has:

    #define SPI_ENABLED 1
    #define NRFX_SPI0_ENABLED 0
    #define NRFX_SPI1_ENABLED 0
    #define NRFX_SPI2_ENABLED 0
    

    Then NRFX_SPI_ENABLED will be set to false. Try adding NRFX_SPI3_ENABLED to this check in apply_old_config.h:

    #if defined(SPI_ENABLED)
    
    #undef NRFX_SPI_ENABLED
    #define NRFX_SPI_ENABLED \
        (SPI_ENABLED && (NRFX_SPI0_ENABLED  || NRFX_SPI1_ENABLED  || NRFX_SPI2_ENABLED || NRFX_SPIM3_ENABLED))
    #undef NRFX_SPIM_ENABLED
    #define NRFX_SPIM_ENABLED \
        (SPI_ENABLED && (NRFX_SPIM0_ENABLED || NRFX_SPIM1_ENABLED || NRFX_SPIM2_ENABLED || NRFX_SPIM3_ENABLED))

  • I added NRFX_SPIM3_ENABLED to this check:

    #define NRFX_SPIM_ENABLED \
        (SPI_ENABLED && (NRFX_SPIM0_ENABLED || NRFX_SPIM1_ENABLED || NRFX_SPIM2_ENABLED || NRFX_SPIM3_ENABLED))

    and the code seems to compile even though that line is grayed in apply_old_config.h file. I needed to set #define SPI_ENABLED explicitly to 1 in order to have successful compilation.

    Thanks, , I learned a lot today.

    Thanks for your effort! It is really appreciated.

    Sincerely,

    Bojan.

Related