Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52 SDK 15.0 issue: legacy driver layer upgrade to new nrfx driver layer

Hi,

I have some problems changing from the legacy driver to the new nrfx driver structure.

I have done the following:

1) Opened pwm example in SDK 15.0.

2) Renamed the pwm functions to nrfx_pwm from nrf_drv_pwm, likewise with relevant data structures.

3) Since I only want to run the new nrfx driver, and not the old legacy driver interface, I have made a change in the sdk_config.h: NRFX_PWM_ENABLED =1, so left it unchanged. PWM_ENABLED=1 (only for legacy driver??), and have changed it to 0.

4) Compiled the project and then get lots of compile errors, mostly that nrfx_pwm_xx functions and data structures is undeclared.

Is the intention to use both NRFX_PWM_ENABLED=1 and PWM_ENABLED=1, to use the new drivers?

I would have guessed that PWM_ENABLED=0 would disable the legacy driver layer.

If this is not your intention, I solution could be:

A) For here and now, just have PWM_ENABLED=1, even if not using legacy driver.

B) In the file apply_old_config.h, the line '#if defined(PWM_ENABLED)' could be changed to '#if PWM_ENABLED'.

Then, also consider doing this for all other relevant peripherial drivers.

Parents
  • Hi Edwin,

    >> I am not sure I understand what you mean. Are you porting an old project
    >> to a new SDK, or porting the new driver back to an old SDK?

    I am working with the PWM example in SDK 15.0.
    I Have renamed functions and datatypes, so they use the new driver layer interface name convention. 
    It works fine, when NRFX_PWM_ENABLED=1 & PWM_ENABLED=1.


    >> And is this a question, or a suggestion?

    It is both a question and a suggestion(suggestion is dependant on your answer).
    Look for the question marks. Sorry if my text was unclear.

    I will try asking the question again:

    A) When using the new driver structure in SDK15, which combination of values for NRFX_PWM_ENABLED & PWM_ENABLED is intended/allowed?

    In sdk_config.h, from by best of understanding, I get:
    NRFX_PWM_ENABLED=0 & PWM_ENABLED=0 => PWM functionality disabled.

    NRFX_PWM_ENABLED=0 & PWM_ENABLED=1 => PWM enabled with old legacy driver layer naming functionality.

    NRFX_PWM_ENABLED=1 & PWM_ENABLED=0 => PWM functionality enabled, but only new driver layer naming functionality??? Not working.

    NRFX_PWM_ENABLED=1 & PWM_ENABLED=1 => PWM enabled with both Old legacy driver layer & new driver layer naming functionality.

    If the combination NRFX_PWM_ENABLED=1 & PWM_ENABLED=0 is valid, there is something faulty (the compilation fails). I have suggested a fix, which seems to solve it.

    Best regards, Erik.

  • Hello,

    Sorry. I understand now. I see that they are both defined in the PWM examples. 

    The nrfx drivers are standalone working drivers intended to work without the SDK. However, the SDK still uses the PWM_ENABLED for wrapping functions. Exactly why it is like this, I am not completely sure. I think it is because of portability reasons. If you look in the apply_old_config.h file, that you mentioned, the NRFX_PWM_ENABLED is overwritten by the PWM_ENABLED.

     

    Basically:

    nrfx_pwm uses only NRFX_PWM_ macros, but in the SDK, there is a legacy layer that makes it possible to use nrfx_pwm_ API via the old nrf_drv_pwm_ namespace. It is correct as you say, that if PWM_ENABLED = 0 and NRFX_PWM_ENABLED  = 1, then the PWM will not be enabled, due to the implementation. If you want to use only the NRFX_PWM_ENABLED, you should remove the #define PWM_ENABLED completely, and not set it to 0.

     

    I agree that this might be a bit confusing. I have forwarded this internally, and they will see if it can be done more comprehensible in the SDK examples.

     

    Thank you for your input.

     

    So to answer your question, what combinations are allowed:
    All, but (!) it depends on whether you include the file apply_old_config.h. If you only want to use the new NRFX_ drivers, you should either remove this file, or completely remove the old driver defines (such as PWM_ENABLED).

     

    Best regards,

    Edvin

Reply
  • Hello,

    Sorry. I understand now. I see that they are both defined in the PWM examples. 

    The nrfx drivers are standalone working drivers intended to work without the SDK. However, the SDK still uses the PWM_ENABLED for wrapping functions. Exactly why it is like this, I am not completely sure. I think it is because of portability reasons. If you look in the apply_old_config.h file, that you mentioned, the NRFX_PWM_ENABLED is overwritten by the PWM_ENABLED.

     

    Basically:

    nrfx_pwm uses only NRFX_PWM_ macros, but in the SDK, there is a legacy layer that makes it possible to use nrfx_pwm_ API via the old nrf_drv_pwm_ namespace. It is correct as you say, that if PWM_ENABLED = 0 and NRFX_PWM_ENABLED  = 1, then the PWM will not be enabled, due to the implementation. If you want to use only the NRFX_PWM_ENABLED, you should remove the #define PWM_ENABLED completely, and not set it to 0.

     

    I agree that this might be a bit confusing. I have forwarded this internally, and they will see if it can be done more comprehensible in the SDK examples.

     

    Thank you for your input.

     

    So to answer your question, what combinations are allowed:
    All, but (!) it depends on whether you include the file apply_old_config.h. If you only want to use the new NRFX_ drivers, you should either remove this file, or completely remove the old driver defines (such as PWM_ENABLED).

     

    Best regards,

    Edvin

Children
  • I have also came across this same "issue" that Erik has. 

    Edvin, can you please update us in this thread if you received any feedback about what would be the best-practice for using the legacy and the new nrfx peripheral drivers?
    It would be also great if you'll be able to write just a couple of sentences in the changelog about these kinds of modifications in future sdk releases. 

    Regards,
    Adam

  • Hello Adam,

    No response yet. We will have to wait and see if they do any changes in a new SDK release.

     

    Basically, all the peripherals uses nrfx drivers in SDK15. It is only a matter of what your defines are called. SDK15 uses files that are just mapping the old driver names to the new nrfx drivers. I am not 100% sure, but I guess they use the old names for porting reasons (customers porting applications from older SDKs). There really isn't a problem using the old define names in sdk_config.h, and in the application layer. The function names are, as I mentioned, simply mapped to the new nrfx drivers.

     

    Alternatively, remove every file that you can find which includes the old "legacy" driver names (including apply_old_config.h) , and replace the function calls with the new names from the nrfx drivers. But again, you will still use the nrfx drivers if you keep the old names. Just be aware that the NRFX defines in sdk_config.h are overruled by the old "legacy" defines in apply_old_config.h. The easiest way to work around this is to define the old "legacy" defines and new nrfx defines to be the same.

     

    Best regards,

    Edvin

Related