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

Re-calling nrfx_spim_init()

Hi,

Is it safe to call nrfx_spim_init() multiple times with and without a handler without calling uninit() in between?

I have an SPI device that needs a sequence of steps to initialise and using a callback approach is actually unnecessarily complicated, so my plan would be to initialise the driver without a callback in the first instance (so that I get blocking transfers) and then once the SPI device is setup then re-call init() with a callback so that the ongoing operations are non-blocking.

I can't see anything in the code that might be problematic, but just wanted to check.

The reality is that I'll probably uninit() between the two sections of code anyway for power saving reasons, but it would be good to know.

As an aside, I'm a new user (I think it's day 3) and the whole driver side of things is very difficult to untangle from the docs ... the nrfx drivers are stated as strategic and the old ones called "legacy" yet as you navigate around the docs for SDK v17 it's almost impossible to follow any links into the nrfx docs. Most of the descriptions and examples are for legacy, and there's very little pointing you anywhere else (bar a single page migration guide that doesn't even have any links to the nrfx drivers!)

So at first glance I think it's too easy to build an app with legacy drivers by default, which presumably is not what people should be doing!

I would have thought a small note at the top of the "Herdware Drivers" page would be useful, highlighting the preferred approach and with a link to the nrfx drivers??

Lee.

(BTW -- I started my project with a different vendors solution, but had to give up on them because of shocking documentation, the Nordic docs are waaaay better and I'm finding it relatively easy to work with, so this isn't a complaint at all ... just a suggestion for improvement!)

  • Hi,

    nrfx_spim_init() will return an NRFX_ERROR_INVALID_STATE if it's called and the module is not in NRFX_DRV_STATE_UNINITIALIZED state:
    You should therefore un-initialize the driver before you re-initialize it. 

    I get your points regarding the NRFX and the legacy driver and understand that it can be a bit confusing for new users. Most of the examples uses the legacy driver that again uses macro forwarding which means that they really are using the NRFX drivers.
    The NRFX driver can be found here.
    Thank you for the feedback
    regards
    Jared
Related