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

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

Children
  • I find this to be a constant source of problems & confusion - both myself and in posts by others here on the forum.

    It is particularly hard to debug because of the way everything is hidden in multiple layers of macro definition, redefinition and preprocessor tricks with the ## operator, etc.

    Disappointed

    This really needs to be far better documented!

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

Related