J-link error but BLE program seems to continue, no error log

Dear Nordic,

I am implementing firmware on a nRF52840 Development Kit (DK) with the following functionality already implemented:

- BLE: 1 service based on ble_uart, another service based on ble_lbs.

I can send commands from my phone to the DK, which can turn on a LED and start taking measurements.

I send the measurement results to three separate characteristics, which my phone can be notified of.

- Timer1: every second, set a flag

- TWI, in main loop: when timer1 flag is set, receive bytes from sensors on external board

Using:

Segger Embedded Studio

nRF5_SDK_17.1.0

s140 software device

Issue

When debugging the program, after a seemingly random amount of time, I get a J-Link error which stops the debugging operation. Sometimes this takes 1 minute, sometimes 10 minutes.

After the error occurs, I can still send commands and receive values via my phone. My phone (nrf connect app) remains connected. If I send the command to toggle the LED, for example, the device still does so. If the LED was on before the error occured, the LED remains on and can still be turned off when I send the command.

What has me stumped is that I never receive a crashlog nor error message. And I am not sure whether that is simply because the device does not crash/ reset or because I haven't set up the error handling correctly.

I have HARDFAULT_HANDLER_ENABLED 1. I set breakpoints in all the files related to error handling, but it simply does not enter any of the breakpoints before the error happens.

I raised the debug_log levels of all related peripherals to 4 (debug), and the latest log message I receive is:

<warning> TWIM: Function: nrfx_twim_xfer, error code: NRF_SUCCESS.
<debug> TWIM: TWIM: Event: NRF_TWIM_EVENT_STOPPED.
<debug> nrf_sdh_ble: BLE event: 0x57.

Which is similiar to normal operations. The BLE event is always the last message.

I am, however, not sure if a function that includes NRF_LOG_FINAL_FLUSH() is ever called, so I might be missing debug information here.

Main Loop

for (;;)
{
idle_state_handle();


// Idle_state_handle puts the device to sleep UNTIL an event occurs. This event can be any interrupt, such as the Timer or Bluetooth module.
// The device effectively halts at idle_state_handle(). After an interrupt, the following code is handled until it is stopped by the idle_state_handle() again.
// Therefore: after the device gets out of idle state, check if the interrupt source was the timer (which sets b_timer_ticked = true), and initiate measurements.
if(b_take_measurements && b_timer_ticked)
{
timer_tick_counter++;
#ifndef NDEBUG
NRF_LOG_DEBUG("Loop Timer Tick Count: %d", timer_tick_counter);
#endif

// Read ADC hydrogen data, process into bytes, Start new measurement and send data.
hydrogen_value = ads1114_read_data(&m_twi, &twi_transfer_done);
float_to_bytes(hydrogen_value, hydrogen_send_array);
err_code = ble_nus_data_send_hydrogen(&m_nus, hydrogen_send_array, &hydrogen_send_array_size, m_conn_handle);
ads1114_configure(&m_twi, &twi_transfer_done); //NOTE; configure also starts a measurement and points to measurement

compare_hydrogen_threshold(hydrogen_value);

//NOTE: Every 4th tick, a humidity and temperature reading will be performed
//HDC1080 datasheet recommends measurements every 500 ms
//Timer is configured for 125 ms, 4 timer ticks is 500 ms
if(timer_tick_counter >= 4)
{
hdc1080_readings_t measurements = hdc1080_read_measurements(&m_twi, &twi_transfer_done);


hdc1080_start_conversion(&m_twi, &twi_transfer_done);

// Separate temperature into bytes to Bluetooth array and send
float_to_bytes(measurements.temperature, temperature_send_array);
err_code = ble_nus_data_send_temperature(&m_nus, temperature_send_array, &temperature_send_array_size, m_conn_handle);

// Separate humidity into bytes to Bluetooth array and send
float_to_bytes(measurements.humidity, humidity_send_array);
err_code = ble_nus_data_send_humidity(&m_nus, humidity_send_array, &humidity_send_array_size, m_conn_handle);

timer_tick_counter = 0;
}

b_timer_ticked = false;
}
}

Includes

#include <stdint.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "ble_hci.h"
#include "ble_advdata.h"
#include "ble_advertising.h"
#include "ble_conn_params.h"
#include "nrf_sdh.h"
#include "nrf_sdh_soc.h"
#include "nrf_sdh_ble.h"
#include "nrf_ble_gatt.h"
#include "nrf_ble_qwr.h"
#include "app_timer.h"
#include "ble_nus.h"
#include "app_uart.h"
#include "app_util_platform.h"
#include "bsp_btn_ble.h"
#include "nrf_pwr_mgmt.h"

//manually added
#include "nrf_drv_twi.h"
#include "nrf_drv_timer.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "ads1114.h"
#include "ad5144a.h"
#include "hdc1080.h"
#include "gasena_ble_command_service.h"

Please find attached my sdk_config.h

Questions

1. Could you please assist me with figuring out the root of this issue? I realise it might be Segger related, but I feel like my firmware is the culprit here.

2. Do you see anything missing in my config file or #includes that could lead to me not handling errors correctly and without log files?

3. Is it possible for the device to reset but still remain connected to my phone, and immediately turn [edit: ON] the LED because of some Bluetooth wizardry? Or should the LED turn off and the device disconnect after debugging has stopped?

Kind regards,

  • Hi Frederik, 

    Could you try to test debugging with one of our example, ble_app_hrs for example ? 
    I suspect that it's an issue with the debugger and has nothing to do with the application or the communication between the DK and the phone. 
    You can verify that the device was not reset by having a LED blink when the device booting up for example.

    Do you have other DK to test ? 

    Which Jlink version you are using ? And which SES version ? Please try to use the SES version (5.42a) mentioned in the release note of the SDK https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/index.html?cp=9_1_0

  • Hi Hung,

    Thank you for your fast response and your assistance.

    Debugger: I assume SES uses the installed debugger on my desktop, which is V7.88. I am not actively using the software but only using SES.

    I will apply your suggestion about having a LED blink when the device boots up.

    I will see if I can find another DK to test with.

    SES: I was using SES version V7.30. I installed V5.42a and now running some tests. It still gives an error, but this time its a bit more informative:

    Running another test results in:

    I received the "Error reading from memory address 0x20004754" countless times in quick succession before losing the target connection.

    The last message in the debug terminal is once again BLE event: 0x57.

    Please forgive my ignorance, but do you have an idea how I can best figure out the root cause of this memory error?

  • I think there must be something wrong with the hardware on the DK. Either too long USB cable, or something wrong with the debugger. 
    Please try to test with another DK to see if you have the same error. Please also try with another USB cable, and connect to another USB port, preferably directly to the mainboard. 

  • Unfortunately I do not have another DK available at the moment. I do have a PCB I just received with an nRF52840 on it, but using that could introduce other uncertainties. 

    The error I mentioned above is when running my firmware, not the ble_app_hrs example, by the way. Apologies for the confusion.

    I've been running the ble_app_hrs_pca10056_s140 for around 15 minutes now without issue. So it seems the issue is my firmware.

    I am guessing one of my BLE functions is trying to read an invalid memory address, as running just the TWI functionality worked fine.

    EDIT: following this guide from nordic, I made sure I had the right memory definitions. Now that I adjusted it, the same error still occurs but now at a different address:

    Error reading from memory address 0x20004734

  • I don't see a problem reading address 0x20004754. It's application memory address and should be available to the application. 

    I would strongly suggest to get hold of another DK and test again. 

Related