nrf52840 S140 Central DFU Bluetooth Zephyr 2.0.0 nrf52840 peripheral

We have nrf52840 S140 BLE Central device that currently connects to TI based sensors. I have implemented code that can upgrade those TI sensors' firmware using the TI BLE protocol.

Now we are developing our own BLE peripheral sensors also based on the nrf52840 but now using the newly supported Zephyr 2.0.0. RF connect stuff. I can update the sensors using the Nordic Android program (unauthenticated for now) and now need to implement upgrading BLE DFU using our central device which connects to a cellular gateway.

I do not want to reinvent the wheel, writing existing code, like I had to do with the TI sensors.

Could you point me to code that allows a Central device to update a peripheral device BLE DFU?

If not where can I look to reinvent another wheel?

Thanks David

Parents
  • Hi David,

    I did not change Simons list function.

    It worked as is. But I have not tried to upload a new image yet, meaning only 1 image lives on the device.
    It only lists 1 slot in this case. I suspect it will list 2 slots if I upload an image to the secondary slot.

    I will let you know when I have tested this.

    Regards,
    Sigurd Hellesvik

  • I am able to use Simons sample to upload images in v2.0.0.

    However, it fails in v2.2.0, and I have not been able to figure out why yet.

    Regards,
    Sigurd Hellesvik

  • DavidKaplan said:

    I cannot see any bootloader mcuboot  information in the nRF9160 RTT log.

    So How did you get it? 

    What am I doing wrong?

    Aha, this was a misunderstanding.

    Since working with the Development Kit, I used UART for logging.

    I have used RTT for logging from the Bootloader before, but I remember it to be unstable.
    Whether you want to continue trying to make Bootloader RTT work is up to you.

    Have you been able to update the peripheral using the changes I made to the SMP Client?

    Regards,
    Sigurd Hellesvik

  • Sorry but for some reason I could not get the nRF9160-Dk 's nrf52840 to output anything on its uart.

    According to the documentation, it should output on VCOM1 using uart TX P0.3 & RX P0.5.

    # ----------------------------------------
    # USE Uart Instead of RTT
    # ----------------------------------------
    CONFIG_UART_CONSOLE=y
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_SERIAL=y
    # ----------------------------------------
    # Enable UART console, for printk()
    # ----------------------------------------
    CONFIG_CONSOLE_HANDLER=n
    CONFIG_CONSOLE=y
    CONFIG_PRINTK=y
    
    # ----------------------------------------
    # USE RTT  Instead of Uart
    # ----------------------------------------
    #CONFIG_CONSOLE=y
    #CONFIG_RTT_CONSOLE=y
    #CONFIG_USE_SEGGER_RTT=y
    #CONFIG_LOG_BACKEND_RTT=y
    

    What am I missing?

    Could you just post your board files?

    Also, on my central zephyr v2.2.0 complains about not using pin ctrl for the uart.

    I added the ms88sf2-pinctrl.dtsi file which I included in ms88sf2.dts

    &uart1 {
    	status = "okay";
    	current-speed = <115200>;
    	pinctrl-0 = <&uart1_default>;
    	pinctrl-1 = <&uart1_sleep>;
    	pinctrl-names = "default", "sleep";
    };
    

    &pinctrl {
    	uart1_default: uart1_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 3)>,
    				<NRF_PSEL(UART_RTS, 1, 8)>;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_RX, 0, 5)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			bias-pull-up;
    		};
    	};
    
    	uart1_sleep: uart1_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 3)>,
    				<NRF_PSEL(UART_RX, 0, 5)>,
    				<NRF_PSEL(UART_RTS, 1, 8)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			low-power-enable;
    		};
    	};
    
    };
    

                     from C:\ncs\v2.2.0\zephyr\drivers\serial\uart_nrfx_uarte.c:11:
    C:\ncs\v2.2.0\zephyr\include\zephyr\toolchain\gcc.h:77:36: error: static assertion failed: "/soc/uart@40028000 defined without required pin configuration"
       77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
          |                                    ^~~~~~~~~~~~~~
    c:\ncs\v2.2.0\zephyr\soc\arm\nordic_nrf\common\soc_nrf_common.h:218:9: note: in expansion of macro 'BUILD_ASSERT'
      218 |         BUILD_ASSERT((IS_ENABLED(CONFIG_PINCTRL) &&                     \
          |         ^~~~~~~~~~~~
    C:\ncs\v2.2.0\zephyr\drivers\serial\uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'NRF_DT_CHECK_PIN_ASSIGNMENTS'
     2080 |         NRF_DT_CHECK_PIN_ASSIGNMENTS(UARTE(idx), 1,                            \
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:\ncs\v2.2.0\zephyr\drivers\serial\uart_nrfx_uarte.c:2189:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
     2189 | UART_NRF_UARTE_DEVICE(1);
          | ^~~~~~~~~~~~~~~~~~~~~
    C:\ncs\v2.2.0\zephyr\include\zephyr\toolchain\gcc.h:77:36: error: static assertion failed: "/soc/uart@40028000 has pinctrl states defined although PINCTRL is not enabled"
       77 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)
          |                                    ^~~~~~~~~~~~~~
    c:\ncs\v2.2.0\zephyr\soc\arm\nordic_nrf\common\soc_nrf_common.h:234:9: note: in expansion of macro 'BUILD_ASSERT'
      234 |         BUILD_ASSERT(IS_ENABLED(CONFIG_PINCTRL) ||                      \
          |         ^~~~~~~~~~~~
    C:\ncs\v2.2.0\zephyr\drivers\serial\uart_nrfx_uarte.c:2080:9: note: in expansion of macro 'NRF_DT_CHECK_PIN_ASSIGNMENTS'
     2080 |         NRF_DT_CHECK_PIN_ASSIGNMENTS(UARTE(idx), 1,                            \
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:\ncs\v2.2.0\zephyr\drivers\serial\uart_nrfx_uarte.c:2189:1: note: in expansion of macro 'UART_NRF_UARTE_DEVICE'
     2189 | UART_NRF_UARTE_DEVICE(1);
          | ^~~~~~~~~~~~~~~~~~~~~

  • DavidKaplan said:
    What am I missing?

    To test UART logging from the nRF52840 on the nRF9160, do the following:

    1. Go to zephyr/samples/hello_world.
    2. Build for "nrf9160dk_nrf52840".
    3. Flip the switch on nRF9160DK to nRF52.
    4. Program.
    5. Connect a serial terminal to VCOM1 and see it log "Hello World ..."

    I did this, and it printed for me.

    DavidKaplan said:
    Could you just post your board files?

    I just used the default board files for the DKs; see Zephyr arm boards.
    For the nRF52840DK, I used nrf52840dk_nrf52840.

    Regards,
    Sigurd Hellesvik

  • OK, I flashed my sensor code using the "nrf9160dk_nrf52840" build and then tried to DFU from my Central with the image streamed and the Central got OK from the nRF9160 dk sensor as I received before.

    Central log:

    02-28 11:23 28/02/2023 09:23:36 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 675] DFU:317200/319026 400
    02-28 11:23 28/02/2023 09:23:36 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 675] DFU:317600/319026 400
    02-28 11:23 28/02/2023 09:23:36 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 675] DFU:318000/319026 400
    02-28 11:23 28/02/2023 09:23:36 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 675] DFU:318400/319026 400
    02-28 11:23 28/02/2023 09:23:36 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 675] DFU:318800/319026 226
    02-28 11:23 28/02/2023 09:23:37 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 789] ImageChecksum AF3A0C7A
    02-28 11:23 28/02/2023 09:23:37 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c: 927] SMP UploadOK
    02-28 11:23 28/02/2023 09:23:37 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c:1208] ImageList
    02-28 11:23 28/02/2023 09:23:37 |  27/02/2023 23:23:14[.ami_vibe.c:1941] ...[ami_smp.c:1211] ImageTest
    02-28 11:23 28/02/2023 09:23:38 |  27/02/2023 23:23:15[.ami_vibe.c:1941] ...[ami_smp.c:1214] ImageReset
    02-28 11:23 28/02/2023 09:23:38 |  27/02/2023 23:23:16[.ami_vibe.c:1941] ...[ami_ble.c:2639] DFUConnectFinishedErr:0
    

    nRF9160-DK log where I used the programmer at the start to perform a reset.

    [00:01:38.147,705] <ESC><err> mpsl_init: m_assert_handler: MPSL ASSERT: 112, 2195<ESC><CR><LF>
    [00:01:38.155,456] <ESC><err> os: hard_fault: ***** HARD FAULT *****<ESC><CR><LF>
    [00:01:38.162,109] <ESC><err> os: hard_fault:   Fault escalation (see below)<ESC><CR><LF>
    [00:01:38.169,433] <ESC><err> os: hard_fault: ARCH_EXCEPT with reason 3<LF>
    <ESC><CR><LF>
    [00:01:38.176,452] <ESC><err> os: esf_dump: r0/a1:  0x00000003  r1/a2:  0x00000000  r2/a3:  0x00000000<ESC><CR><LF>
    [00:01:38.186,065] <ESC><err> os: esf_dump: r3/a4:  0x20003f54 r12/ip:  0x00000000 r14/lr:  0x0003a413<ESC><CR><LF>
    [00:01:38.195,678] <ESC><err> os: esf_dump:  xpsr:  0x41000018<ESC><CR><LF>
    [00:01:38.201,843] <ESC><err> os: esf_dump: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000<ESC><CR><LF>
    [00:01:38.213,226] <ESC><err> os: esf_dump: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000<ESC><CR><LF>
    [00:01:38.224,609] <ESC><err> os: esf_dump: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000<ESC><CR><LF>
    [00:01:38.235,992] <ESC><err> os: esf_dump: s[12]:  0x00000000  s[13]:  0x00000002  s[14]:  0x00000000  s[15]:  0x00000000<ESC><CR><LF>
    [00:01:38.247,344] <ESC><err> os: esf_dump: fpscr:  0x00000100<ESC><CR><LF>
    [00:01:38.253,479] <ESC><err> os: esf_dump: Faulting instruction address (r15/pc): 0x0002f618<ESC><CR><LF>
    [00:01:38.262,298] <ESC><err> os: z_fatal_error: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0<ESC><CR><LF>
    [00:01:38.271,331] <ESC><err> os: z_fatal_error: Fault during interrupt handling<LF>
    <ESC><CR><LF>
    [00:01:38.279,113] <ESC><err> os: z_fatal_error: Current thread: 0x20002ca8 (unknown)<ESC><CR><LF>
    [00:01:38.287,261] <ESC><err> fatal_error: k_sys_fatal_error_handler: Resetting system<ESC><CR>
    [00:00:00.252,288] <ESC><inf> board_control: vcom0_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.259,155] <ESC><inf> board_control: vcom2_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.266,052] <ESC><inf> board_control: led1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.272,796] <ESC><inf> board_control: led2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.279,541] <ESC><inf> board_control: led3_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.286,254] <ESC><inf> board_control: led4_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.292,999] <ESC><inf> board_control: switch1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.299,987] <ESC><inf> board_control: switch2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.306,976] <ESC><inf> board_control: button1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.313,995] <ESC><inf> board_control: button2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.320,983] <ESC><inf> board_control: nrf_interface_pins_0_2_routing is disabled<ESC><CR><LF>
    [00:00:00.329,040] <ESC><inf> board_control: nrf_interface_pins_3_5_routing is disabled<ESC><CR><LF>
    [00:00:00.337,097] <ESC><inf> board_control: nrf_interface_pins_6_8_routing is disabled<ESC><CR><LF>
    [00:00:00.345,123] <ESC><inf> board_control: Board configured.<ESC><CR><LF>
    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.355,041] <ESC><inf> mcuboot: Starting bootloader<ESC><CR><LF>
    [00:00:00.360,992] <ESC><inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.370,971] <ESC><inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.381,072] <ESC><inf> mcuboot: Boot source: none<ESC><CR><LF>
    [00:00:00.386,474] <ESC><inf> mcuboot: Swap type: none<ESC><CR><LF>
    [00:00:00.460,571] <ESC><inf> mcuboot: Bootloader chainload address offset: 0xc000<ESC><CR><LF>
    [00:00:00.468,139] <ESC><inf> mcuboot: Jumping to the first image slot<ESC><CR>
    ÿ[00:00:00.000,152] <ESC><inf> board_control: init: vcom0_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.007,568] <ESC><inf> board_control: init: vcom2_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.015,014] <ESC><inf> board_control: init: led1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.022,277] <ESC><inf> board_control: init: led2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.029,541] <ESC><inf> board_control: init: led3_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.036,804] <ESC><inf> board_control: init: led4_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.044,067] <ESC><inf> board_control: init: switch1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.051,605] <ESC><inf> board_control: init: switch2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.059,143] <ESC><inf> board_control: init: button1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.066,650] <ESC><inf> board_control: init: button2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.074,188] <ESC><inf> board_control: init: nrf_interface_pins_0_2_routing is disabled<ESC><CR><LF>
    [00:00:00.082,763] <ESC><inf> board_control: init: nrf_interface_pins_3_5_routing is disabled<ESC><CR><LF>
    [00:00:00.091,339] <ESC><inf> board_control: init: nrf_interface_pins_6_8_routing is disabled<ESC><CR><LF>
    [00:00:00.099,914] <ESC><inf> board_control: init: Board configured.<ESC><CR><LF>
    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.110,412] <ESC><inf> mcumgr_zephyr_grp: zephyr_basic_mgmt_init: Registering Zephyr basic mgmt group<ESC><CR><LF>
    00/00/0000 00:00:00[ami_main.c: 631] Startup<CR><LF>
    00/00/0000 00:00:00[ami_cfg.c: 256] DeviceID:0<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 448] MainInitErr:4096<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 657] VaporBLE#0 26-Feb-2023 v1.0.0 1.0 2.26<CR><LF>
    build time: Feb 28 2023 11:08:57<CR><LF>
    [00:00:00.245,910] <ESC><inf> sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision: <CR><LF>
                                             6d 90 41 2a 38 e8 ad 17  29 a5 03 38 39 27 d7 85 |m.A*8... )..89'..<CR><LF>
                                             1f 85 d8 e1                                      |....             <ESC><CR><LF>
    [00:00:00.276,824] <ESC><inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)<ESC><CR><LF>
    [00:00:00.285,797] <ESC><inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)<ESC><CR><LF>
    [00:00:00.293,518] <ESC><inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 109.16784 Build 2917677098<ESC><CR><LF>
    [00:00:00.306,365] <ESC><inf> bt_hci_core: bt_init: No ID address. App must call settings_load()<ESC><CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 506] ActualTxPwr:8<CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 788] Bluetooth initialized<CR><LF>
    [00:00:00.325,286] <ESC><wrn> bt_hci_core: bt_set_name: Unable to store name<ESC><CR><LF>
    [00:00:00.333,099] <ESC><inf> bt_hci_core: bt_dev_show_info: Identity: C0:F1:EE:C6:31:44 (random)<ESC><CR><LF>
    [00:00:00.342,010] <ESC><inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x11fa, manufacturer 0x0059<ESC><CR><LF>
    [00:00:00.353,057] <ESC><inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0x11fa<ESC><CR><LF>
    [00:00:00.362,243] <ESC><wrn> bt_hci_core: bt_set_name: Unable to store name<ESC><CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 555] UpdateAdv x:0 y:0 z:0 Tmp:0 F:0x20<CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 593] AdvertisingStarted<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 676] BootConfirmed<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 683] ResetCause:1<CR><LF>
    [00:00:00.404,693] <ESC><err> bt_gatt: db_hash_store: Failed to save Database Hash (err -2)<ESC><CR><LF>
    [00:00:00.252,288] <ESC><inf> board_control: vcom0_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.259,155] <ESC><inf> board_control: vcom2_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.266,082] <ESC><inf> board_control: led1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.272,796] <ESC><inf> board_control: led2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.279,541] <ESC><inf> board_control: led3_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.286,285] <ESC><inf> board_control: led4_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.293,029] <ESC><inf> board_control: switch1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.300,048] <ESC><inf> board_control: switch2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.307,037] <ESC><inf> board_control: button1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.314,025] <ESC><inf> board_control: button2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.321,044] <ESC><inf> board_control: nrf_interface_pins_0_2_routing is disabled<ESC><CR><LF>
    [00:00:00.329,101] <ESC><inf> board_control: nrf_interface_pins_3_5_routing is disabled<ESC><CR><LF>
    [00:00:00.337,158] <ESC><inf> board_control: nrf_interface_pins_6_8_routing is disabled<ESC><CR><LF>
    [00:00:00.345,214] <ESC><inf> board_control: Board configured.<ESC><CR><LF>
    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.355,102] <ESC><inf> mcuboot: Starting bootloader<ESC><CR><LF>
    [00:00:00.361,083] <ESC><inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.371,063] <ESC><inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.381,164] <ESC><inf> mcuboot: Boot source: none<ESC><CR><LF>
    [00:00:00.386,566] <ESC><inf> mcuboot: Swap type: none<ESC><CR><LF>
    [00:00:00.460,662] <ESC><inf> mcuboot: Bootloader chainload address offset: 0xc000<ESC><CR><LF>
    [00:00:00.468,231] <ESC><inf> mcuboot: Jumping to the first image slot<ESC><CR>
    ÿ[00:00:00.000,152] <ESC><inf> board_control: init: vcom0_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.007,568] <ESC><inf> board_control: init: vcom2_pins_routing is ENABLED<ESC><CR><LF>
    [00:00:00.014,984] <ESC><inf> board_control: init: led1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.022,247] <ESC><inf> board_control: init: led2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.029,510] <ESC><inf> board_control: init: led3_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.036,773] <ESC><inf> board_control: init: led4_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.044,067] <ESC><inf> board_control: init: switch1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.051,574] <ESC><inf> board_control: init: switch2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.059,112] <ESC><inf> board_control: init: button1_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.066,650] <ESC><inf> board_control: init: button2_pin_routing is ENABLED<ESC><CR><LF>
    [00:00:00.074,188] <ESC><inf> board_control: init: nrf_interface_pins_0_2_routing is disabled<ESC><CR><LF>
    [00:00:00.082,763] <ESC><inf> board_control: init: nrf_interface_pins_3_5_routing is disabled<ESC><CR><LF>
    [00:00:00.091,339] <ESC><inf> board_control: init: nrf_interface_pins_6_8_routing is disabled<ESC><CR><LF>
    [00:00:00.099,914] <ESC><inf> board_control: init: Board configured.<ESC><CR><LF>
    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.110,412] <ESC><inf> mcumgr_zephyr_grp: zephyr_basic_mgmt_init: Registering Zephyr basic mgmt group<ESC><CR><LF>
    00/00/0000 00:00:00[ami_main.c: 631] Startup<CR><LF>
    00/00/0000 00:00:00[ami_cfg.c: 256] DeviceID:0<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 448] MainInitErr:4096<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 657] VaporBLE#0 26-Feb-2023 v1.0.0 1.0 2.26<CR><LF>
    build time: Feb 28 2023 11:08:57<CR><LF>
    [00:00:00.245,971] <ESC><inf> sdc_hci_driver: hci_driver_open: SoftDevice Controller build revision: <CR><LF>
                                             6d 90 41 2a 38 e8 ad 17  29 a5 03 38 39 27 d7 85 |m.A*8... )..89'..<CR><LF>
                                             1f 85 d8 e1                                      |....             <ESC><CR><LF>
    [00:00:00.276,916] <ESC><inf> bt_hci_core: hci_vs_init: HW Platform: Nordic Semiconductor (0x0002)<ESC><CR><LF>
    [00:00:00.285,888] <ESC><inf> bt_hci_core: hci_vs_init: HW Variant: nRF52x (0x0002)<ESC><CR><LF>
    [00:00:00.293,640] <ESC><inf> bt_hci_core: hci_vs_init: Firmware: Standard Bluetooth controller (0x00) Version 109.16784 Build 2917677098<ESC><CR><LF>
    [00:00:00.306,488] <ESC><inf> bt_hci_core: bt_init: No ID address. App must call settings_load()<ESC><CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 506] ActualTxPwr:8<CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 788] Bluetooth initialized<CR><LF>
    [00:00:00.325,408] <ESC><wrn> bt_hci_core: bt_set_name: Unable to store name<ESC><CR><LF>
    [00:00:00.333,251] <ESC><inf> bt_hci_core: bt_dev_show_info: Identity: C0:F1:EE:C6:31:44 (random)<ESC><CR><LF>
    [00:00:00.342,132] <ESC><inf> bt_hci_core: bt_dev_show_info: HCI: version 5.3 (0x0c) revision 0x11fa, manufacturer 0x0059<ESC><CR><LF>
    [00:00:00.353,179] <ESC><inf> bt_hci_core: bt_dev_show_info: LMP: version 5.3 (0x0c) subver 0x11fa<ESC><CR><LF>
    [00:00:00.362,365] <ESC><wrn> bt_hci_core: bt_set_name: Unable to store name<ESC><CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 555] UpdateAdv x:0 y:0 z:0 Tmp:0 F:0x20<CR><LF>
    00/00/0000 00:00:00[ami_ble.c: 593] AdvertisingStarted<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 676] BootConfirmed<CR><LF>
    00/00/0000 00:00:00[ami_main.c: 683] ResetCause:1<CR><LF>
    [00:00:00.404,815] <ESC><err> bt_gatt: db_hash_store: Failed to save Database Hash (err -2)<ESC><CR><LF>
    01/01/2004 00:01:00[ami_main.c: 601] NewMin<CR><LF>
    01/01/2004 00:02:00[ami_main.c: 601] NewMin<CR><LF>
    01/01/2004 00:03:00[ami_main.c: 601] NewMin<CR><LF>
    01/01/2004 00:04:00[ami_main.c: 601] NewMin<CR><LF>
    

    It does not look that the bootloader showed anything different between the programmer reset and the SMP reset.

    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.355,041] <ESC><inf> mcuboot: Starting bootloader<ESC><CR><LF>
    [00:00:00.360,992] <ESC><inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.370,971] <ESC><inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.381,072] <ESC><inf> mcuboot: Boot source: none<ESC><CR><LF>
    [00:00:00.386,474] <ESC><inf> mcuboot: Swap type: none<ESC><CR><LF>
    [00:00:00.460,571] <ESC><inf> mcuboot: Bootloader chainload address offset: 0xc000<ESC><CR><LF>
    [00:00:00.468,139] <ESC><inf> mcuboot: Jumping to the first image slot<ESC><CR>
    ======================================================================
    *** Booting Zephyr OS build v3.2.99-ncs1 ***<CR><LF>
    [00:00:00.355,102] <ESC><inf> mcuboot: Starting bootloader<ESC><CR><LF>
    [00:00:00.361,083] <ESC><inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.371,063] <ESC><inf> mcuboot: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3<ESC><CR><LF>
    [00:00:00.381,164] <ESC><inf> mcuboot: Boot source: none<ESC><CR><LF>
    [00:00:00.386,566] <ESC><inf> mcuboot: Swap type: none<ESC><CR><LF>
    [00:00:00.460,662] <ESC><inf> mcuboot: Bootloader chainload address offset: 0xc000<ESC><CR><LF>
    [00:00:00.468,231] <ESC><inf> mcuboot: Jumping to the first image slot<ESC><CR>
    

    Next, I tried to use my nRF52840-DK as the Central with your code and my nRF9160-DK as the sensor.

    After using the JFlash.ex flash program to upload the app_update.bin file to 0x86000 not 0x50000 and

    changing the connection UUID to the one I use, the Central connected.

    I pressed button#1 and got a list with only one slot the first time and the second time two slots.

    (Both times the upload failed).

    When pressed button#2 and saw that the central tries to upload all of second slot and not just the image size.

    Is this what you saw too?

    Maybe I should upload with my code the entire slot instead of just the app_update.bin file size?

    Should the padded data be zero or 0xFF?

    In any case, I got an error at almost the end of the upload from the end unit:

    *** Booting Zephyr OS build v3.2.99-ncs1 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0xc000
    *** Booting Zephyr OS build v3.2.99-ncs1 ***
    Starting Bluetooth Central SMP Client example
    I: SoftDevice Controller build revision:
    I: 6d 90 41 2a 38 e8 ad 17 |m.A*8...
    I: 29 a5 03 38 39 27 d7 85 |)..89'..
    I: 1f 85 d8 e1             |....
    I: HW Platform: Nordic Semiconductor (0x0002)
    I: HW Variant: nRF52x (0x0002)
    I: Firmware: Standard Bluetooth controller (0x00) Version 109.16784 Build 2917677098
    I: Identity: DF:EE:12:96:B1:89 (random)
    I: HCI: version 5.3 (0x0c) revision 0x11fa, manufacturer 0x0059
    I: LMP: version 5.3 (0x0c) subver 0x11fa
    Bluetooth initialized
    Scanning successfully started
    Filters matched. Address: C0:F1:EE:C6:31:44 (random) connectable: yes
    Image list command send error (err: -6)
    Connected: C0:F1:EE:C6:31:44 (random)
    MTU exchange pending
    E: pairing failed (peer reason 0x3)
    Security failed: C0:F1:EE:C6:31:44 (random) level 1 err 4
    MTU exchange successful
    Current MTU: 498
    The discovery procedure succeeded
    
    -----------PRIMARY IMAGE-----------
          slot: 0
          version: 0.0.0
          hash: 0x67fb72f73a0fda917c78ad444dbdbc7955e1b12842a66a1222f4ca95a6f0
          bootable: true
          pending: false
          confirmed: true
          active: true
          permanent: false
    
    -----------SECONDARY IMAGE-----------
          slot: 1
          version: 0.0.0
          hash: 0x67fb72f73a0fda917c78ad444dbdbc7955e1b12842a66a1222f4ca95a6f0
          bootable: true
          pending: false
          confirmed: false
          active: false
          permanent: false
    [  95% ] |===============================================   | (474900/499712 bytes)Error in image upload response: 1
    
    

    I tried the nRF52840 Central updating my custom sensor and got the same error:

    [ 95% ] |=============================================== | (474900/499712 bytes)Error in image upload response: 1

    So, I can't reproduce a DFU successfully like you, so it is evident that I am doing more than one thing wrong.

    Thanks David

  • OK I see that the secondary image size on my Central nRF52840 build and my nRF9160 & custom sensors are different sizes.

    1) nRF52840 central
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x86000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x86000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0x100000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x7a000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    
    send_upload2()
    	int last_addr = (PM_MCUBOOT_SECONDARY_END_ADDRESS-0x6000);  // ?!?
    ===================================================
    2) nRF9160 sensor
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x80000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x80000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0xf4000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x74000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    #define PM_5_LABEL MCUBOOT_SECONDARY
    
    ======================================================
    3) Custom sensor
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x80000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x80000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0xf4000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x74000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    #define PM_5_LABEL MCUBOOT_SECONDARY
    

    I just adjusted the central code so it would only send 0x74000 bytes instead of 0x7a000,

    but that did not help either. (475136 = 0x74000)

    send_upload2()
    int last_addr = (PM_MCUBOOT_SECONDARY_END_ADDRESS-0x6000); // ?!?

    I got when uploading:

    [  99% ] |================================================= | (474900/475136 bytes)Error in image upload response: 1

    Still the questions in the previous post are open.

    Thanks David

