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.

  • 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.

  • 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