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

SDK 15 and Mesh 2.0 Generate a DFU file with nrfutil - ValueError

We used nRF5_SDK_15.0.0_a53641a and nrf5_SDK_for_Mesh_v2.0.0_src.

We are following DFU quick start guide http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.meshsdk.v0.10.0%2Findex.html

For nRF52:

mesh-sdk$ nrfutil dfu genpkg --application bin/blinky/blinky_nrf52832_xxAA_s132_5.0.0.hex \
--company-id 0x00000089 \
--application-id 1 \
--application-version 2 \
--key-file private_key.txt \
--sd-req 0x009D \
--mesh dfu_test.zip
We used "--company-id 0x00000089 \" to match Step 2 public key:
{
"bootloader_config": {
"bootloader_id": 1,
"bootloader_version": 1,
"company_id": 89,
"application_id": 1,
"application_version": 1,
"public_key": "ed09a58df6db5cd15b8637304f31d31f4042492ed7c7e4839fbe903f260a2ba1a855e92b72885825481ad56282bcf549ad7455ec46f000f0f62d97eeec883ba6"
}
}
The hex we used is C:\Nordic\nRF5_SDK_15.0.0_a53641a\mesh_sdk\bin\blinky\blinky_nrf52832_xxAA_s132_5.0.0.hexblinky_nrf52832_xxAA_s132_5.0.0.hex
We got ValueError, please see attached screen shot. 
Please advise.  Thanks
Parents
  • We started command prompt on an administrator.  I have make sure all the steps before and after step 8 using s132 softdevice version 6.0.  We tried to flash the program via both SES and nrfjprog (like shown in step 8).  We also used difference Bud rate 115200, 57600, 38400, 19200, 14400 and 9600.

    Attached are the cmd script file

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\ALaw>cd C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil keys --gen-key private_key.txt
    Generated key at: private_key.txt
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil keys --show-vk hex private_key.tx
    t
    Verification key Qx: d78ea2728b31c63b185402f4209803b478d0828b02a0f44da9f5d782b04
    7fe45
    Verification key Qy: b60bf4db2e572b4b6053c0c7e9371b309c93ee53c300906afc6c7f2d99c
    e11cd
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu genpkg --application bin/blin
    ky/blinky_nrf52832_xxAA_s132_6.0.0.hex --company-id 0x00000059 --application-id
    1 --application-version 2 --key-file private_key.txt --sd-req 0x009D --mesh dfu_
    test.zip
    Key file was given, setting DFU version to 0.8
    Zip created at dfu_test.zip
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>cd tools/dfu
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools\dfu>python device_page_generator.py
     -d nrf52832_xxAA -sd "s132_6.0.0"
    Wrote device page for nrf52832_xxAA with the s132_6.0.0 SoftDevice to bin/device
    _page_nrf52832_xxAA_s132_6.0.0.hex.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools\dfu>cd ..
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src\tools>cd ..
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --eraseall
    Erasing user available code and UICR flash areas.
    Applying system reset.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/softdevice/s132_nr
    f52_6.0.0_softdevice.hex --chiperase
    Parsing hex file.
    Erasing user available code and UICR flash areas.
    Applying system reset.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/bootloader/armcc/m
    esh_bootloader_serial_armcc__nrf52832_xxAA.hex
    Parsing hex file.
    ERROR: The file specified could not be found.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program bin/bootloader/armcc/m
    esh_bootloader_serial_armcc_nrf52832_xxAA.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program examples\dfu\build\dfu
    _nrf52832_xxAA_s132_6.0.0_Debug\dfu_nrf52832_xxAA_s132_6.0.0.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --program tools/dfu/bin/device_p
    age_nrf52832_xxAA_s132_6.0.0.hex
    Parsing hex file.
    Reading flash area to program to guarantee it is erased.
    Checking that the area to write is not protected.
    Programming device.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfjprog --reset
    Applying system reset.
    Run.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu serial -pkg dfu_test.zip -p C
    OM46 -b 115200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 115200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil dfu serial -pkg dfu_test.zip -p C
    OM46 -b 57600 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 38400 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 19200 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    target -> PC: e8
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 14400 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>nrfutil --verbose dfu serial -pkg dfu_tes
    t.zip -p COM46 -b 9600 -fc --mesh
    Upgrading target on COM46 with DFU package C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_sr
    c\dfu_test.zip. Flow control is enabled.
      [------------------------------------]    0%Flushing com-port...
    Opened com-port
    Starting DFU upgrade of type 4, SoftDevice size: 0, bootloader size: 0, applicat
    ion size: 1912
    Sending DFU start packet, afterwards we wait for the flash on target to be initi
    alized before continuing.
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    PC -> target: 0502aabbccdd
    
    
    Failed to upgrade target. Error is: Failed to establish connection
    
    Possible causes:
    - bootloader, SoftDevice or application on target does not match the requirement
    s in the DFU package.
    - baud rate or flow control is not the same as in the target bootloader.
    - target is not in DFU mode. If using the SDK examples, press Button 4 and RESET
     and release both to enter DFU mode.
    Closing serial port...
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>
    
    
    
    
    C:\Nordic\nrf5_SDK_for_Mesh_v2.0.1_src>

    Step 1: private_key.txt 

    -----BEGIN EC PRIVATE KEY-----
    MHcCAQEEIHPeFxystPEoiZd7uOpCqfRxyO69QavgEeIowj7u+fp2oAoGCCqGSM49
    AwEHoUQDQgAE146icosxxjsYVAL0IJgDtHjQgosCoPRNqfXXgrBH/kW2C/TbLlcr
    S2BTwMfpNxswnJPuU8MAkGr8bH8tmc4RzQ==
    -----END EC PRIVATE KEY-----
    

    Step 2: bootloader_config_default.json 

    {
        "bootloader_config": {
            "bootloader_id": 1,
            "bootloader_version": 1,
            "company_id": 89,
            "application_id": 1,
            "application_version": 1,
    		"public_key": 
    	"d78ea2728b31c63b185402f4209803b478d0828b02a0f44da9f5d782b047fe45b60bf4db2e572b4b6053c0c7e9371b309c93ee53c300906afc6c7f2d99ce11cd"	
    	
        }
    }
    

    Step 3: dfu_test.zip dfu_test.zip

    Step 4: Modified  dfu_nrf52832_xxAA_s132_6.0.0.py from 5.0.0 to 6.0.0 

    # Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are met:
    #
    # 1. Redistributions of source code must retain the above copyright notice, this
    #    list of conditions and the following disclaimer.
    #
    # 2. Redistributions in binary form must reproduce the above copyright
    #    notice, this list of conditions and the following disclaimer in the
    #    documentation and/or other materials provided with the distribution.
    #
    # 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    #    contributors may be used to endorse or promote products derived from this
    #    software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    # IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
    # ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
    # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    # POSSIBILITY OF SUCH DAMAGE.
    
    import argparse
    import enum
    import struct
    import intelhex
    import sys
    import json
    import os
    
    PACKAGE_PARENT = '..'
    SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
    sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))
    
    from deviceutil.deviceutil import \
        get_application_limits, \
        make_bootloader_for_platforms, \
        set_softdevices_for_platforms, \
        load_softdevies, \
        load_platforms
    
    WORD_SIZE = 4
    
    
    class BLInfoType(enum.IntEnum):
        INVALID = 0x00
        ECDSA_PUBLIC_KEY = 0x01
        VERSION = 0x02
        JOURNAL = 0x03
        FLAGS = 0x04
        SEGMENT_SD = 0x10
        SEGMENT_BL = 0x11
        SEGMENT_APP = 0x12
        LAST = 0x7FFF
    
    
    class DevicePageEntry(object):
        def __init__(self, bl_info_type, data):
            #print("Type: ", type(data).__name__)
            if not (isinstance(bl_info_type, BLInfoType) and
                    (isinstance(data, bytearray) or isinstance(data, str))):
                raise TypeError("Invalid type %r" % (type(data)))
    
            self.bl_info_type = bl_info_type
            if (isinstance(data, str)):
               data = bytearray.fromhex(data)
            self.data = self.pad(data)
    
        @property
        def word_count(self):
            return (len(self.data) + WORD_SIZE) // WORD_SIZE
    
        def pad(self, data):
            pad_byte_count = (WORD_SIZE - len(data) % WORD_SIZE) % WORD_SIZE
            if pad_byte_count > 0:
                data += bytearray([0xFF] * pad_byte_count)
            return data
    
        def serialize(self):
            return (bytearray(struct.pack('<HH', self.word_count, self.bl_info_type)
                              + self.data))
    
    
    class DevicePage(object):
        def __init__(self, platform, softdevice, bootloader_config):
            self.entries = []
            self.generate_entries(platform, softdevice, bootloader_config)
            self.platform = platform
            self.softdevice = softdevice
    
        def generate_entries(self, platform, softdevice, bootloader_config):
            public_key = bytearray.fromhex(bootloader_config["public_key"]) \
                         if "public_key" in bootloader_config else None
            if public_key:
                self.entries.append(
                    DevicePageEntry(BLInfoType.ECDSA_PUBLIC_KEY, public_key))
    
            app_limits = get_application_limits(platform, softdevice)
            app_segment = bytearray(struct.pack("<II",
                                                app_limits["flash_start"],
                                                app_limits["flash_size"]))
            sd_segment = bytearray(struct.pack("<II",
                                               softdevice["flash_start"],
                                               softdevice["flash_size"]))
            bl_segment = bytearray(struct.pack("<II",
                                               platform["bootloader"]["flash_start"],
                                               platform["bootloader"]["flash_size"]))
    
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_APP, app_segment))
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_SD, sd_segment))
            self.entries.append(
                DevicePageEntry(BLInfoType.SEGMENT_BL, bl_segment))
    
            version_data = bytearray(struct.pack("<HBBIHI",
                                                 int(softdevice["version"], 16),
                                                 bootloader_config["bootloader_id"],
                                                 bootloader_config["bootloader_version"],
                                                 bootloader_config["company_id"],
                                                 bootloader_config["application_id"],
                                                 bootloader_config["application_version"]))
    
            #print(version_data)
            self.entries.append(DevicePageEntry(BLInfoType.VERSION,
                                                version_data))
    
            self.entries.append(DevicePageEntry(BLInfoType.FLAGS,
                                                bytearray(struct.pack('I', 0xFFFFFFFF))))
    
        def write_hex(self, hexfile):
            # Info page metadata
            raw_data = bytearray(struct.pack("<BBBB", 4, 1, 8, 8))
            raw_data += bytearray().join(map(DevicePageEntry.serialize, self.entries))
            raw_data += bytearray(struct.pack("<HH", 0xFFFF, BLInfoType.LAST))
            hex_output = intelhex.IntelHex()
            hex_output.frombytes(raw_data,
                                 self.platform["flash_size"] - self.platform["page_size"])
            hex_output.tofile(hexfile, "hex")
    
    
    def write_specific_page(platforms, softdevices, args):
        platform = next((p for p in platforms if args.device == p["name"]), None)
        if not platform:
            print("Unknown device: \"%s\" in list %r" % (args.device, [p["name"] for p in platforms]))
            sys.exit(1)
    
        softdevice = next((s for s in softdevices if args.softdevice == s["name"]), None)
        if not softdevice:
            print("Unknown SoftDevice: \"%s\"" % (args.softdevice))
            sys.exit(1)
    
        if args.softdevice not in platform["softdevices"]:
            print("Unknown SoftDevice \"%s\" for platform \"%s\"" %
                  (args.softdevice, args.device))
            sys.exit(1)
    
        # Filter out the others...
        platforms = [p for p in platforms
                     if args.device.lower() in p["name"].lower()]
    
        make_bootloader_for_platforms(platforms)
        set_softdevices_for_platforms(platforms, softdevices)
    
        # Dict is updated by reference
        # platform = platforms[args.device]
        # softdevice = softdevices[args.softdevice]
    
        with open(args.bootloader_config, "r") as f:
            bootloader_config = json.load(f)["bootloader_config"]
        device_page = DevicePage(platform, softdevice, bootloader_config)
        if not args.output_file:
            args.output_file = "_".join(["device_page",
                                         self.platform["name"],
                                         self.softdevice["name"]]) + ".hex"
    
        device_page.write_hex(args.output_file)
    
    
    def write_all(platforms, softdevices, args):
        make_bootloader_for_platforms(platforms)
        set_softdevices_for_platforms(platforms, softdevices)
    
        with open(args.bootloader_config, "r") as f:
            bootloader_config = json.load(f)["bootloader_config"]
    
        for platform in platforms:
            for softdevice in platform["softdevices"]:
                device_page = DevicePage(platform, softdevice, bootloader_config)
                device_page.write_hex(args.output_file)
    
    
    def main():
        softdevices = load_softdevies("../configuration/softdevices.json")
        platforms = load_platforms("../configuration/platforms.json")
        sd_str = ''
        for sd in softdevices:
            sd_str += ''.join(sd["name"]) + "\n"
        plt_str = ''
        for plt in platforms:
            plt_str += ''.join(plt["name"]) + '\n'
    
        SOFTDEVICE = "s132_6.0.0"
        DEVICE = "nrf52832_xxAA"
        parser = argparse.ArgumentParser(description="Device Page Generator")
        parser.add_argument("-d", "--device", help="Select device: " + ''.join(plt_str),
                            default=DEVICE)
        parser.add_argument("-sd", "--softdevice", help="Select SoftDevice: "  + ''.join(sd_str),
                            default=SOFTDEVICE)
        parser.add_argument("-c", "--bootloader-config",
                            default="bootloader_config_default.json",
                            help="Bootloader configuration file")
        parser.add_argument("-o", "--output-file", help="Output hex file",
                            default="bin/device_page_%s_%s.hex" % (DEVICE, SOFTDEVICE))
        parser.add_argument("--all", default=False, action="store_true",
                            help=("Writes all known device page combinations to "
                                  + "\'bin/\'"))
        args = parser.parse_args()
    
        dirname = os.path.dirname(args.output_file)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
    
        if args.all:
            write_all(platforms, softdevices, args)
            print("Wrote for device pages for all devices.")
        elif args.softdevice and args.device:
            write_specific_page(platforms, softdevices, args)
            print("Wrote device page for %s with the %s SoftDevice to %s." %
                  (args.device, args.softdevice, args.output_file))
    
    
    if __name__ == "__main__":
        main()
    

    to generate 

     device_page_nrf52832_xxAA_s132_6.0.0.hex device_page_nrf52832_xxAA_s132_6.0.0.hex

    Step 6: s132_nrf52_6.0.0_softdevice.hex s132_nrf52_6.0.0_softdevice.hex

    Step 7: s132_nrf52_6.0.0_softdevice.hex mesh_bootloader_serial_armcc_nrf52832_xxAA.hex

    Step 8: Program device using nrfjprog  to download dfu_nrf52832_xxAA_s132_6.0.0.hex dfu_nrf52832_xxAA_s132_6.0.0.hexdfu_nrf52832_xxAA_s132_6.0.0.map

     

    Step 9: Program device_page_nrf52832_xxAA_s132_6.0.0.hex device_page_nrf52832_xxAA_s132_6.0.0.hex 

    Step 10: We tried difference Baud Rates, press Button 4 and RESET and release both to enter DFU mode and use s132 and version 6.0.0, still got

    "Error is: Failed to establish connection"

     

    Please advise.  Thanks.

  • I got a few tips from a Mesh developer here at Nordic:

    "The original issue seems to be an error in the json file. Looks like there is an extra "}" at the end, maybe.

    Next, is the customer sure that the com port used is the correct com port?

    The SEGGER DFU build had a known issue with the flash_placement.xml file. I would advise the customer to use some of the pre-compiled binaries to test the DFU first."

    But I believe you have fixed the first issue, correct? I also believe you are using the correct com port & I believe you have used the pre-compiled binaries & not your own built hex files.

    I am not sure these tips will help all too much, but it's worth giving it a shot!

  • 1) Update: I have tried to erase the chip, program the softdevice to the nrf52 & then program the blinky hex file that is updated during the dfu process & no LEDs are blinking. Update2: The precompiled blinky hex file works fine. First off, you must program the softdevice before programming the blinky hex file. Secondly, you must reset the board before it starts working (i.e. nrfjprog --reset). I believe the dfu worked fine, only that I was stupid enough not reset the board at the end of the DFU. I will double check this.

    2) The serial number is the number on top of the interface MCU on the dev kit. It's the number on the white sticker on the bottom which I believe always is 9 digits long.

    3) The only reason I used Mesh SDK v2.0.0 & SD v5 was because you used this setup in your original question. I would recommend you to use the latest SDK & Softdevice. Not sure exactly why I used the v5 softdevice.

    4) If you want to use mesh sdk v2.0.1 & softdevice 6, I do not believe you need to use the cmake command to generate a new SES project (I believe this was only the case because the ses dfu mesh bootloader project used softdevice 5 in mesh sdk v2.0.0, whereas we wanted it to use v6 softdevice.)

    To answer your question: Yes, I believe you need the .. at the end of the cmake command. The reason it is not working is because you need to make a build folder inside the root folder of the mesh sdk (i.e. where examples, mesh, models & all other folders are located). Then, inside the build folder, you can run the command you posted in your question. If you look at the cmake infocenter doc, you notice that there is a "build$" in front of the cmake command. This will then build an examples folder inside the build folder which does not contain the SES project files (I do not know why this happens). What you will notice though is that the examples inside the root mesh sdk folder do get updated.

    5) Here is more info about building the mesh stack. Normally, you can just open a Segger Embedded Studio project & compile to build the mesh stack. You can use cmake if you cannot find a SES project for your device or softdevice version. 

    Regarding the question about doing a dfu with sdk 15 & mesh sdk v2.0.1 combined, this should be doable. Would you only need to update the application? If you want to do a dfu of all of the nodes in the mesh network, you could use the dfu bootloader from the dfu example in the mesh sdk.

  • I used other blinky example file and Mesh SDK v2.0.1 & softdevice 6, device was programmed and LEDs were ON. Thanks for the advices. But when I verified the bootloader, it was stuck at “Resetting device ..”, please see attached cmd_script 

    C:\Users\advanchip>cd C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.0_src_support\tools\dfu
    
    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.0_src_support\tools\dfu>python bootloader_verify.py 682630616 COM3
    Device family:                  NRF52
    Reading UICR..                  OK.
    Reading Device page..           OK.
    Resetting device..
    

    which is difference from DFU quick start guide, please see screen shoot. 

    For Cmake, I created a Build folder using mkdir and still got the same error.

    CMake Error: CMake was unable to find a build program corresponding to "Ninja".

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src_CMake>mkdir build
    
    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src_CMake>cd build
    
    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src_CMake\build>cmake -G Ninja ..
    -- Configuring CMake for nRF5 SDK for Bluetooth Mesh 2.0.1
    CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
    -- Configuring incomplete, errors occurred!
    See also "C:/Nordic_SES/nrf5_SDK_for_Mesh_v2.0.1_src_CMake/build/CMakeFiles/CMakeOutput.log".
    
    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src_CMake\build>
    

    Please advise.  Thanks.

  • Have you tried using the bootloader_verify.py file from mesh sdk v2.0.1? Do you still receive the same error then? Did you make sure to run an nrfjprog --reset running the python script? This may help.

    Regarding ninja, I believe you can run the command: pip install Ninja or pip install ninja

    As far as I am aware though, for your use case, you will not need to use cmake unless you want a different segger project for a different device.

  • I successfully built file using cmake.  Thank you very much.

    Yes, I used the bootloader_verify.py file from mesh sdk v2.0.1, please see attached directory folder of bootloader_verify.py 

    # Copyright (c) 2010 - 2018, Nordic Semiconductor ASA
    # All rights reserved.
    #
    # Redistribution and use in source and binary forms, with or without
    # modification, are permitted provided that the following conditions are met:
    #
    # 1. Redistributions of source code must retain the above copyright notice, this
    #    list of conditions and the following disclaimer.
    #
    # 2. Redistributions in binary form must reproduce the above copyright
    #    notice, this list of conditions and the following disclaimer in the
    #    documentation and/or other materials provided with the distribution.
    #
    # 3. Neither the name of Nordic Semiconductor ASA nor the names of its
    #    contributors may be used to endorse or promote products derived from this
    #    software without specific prior written permission.
    #
    # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    # IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
    # ARE DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
    # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    # POSSIBILITY OF SUCH DAMAGE.
    
    import binascii
    import subprocess
    import shlex
    import sys
    import serial
    import time
    
    def get_device_family(serial_number):
        family = {
            '480': 'NRF51',
            '680': 'NRF51',
            '681': 'NRF51',
            '682': 'NRF52',
        }
        if not serial_number[:3] in family:
            return 'NRF51' # fallback to 51.
        else:
            return family[serial_number[:3]]
    
    def read_serial_event(s):
        evt = ""
        while True:
            length = s.read()
            if ord(length) > 0:
                evt = s.read(ord(length))
                return evt
    
    
    
    def print_usage():
        print("")
        print("Usage:\tbootloader_verify.py <Segger serial-number> <COM-port>")
    
    def nrfjprog(args):
        process = subprocess.Popen(shlex.split("nrfjprog " + args), stdout=subprocess.PIPE)
        out, err = process.communicate()
        if process != None and process.returncode == 2:
            print("Couldn't find nrfjprog, exiting.")
            exit(2)
        if process == None or process.returncode != 0:
            print("Error calling nrfjprog with arguments " + args + ".")
            print(out)
            exit(2)
        return out
    
    def read_uicr(serial_number):
        family = get_device_family(serial_number)
        sys.stdout.write("Device family:\t\t\t" + family + "\n")
        sys.stdout.write("Reading UICR..\t\t\t")
        read = nrfjprog("-s " + serial_number + " --memrd 0x10001014 --n 4 --w 32 --family " + family).strip()
        bootloader_addr = str(read).split()[1]
        if bootloader_addr == "FFFFFFFF":
            print("ERROR: UICR NOT SET.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            exit(1)
    
        read = nrfjprog("-s " + serial_number + " --memrd 0x" + bootloader_addr + " --n 4 --w 32 --family " + family).strip()
        bootloader_vector_pointer = str(read).split()[1]
        if bootloader_vector_pointer < "20000000":
            print("ERROR: Bootloader vector pointer invalid.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        if bootloader_vector_pointer == "FFFFFFFF":
            print("ERROR: Bootloader not present.")
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDid you flash the Softdevice BEFORE the bootloader?")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        print("OK.")
        return bootloader_addr
    
    def read_device_page(serial_number):
        family = get_device_family(serial_number)
        # need to know the flash size to get the device page. Can read this from the FICR:
        ficr = str(nrfjprog("-s " + serial_number + " --memrd 0x10000010 --n 8 --w 32 --family " + family).strip()).split()[1:]
        code_page_size = int(ficr[0], 16)
        code_page_count = int(ficr[1], 16)
        device_page_location = code_page_size * (code_page_count - 1)
    
        sys.stdout.write("Reading Device page..\t\t")
        device_page = nrfjprog("-s " + serial_number + " --memrd " + hex(device_page_location) + " --n 4 --w 32 --family " + family).strip()
        device_page_header = str(device_page).split()[1]
        if device_page_header == "FFFFFFFF":
            print("ERROR: DEVICE PAGE NOT PRESENT.")
            print("Checkpoints:")
            print("\tHave you flashed the device page?")
            exit(1)
        if device_page_header != "08080104":
            print("ERROR: DEVICE PAGE INVALID.")
            print("Checkpoints:")
            print("\tDid you erase the device before programming all the hex-files?")
            exit(1)
        print("OK.")
        return device_page_header
    
    def reset_device(serial_number, port):
        sys.stdout.write("Resetting device..\t\t")
        try:
            s = serial.Serial(port, 115200, rtscts = True)
        except:
            print("ERROR: Could not open COM port " + port)
            exit(1)
        family = get_device_family(serial_number)
        nrfjprog("-s " + serial_number + " --reset --family " + family)
        time.sleep(0.2)
        response = read_serial_event(s)
    
        if b"\x81\x02\x00" == response[:3]:
            print("OK (In application)")
        elif not b"\x81\x01\x00" in response:
            print("ERROR: Invalid start sequence from bootloader: " + binascii.hexlify(response))
            print("Checkpoints:")
            print("\tHave you flashed the bootloader with nrfjprog?")
            print("\tDoes your bootloader have serial communication enabled?")
            s.close()
            exit(1)
        else:
            print("OK.")
        time.sleep(0.1)
        s.close()
    
    def echo(port):
        sys.stdout.write("Checking serial connection..\t")
        try:
            s = serial.Serial(port, 115200, rtscts = True)
        except:
            print("ERROR: Could not open COM port " + port)
            exit(1)
        s.write(b"\x03\x02\xaa\xbb")
        time.sleep(0.1)
        if not s.read(4).startswith(b"\x03\x82\xaa\xbb"):
            print("ERROR: Invalid response!")
            print("Checkpoints:")
            s.close()
            exit(1)
        s.close()
        print("OK.")
    
    if __name__ == "__main__":
        if len(sys.argv) < 2:
            print("Please provide the serial number of your device")
            print_usage()
            exit(1)
        if len(sys.argv) < 3:
            print("Please provide the COM port of your device")
            print_usage()
            exit(1)
        try:
            int(sys.argv[1])
        except:
            print("Invalid serial number " + sys.argv[1])
            print_usage()
            exit(1)
    
        bootloader_addr = read_uicr(sys.argv[1])
        read_device_page(sys.argv[1])
        reset_device(sys.argv[1], sys.argv[2])
        echo(sys.argv[2])
    
        print("\nBootloader verification OK.")
    

    When I ran python bootloader_verify.py 682630616 COM3, it was get stuck in

    Resetting device..

    and didn't go anywhere.  The Command Prompt won't accept any command, please see attached screen shoot.  

    Please advise.  Thanks.

  • I have two tips: add some prints (i.e. sys.stdout.write("...")) in the bootloader_verify.py script to see where the error is occurring and/or try the whole dfu getting started process again. Most likely there is some small mistake you are making somewhere that is leading to this issue (e.g. running mesh_bootloader_gccarmemb instead of mesh_bootloader_serial_gccarmemb). I have tested this example again with three nrf52832 dev kits & the blinky dfu worked.

    I have had one issue with the COM port, so it might also be worthwhile to try a different usb port or try running the python bootloader_verify.py script on another one of your devices.

Reply
  • I have two tips: add some prints (i.e. sys.stdout.write("...")) in the bootloader_verify.py script to see where the error is occurring and/or try the whole dfu getting started process again. Most likely there is some small mistake you are making somewhere that is leading to this issue (e.g. running mesh_bootloader_gccarmemb instead of mesh_bootloader_serial_gccarmemb). I have tested this example again with three nrf52832 dev kits & the blinky dfu worked.

    I have had one issue with the COM port, so it might also be worthwhile to try a different usb port or try running the python bootloader_verify.py script on another one of your devices.

Children
  • It worked in my other computer now.

    I tried both

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\gccarmemb\ mesh_bootloader_serial_gccarmemb_nrf52832_xxAA.hex

    And

    C:\Nordic_SES\nrf5_SDK_for_Mesh_v2.0.1_src\bin\bootloader\armcc\ mesh_bootloader_serial_armcc_nrf52832_xxAA.hex

    What is the difference between gccarmemb and armcc?

    Now it works using serial port, but my goal is updating firmware on mesh devices without using any cable connection as stated in the DFU quick start guide.

    I tried to use -s <serial number> on another module, but nothing happened.  Please specify which steps I should add -s <serial number>.  

    Please advise.  Thanks.

  • I followed the DFU quick start guide using 2 development kits, where one (682630616) is interfaced over the COM port, which is the one we have been using to check out from Step 1 to Step 10.  Now I am using the other development kits (682686733) receives the DFU from the first device (682630616) over the mesh.  According to the DFU quick start guide, I specified which device to use in which context, add the -s 682686733 option for each call to the nrfjprog command.  Therefore, we started to communicate with 682686733 starting Step 5 to Step 9 as below:

    Step 5 Erase all chip memory (including UICR) on all devices
    nrfjprog --eraseall -s 682686733

    Step 6 Flash the SoftDevice on all devices
    nrfjprog --program bin/softdevice/s132_nrf52_6.0.0_softdevice.hex --chiperase -s 682686733

    Step 7 Flash the serial bootloader on all devices
    nrfjprog --program bin/bootloader/gccarmemb/mesh_bootloader_serial_gccarmemb_nrf52832_xxAA.hex -s 682686733

    Step 8 Flash the first application on all devices
    nrfjprog --program examples\dfu\build\dfu_nrf52832_xxAA_s132_6.0.0_Release\dfu_nrf52832_xxAA_s132_6.0.0.hex -s 682686733

    Step 9 Flash the device page on all devices
    nrfjprog --program tools/dfu/bin/device_page_nrf52832_xxAA_s132_6.0.0.hex -s 682686733

    nrfjprog --reset -s 682686733

    Every Step, I got an error:
    ERROR: There is no debugger connected to the PC with the given serial number.

    Please see below attached screen shoot.

     

    Do we need to connect the other development kit 682686733 to the PC?  How can we do it over the mesh or over the air?

    According to the DFU quick start guide, I also downloaded the mesh_dfu branch as shown at below screen shoot, but I don't know how to use it. 

    Please advise.  Thanks.

  • I used gcc armemb. gcc armemb uses the GCC ARM compiler & armcc uses the compiler provided by keil. You need to add the nrfjprog -s command to all of the nrfjprog commands in this quick start guide.

    But what I do instead, which I find easier, is to just write the nrfjprog commands without the -s at the back. That way, you should get a popup with a list of all the segger IDs if you have attached multiple DKs. If you only have one connected, the nrfjprog command will run without any errors. Then, you can choose the segger ID that you want to use.

  • I'm facing a problem in step 4 when i need to generate a hex version of device page, i did this : 

    dfu$ py device_page_generator.py -d nrf52832_xxAA -sd "s132_6.0.0"

    and this is the result

    Wrote device page for nrf53832_xxAA with the s132_6.0.0 SoftDevice to bin/device_page_nrf52832_xxAA_s132_5.0.0.hex instead of s132 version 6 

    here is the bin directory 

    I don't know why it doesn't generate device page with s132 v6.0.0, help please 

  • Hi could you please open a new case regarding this.

Related