Reply
  • OK I see that the secondary image size on my Central nRF52840 build and my nRF9160 & custom sensors are different sizes.

    1) nRF52840 central
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x86000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x86000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0x100000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x7a000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    
    send_upload2()
    	int last_addr = (PM_MCUBOOT_SECONDARY_END_ADDRESS-0x6000);  // ?!?
    ===================================================
    2) nRF9160 sensor
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x80000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x80000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0xf4000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x74000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    #define PM_5_LABEL MCUBOOT_SECONDARY
    
    ======================================================
    3) Custom sensor
    #define PM_MCUBOOT_SECONDARY_OFFSET 0x80000
    #define PM_MCUBOOT_SECONDARY_ADDRESS 0x80000
    #define PM_MCUBOOT_SECONDARY_END_ADDRESS 0xf4000
    #define PM_MCUBOOT_SECONDARY_SIZE 0x74000
    #define PM_MCUBOOT_SECONDARY_NAME mcuboot_secondary
    #define PM_MCUBOOT_SECONDARY_ID 5
    #define PM_mcuboot_secondary_ID PM_MCUBOOT_SECONDARY_ID
    #define PM_mcuboot_secondary_IS_ENABLED 1
    #define PM_5_LABEL MCUBOOT_SECONDARY
    

    I just adjusted the central code so it would only send 0x74000 bytes instead of 0x7a000,

    but that did not help either. (475136 = 0x74000)

    send_upload2()
    int last_addr = (PM_MCUBOOT_SECONDARY_END_ADDRESS-0x6000); // ?!?

    I got when uploading:

    [  99% ] |================================================= | (474900/475136 bytes)Error in image upload response: 1

    Still the questions in the previous post are open.

    Thanks David

Children
No Data
Related