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

Segger-Nordic Effect

Good day,

I would like to start this thread by saying that I have been developing an application using the nRF52832 chip for several months, so far it has been a very difficult but not impossible journey and I have seen that I have not been the only one (https://devzone.nordicsemi.com/f/nordic-q-a/54157/difficult-to-use-nrf5x-sdk-from-scratch  https://devzone.nordicsemi.com/f/nordic-q-a/21403/we-really-want-to-work-with-nordic-but-they-makes-it-hard). I started using the Keil software, but it was impossible to continue working with that software due to the problem that arises at the time of importing libraries and drivers, from the same projects that come by default in the software and the example projects that are downloaded from devzone. 

So my team and I decided to start using Segger Embedded Studio and everything became much more practical and it was easier to import libraries, create new files and add them to the path, etc. (I would like to give this advice for those who are just starting with this technology and are deciding which software to use to program the nRF52 chips). Nevertheless, after several weeks, we realized that something strange happens when trying to program the nRF52832 and the nRF52810, either on the DK nRF52 board or on a custom board, and we have called it: "The Segger-Nordic effect".

Because of what happened today, I decided to share this, besides the fact that we are still trying to figure out the problem, what happens is the following:

We are trying to measure the current consumption using the example ...\examples\ble_peripheralc\ble_app_template  based on what is described in the Nordic infocenter (https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf52832_dk%2FUG%2Fnrf52_DK%2Fhw_meas_current.html) using an oscilloscope and an ampere-meter in order to compare and verify the result.

For this purpose, we carry out the following in the nRF52 DK board:

  1. Cut the PCB track shorting solder bridge SB9 to put P22 in series with the load.
  2. Short solder bridge SB12 (if using external power supply) to bypass the protection diode which would otherwise give a voltage drop.

Since we short-circuit SB12, we add an external supply on P21 at 3.3v and add a 10 ohms resistance in SB9 and that is where we measure with the oscilloscope.

From here is where it all starts to get a little tricky:

To begin, the led 1 of the board begins to blink as if it were in advertising mode and we have set an APP_ADV_DURATION of 2000, however it blinks infinitely. But when we try to search it with the Nordic nRF Connect application, the device does not appear.

We were doing a test using the function nrf_pwr_mgmt_run(); inside static void idle_state_handle(void); in order to know how much current was being consumed when connected with BLE, We moved, changed, deleted and increased several things and we managed to see it only once and realized that it was consuming around 4 mA, but we never saw the device again.

Seeing what the function nrf_pwr_mgmt_run does:

void nrf_pwr_mgmt_run(void)
{
    PWR_MGMT_FPU_SLEEP_PREPARE();
    PWR_MGMT_SLEEP_LOCK_ACQUIRE();
    PWR_MGMT_CPU_USAGE_MONITOR_SECTION_ENTER();
    PWR_MGMT_DEBUG_PIN_SET();

    // Wait for an event.
#ifdef SOFTDEVICE_PRESENT
    if (nrf_sdh_is_enabled())
    {
        ret_code_t ret_code = sd_app_evt_wait();
        ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
        UNUSED_VARIABLE(ret_code);
    }
    else
#endif // SOFTDEVICE_PRESENT
    {
        // Wait for an event.
        __WFE();
        // Clear the internal event register.
        __SEV();
        __WFE();
    }

    PWR_MGMT_DEBUG_PIN_CLEAR();
    PWR_MGMT_CPU_USAGE_MONITOR_SECTION_EXIT();
    PWR_MGMT_SLEEP_LOCK_RELEASE();
}

We decided to directly insert the function "Wait for an event":

/**@brief Function for handling the idle state (main loop).
 *
 * @details If there is no pending log operation, then sleep until next the next event occurs.
 */
static void idle_state_handle(void)
{
       //nrf_pwr_mgmt_run();
       __WFE();
       __SEV();
       __WFE();
}

On a first attempt at making the change the device appeared, however that was just after loading the program, when changing the USB connection for external supply the device did not appear again. We did several tests until we realized that we must perform a ritual for the device to appear:

1. Ctrl + X the lines __WFE(); __SEV(); __WFE();

2. Ctrl + V the same lines in the same place.

3. Build and Run the program but with the P22 disconnected for Segger to mark the error of not finding the J-link

4. Connect the P22 pins to the 10 ohms resistance.

5. Build and Run de program.... et voilà!



We did this several times and it worked each time, until it stopped working and we couldn't see it anymore, for now we are still looking for a way to make this work. We have seen in other tests that the code sometimes does not work, but copying and pasting the same code in the same lines makes the program work. If you could help us figure out what's going on, we'd appreciate it.

We loaded the program, connected to the cell phone, measured the current and the result was: 240 uA. We only have the doubt if this is correct, since we have seen the several posts that having the softdevice must use the function nrf_pwr_mgmt_run() and not the function __WFE(); besides that is what is described in the comments of the same function. However, with this we got what we wanted, to reduce the current.

Could you give us your opinion and advice on this?

I also want to use this thread to ask:

In sleep mode we have a consumption of 1 uA, in advertising mode a current consumption of 100 to 150 uA and in connected mode a consumption of 240 uA (until the last test we could see).

Is the current consumed in advertising mode normal? or should it be much lower?

Is it possible to have in connected mode a consumption of around 20 uA? The device does not perform any action, it only sends the battery level every 30 minutes using the BAS function.

I hope that this post will be useful to someone else and that you can also help me to answer the questions that have come up, thank you very much for your attention and your help.

  • Hello,

    It's hard to say if the problems you observing are related to FW, HW, or both. To try narrow it down, I would suggest you try to measure current with my 'ble_app_template_260325' project attached below, and see if you can get similar results with your setup as I got when I measured it here.

    To begin, the led 1 of the board begins to blink as if it were in advertising mode and we have set an APP_ADV_DURATION of 2000, however it blinks infinitely. But when we try to search it with the Nordic nRF Connect application, the device does not appear.

    Ok, so the advertisment will time out after 20 seconds of advertising. However, the LED indication for advertising is started on BLE_ADV_EVT_FAST by calling the bsp_indication_set(BSP_INDICATE_ADVERTISING), and it will not stop until the app calls bsp_indication_set() with a different indication state (see BSP indication states). In other words, it's the application that's responsible for changing the LED indication when the app stops advertising. Otherwise, the LED will keep blinking forever.

    Measurements results with ble_app_template_260325 and nRF52DK

    Advertising mode

    Connected mode (~180 ms connection interval)

    Attachment (Requires nRF5 SDK v17.0.2)

    1033.ble_app_template_260325.zip

  • Hi Vidar,

    I want to thank you for your prompt response, I have tried the program and it works like a charm, in advertising mode it consumes a maximum of 90 uA, varying up to 5 uA, and in connected mode it varies from 5 uA to 43 uA, what is the reason for this variation?

    I have noticed that I can connect and disconnect without any problem with your program, but with mine, today, I have connected once and I could not do it more. With this we can realize that it is a problem of FW.

    Trying the same program but without the short circuit of SB9 and desoldering SB12 (returning to normal) the program works perfectly well, in fact it also works with a custom board, the problem arises when making the change to measure current.

    With regard to the led, I made the changes of BSP indication states so that only the BLE_ADV_EVT_FAST works and finish the advertising in just 20 seconds and then continue to IDLE mode, that's why I realized that the problem of infinite blinking arises.

    Another factor that I see different between our programs is that I am using the nRF5_SDK_15.0.0 SDK, I'm not sure if this has anything to do with what's happening.

  • Update

    I have found the solution to the problem that the device does not appear and the LED blinks infinitely:

    I was testing using the example nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral\ble_app_template\pca10040e, I had read that in order to develop a program for the nRF52810 chip it is necessary to remove  the DEVELOP_IN_NRF5282 of the project options.

    Then I had removed that line and that was causing the problem, when I put it back the program works as expected. However, there is still a current consumption of 267uA, which is possibly due to BAS or because we are using a PWM pin, any idea will be appreciated. In my project the consumption is stabilized at 267 uA but in the one you send me there is a continuous variation, why does this happen?

    Thanks for the help Vidar, your program helped me solve that part.

Related