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

NRF52840 requires power cycle, HW reset, or Verify to run after flashing firmware

Hello, I've seen some similar questions about resets after downloading firmware, but haven't been able to find the solution to my problem.

I'm using a Minew MS88SF3 NRF52840-QIAA module with SDK17.0.0 with Segger Embedded Studios v4.52, messily soldered onto a custom board for a HID keyboard prototype. I've had some issues needing to resolder the module, needing to touch up some pins, but I think I've got those all sorted out so I've convinced myself it's a software issue.

Testing with the ble_hids_keyboard example (PCA10056 and S140) I can't seem to download firmware and have it run right afterwards, but only when the device had existing firmware. The problem can be succinctly summarized as:

Firmware runs successfully when:

  • Erase All followed by Download
  • Download followed by Verify
  • Download followed by pulling Reset pin low
  • Download followed by power cycling
  • Run in Debug mode

Firmware does not run when:

  • Download onto a chip with existing firmware and leaving it be

When I have RTT Viewer running during a download of a slightly modified firmware, I get this error message:

00> <info> app_timer: RTC: initialized.
00> 
00> <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at B:\Users\[me]\Documents\NRF52_SDK17.0\nRF5_SDK_17.0.0_9d13099\examples\my_custom_projects\nrf52840_keypad_0\main.c:1497
00> 
00> PC at: 0x000315F9
00> 
00> <error> app: End of error report

Line 1496 and 1497 of main.c are as follows. It's interesting that I would get this error after a Download, but not when running it in Debug.

err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);

Otherwise, for the default hids_keyboard example, I just get this. Not sure I remember what I changed to make the error logging more verbose in my custom firmware.

00> <info> app_timer: RTC: initialized.
00> 
00> <error> app: Fatal error

Thanks!

  • Possibly the code is set to expect a 32kHz crystal when none is fitted, or if fitted it doesn't oscillate. If so there are weird side effects such as you are describing. Perhaps add this to the very top of sdk_config.h to eclipse all the setting lower down in that header file:

    // NO_32_KHZ_CRYSTAL
    #define NRFX_CLOCK_CONFIG_LF_SRC         0
    #define CLOCK_CONFIG_LF_SRC              0
    #define NRF_SDH_CLOCK_LF_SRC             0
    #define NRF_SDH_CLOCK_LF_RC_CTIV        16
    #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV    2
    #define NRF_SDH_CLOCK_LF_ACCURACY        1 // <1=> NRF_CLOCK_LF_ACCURACY_500_PPM

  • Thanks for taking the time to answer. I believe the 32khZ crystal within the module must be oscillating in order for BLE to function properly, which it does when the reset is issued. Nonetheless I tried your solution, but no luck unfortunately

  • Hi

    When the nrf_sdh_enable_request() returns the INVALID_STATE error, that indicates that the SoftDevice is already enabled, which points to the SoftDevice having been started earlier in your application, or that it isn't disabled correctly initially.

    If you enable the SoftDevice using the nrf_sdh_enable_request() you should also disable it using the same API with nrf_sdh_disable_request(). This is likely what is causing the error you're seeing.

    Best regards,

    Simon

  • Thanks for the information! Since the problem only occurs on the SDK examples that use a softdevice, that seems to be it, but do you know how I can alleviate the problem within the context of the run-after-download issue? I have a 4-wire SWD connection with GND/VCC, and SWDIO/SWCLK. If I understand the problem correctly, it's as if the SoftDevice remains enabled between firmware downloads.

  • It seems very strange that the SoftDevice should already run if you do an erase all before flashing the device. It could be the case that your application enables the SoftDevice prior to line 1496 in your main.c application. If so you can try removing this call. Have you made any changes to the ble_hids_keyboard example, or is it the default example that fails like this?

    Best regards,

    Simon

Related