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

Configuring SPI -- is the legacy layer required?

Hello,

I am migrating a BLE project from SDK 13.1 to SDK 15, and am running into an issue with SPI functionality.  I have followed the migration guide for 14.2 to 15, changed the variable/function/macro names as appropriate, but it still does not function.

It appears that there are now several places within  SDK 15 where NRFX_SPIM_ENABLED is defined. ( namely the sdk_config for the particular project, then again for each modules\templates\nRF52*\)

I am using NRFX_SPIM0_ENABLED for my particular project.

Also within the nrfx_glue.h, there is the include apply_old_config.h which looks like:

#undef NRFX_SPI0_ENABLED
#define NRFX_SPI0_ENABLED (SPI0_ENABLED && !SPI0_USE_EASY_DMA)
#undef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED (SPI0_ENABLED && SPI0_USE_EASY_DMA)

I don't understand this. Isn't SPI0_ENABLED part of the legacy SPI driver? The Migration document recommends to fully implement the new NRFX drivers as the older ones will be depreciated.

Could I get some advice on this? Maybe the sdk_configs at a minimum? I have vigorously reviewed the nrfx_spi example, which has not borne fruit.

Thanks!

Parents Reply Children
  • It may be the _intention_ that the legacy driver is not required, but the configuration for it _IS_ required, due to (in my opinion) a bug in SDK 15.0 apply_old_config.h.  Here's what I wrote in response to another ticket (206140) for the same issue:

    I have the same problem, and just spent an hour tracking it down. It is caused by the legacy adapter code in apply_old_config.h, which is included from nrf_glue.h, which is included from nrfx.h, which is included from just about everything peripheral-related.

    If you're not using the legacy interface, this should leave your NRFX_SPI0_ENABLED etc. unchanged, but unfortunately it does not. If you don't also have SPI0_ENABLED, it redefines NRFX_SPI0_ENABLED to 0. In my opinion, this is a serious defect in the SDK; using the new NRFX drivers shouldn't require having the legacy defines also set.

    The workaround is to define SPI<n>_ENABLED to have the same value as NRFX_SPI<n>_ENABLED, to prevent apply_old_config from changing it.

  • Just remove the legacy SPI driver config from sdk_config.h and you will be fine. apply_old_config.h will overwrite the config if the SPI_ENABLED config is defined, so you should make sure it is not defined at all. This can only be achieved by removing the config from sdk_config.h. 

    You do not need the legacy config when using the new nrfx drivers, so removing this is completely safe.

  • Before reading your reply, I just tracked it down to the fact that apply_old_config.h uses #ifdef to check for the legacy configuration. That makes it think legacy is enabled if the define is to 0. It should use #if the way almost all other Nordic SDK feature tests work; that way if it is either undefined OR zero, the right thing will happen. In my opinion, this is still a defect in the SDK.

Related