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

Flashing an hex file to Red Bear Lab BLE Nano (nRF51822) from command line

I am using the eclipse/gcc toolchain as explained in this tutorial. I am able to generate and flash my application code and softdevice separately using hex format.

I am using the flash and flash_softdevice targets defined in the makefiles of nRF51 SDK:

flash: $(MAKECMDGOALS)
	@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
	nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
	
## Flash softdevice
flash_softdevice: 
@echo Flashing: s110_softdevice.hex
nrfjprog --reset --program ../../../../../../components/softdevice/s110/hex/s110_softdevice.hex

I do not know why, but although the flashing process of the two hex files works ok, the application in BLE Nano does not work.

If I merge the two files using the nRF51 tools, the app keeps not workig on my BLE Nano.

mergehex.exe --merge ../../../../../../components/softdevice/s110/hex/s110_softdevice.hex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex --output $(OUTPUT_BINARY_DIRECTORY)/merge_$(OUTPUT_FILENAME).hex
    
nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/merge_$(OUTPUT_FILENAME).hex

However the hex file generated in the previous step is a good one. I can upload it to BLE Nano using the MK-20 USB dongle and drag&drop in the BLE Nano drive. Once flashed, the app is properly installed and I can use it.

From this moment (after flashing once with MK_20 dongle), I can recompile my app in eclipse/gcc and generate a new $(OUTPUT_FILENAME).hex file and flash it to BLE Nano from eclipse or command line with the flash target (no need to use the BLE Nano dongle).

I believe that I am missing some paratmeters (bootloader?) or commands (reset?) when trying to flash from eclipse. Any help about what do I need to do to upload the merged HEX file from eclipse/command line?

  • Are you using a J-link programmer instead of the BLE Nano dongle?

  • I am using both USB dongle MK20 from BLE Nano and J-Link programmer. If I use the MK-20 dragging and dropping the merged HEX file, the app is propoerly installed. If I use J-Link flashing the merged HEX file (or flashing first SD and then the app), the flashing process is successful but the app does not work/start. I guess that I miss a bootloader in the case of J-Link that MK-20 is flashing somehow by default.

    If I flash the app once with MK-20, I can move the BLE Nano to J-Link and then I can reflash (only) the app from Jlink and the app is then properly updated (I assume that the MK-20 bootloader is not deleted and is still valid)

  • I found the cause for my issues. Nothing to do with BLE Nano, nRF51822 or j-Link. The problem was the malfunctionaing USB hardware of my PC.

    I am not sure why this is happening, but sometimes the J-Link USB driver misbehaves. Although I can still flash BLE Nano from J-Link, the BLE Nano is not properly reset afterwards. This means that the installed application is not "visible" over BLE. When this situation happens, the green LED indicator of J-Link blinks at 10Hz.

    If I connect J-Link to another PC or connect BLE Nano through the MK-20 USB dongle, I see that the application has been properly isntalled and is "visible" over BLE.

    When this happens, I restart my PC and things start working again (I believe the issue is with the USB hardware of my old PC, not with the J-Link driver)

Related