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

Adding nrf_nvic_state_t nrf_nvic_state = {0}; causes code not to build. No reason for build failure

I am still trying to figure out what NVIC_SystemReset actually does and why a build and run always gives an error forcing me to press the reset button on the DK to function,

I found this text in the documentation:

In order to use this module, the following code has to be added to a .c file:

Definitions and declarations starting with __ (double underscore) in this header file are not intended for direct use by the application.

I had not done this, so I added it as a global in my 'main' file to see if NVIC_SystemReset() would behave in an expected manner and if that would fix the build and load issue I have on the nRF523840 DK. Well, after adding that line of code the build simply fails. No reason, no indication that this line of code caused it. The only reason I knew that it was the reason is because the code built before adding that one line of code.

So now I have another question. How is it that the documentation states that I MUST add this line to use NVIC calls through SoftDevice yet adding it causes the build to fail? Without that line the code mostly works, especially in debug mode. I did not catch this requirement earlier because it is not noted in the functions, but in a different place.

Is the documentation wrong? Perhaps misleading and that line is only needed for SOME of the NVIC SotfDevce calls? I am very confused. Something is not working right with respect to loading new code, and doing an NVIC_SystemReset when the module finishes (after a BTLE disconnect). The idea is that the NVIC_SystemReset should bring the module back to the program start as if the board just powered up.

Just did a global search for the implementation in some example in the SDK and there was none. The comment was found in several nrf_nvic.h files. This gets more confusing by the hour. Am I running down a rathole?

  • Hi

    I believe the build problem is caused by the fact that the nrf_nvic_state variable is already implemented in app_util_platform.c, causing an error when you define it again. Essentially this is already handled by the SDK, and you don't need to define it in the application. 

    I don't understand why the build error lacks any further description though, I had to open the map file to realise it was already defined somewhere else. 

    Then to perform a soft reset you just need to call sd_nvic_SystemReset();

    Still, doing a system reset in this case feels a bit like treating the symptom rather than the cause, and we might want to look into why you need a reset to get the code to run in the first place. 

    Are you able to run the code if you start a debug session?

    Are you able to give me a brief overview of the functionality of your application, and what standard SDK example you started out with, if any?

    Also the type and version of chip, SDK and SoftDevice could be useful. 

    Best regards
    Torbjørn

  • I will give you the entire project if you want and it will help.

    I am using the nRF52840 DK and SoftDevice s140 7.2.0 (I see 7.3.0 is out; should get that). The SDK package I started with is 17.0.2. I started with the ghs example but you would not recognize it anymore. I started with that to get all the board setups, buttons and LEDs, and hardware initializations correct.

    If I run using the SES build and debug option, I do not need to press the DK's reset button to start the app and after the NVIC_SystemReset() call that I make after a disconnect. App restarts as desired.

    I do not call the reset method on program startup but only on program termination (after a disconnect) to restart the program as if it entered 'main()'  from a power up. It is difficult to get output during a real power up because putty won't open a session on the COM port until powered up, and once powered up, its too late to catch the output in the putty window. I assume a SES 'build and run' does effectively the same thing.

    As I stated in the initial question, I am NOT using the SDK but just SoftDevice. Well, I am not using the SDK for Bluetooth or flash writes and I have been able to remove those directories from the project s well as a few libraries. However, there are many libraries for RTC and other hardware setups that I don't dare to touch and really don't know what they do.

    So I am trying to solve two problems. The first is the fact I have to push the DK's reset button to start the program (that's in a separate issue) and why calling NVIC_SystemReset() is also working inconsistently. (This issue.) They are likely related. I suppose I could call sd_nvic_SystemReset(). Does it make a difference?

  • Hi 

    What inconsistencies are you still seeing in regards to the NVIC_SystemReset() function?

    The original topic was mostly about the build errors related to the code mentioned in the documentation. 

    For consistency you should call the sd_nvic_SystemReset() function rather than the native NVIC API, but in the case of this particular function the difference is negligible. sd_nvic_SystemReset() will call NVIC_SystemReset() under the hood. 

    Other parts of the sd_nvic_ function set have more differences, in order to prevent you from altering interrupts used by the SoftDevice, or try to use interrupt priorities reserved by the SoftDevice. 

    Having a look at your code might be useful, but it is limited how much I can dig into it if it is a large software project. If you want me to make the case private so you can share the code in confidence just let me know. 

    Best regards
    Torbjørn

  • 5861.nRF5_SDK_17.0.2_d674dde.zipI changed to sd_nvic_SystemReset but it did not solve the need to press the reset button on the DK after downloading new code onto the board (or on powering up). I also need to press the reset button (sometimes) after calling sd_nvic_SystemReset (which I only call on a disconnect).. When running with no optimizations, it is often the case I do not need to press the reset after the disconnect to restart. When running in debug mode (line by line) I never have to press the reset button, not even on program download. When running in an optimization to minimize size, I always have to press the reset button, both on download and after the call to sd_nvic_SystemReset().

    In another project (much simpler) on the DK after calling the system reset on a disconnect, the program restarts and begins to advertise, The same code on the nfr52840 dongle does not restart. I have to pull the dongle and plug it back in to get it to restart.

    That is what I mean by inconsistencies. I don't know what the DK's reset button does compared to what the software call does.

    Given all that, I must be missing something fundamental.

    I am happy to share the code and I don't care who looks at it. In the end when all is working as it should and the standard is complete, we will donate the code to Nordic so they can make it one of their examples. At least it will be a package showing the use of SoftDevice only for Bluetooth. That makes the code more portable between the pc-ble-driver and the actual hardware. 

    I suppose the best way to package it is to zip up the original downloaded package which was nRF5_SDK_17.0.2_d674dde. Not entirely sure how to attach it...

    In the examples directory I originally copied the ghs (I think) directory and started from there. There are a few other projects I have in there which I have made in testing various options on this GHS standard. I suppose I can delete those to save space.

  • Hi 

    Thanks for sharing your code. It build and runs nicely (refreshing to get code that builds without warnings!). 

    Everything seems to run fine here, but maybe that is because you have added some function to reset the code after it is programmed?
    I couldn't find any reference to this in your main() function though. 

    When I erase the flash in Segger Embedded Studio and then do a code download I can see the full startup sequence, and the code appers to run nicely:

    <debug> app: Main start GHS
    <info> app_timer: RTC: initialized.
    <debug> app: RAM starts at 0x20002B10
    <debug> app: Advertising data set
    <debug> app: Advertisement
     02 01 06 0F 09 47 68 73|....   Ghs
     20 53 70 69 72 6F 6D 65| Spirome
     74 65 72 03 03 90 F9 05|ter.....
     16 90 F9 1D 10         |.....
    <debug> app: Scan Response
     03 19 00 00            |....
    <debug> app: Service initiated
    <debug> app: Characteristic 0xF991 initiated
    <debug> app: Characteristic 0xF992 initiated
    <debug> app: GHS Start at time 0!

    Do I have to program the board some other way to see the issue, or is there some workaround code I need to disable in order to reproduce it?

    Best regards
    Torbjørn

Related