GithubHelp home page GithubHelp logo

nrf52-dfu's Introduction

nrf52-dfu

Nordic nRF52 firmware update example from secondary MPU

For details, see our blog post: https://blog.classycode.com/updating-the-firmware-on-an-nrf52-from-another-microcontroller-b513080dc0cd

Step by step instructions

1 - Provide the SDK and toolchain in the root directory

  • sdk/nRF5_SDK_15.2.0_9412b96
  • toolchain/gcc-arm-none-eabi-7-2018-q2-update

The nRF52 SDK is available on the Nordic web site: https://www.nordicsemi.com/Software-and-tools/Software/nRF5-SDK/Download

To download the ARM toolchain, visit the ARM developer web site: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads

Patch the SDK:

$ patch -p0 < nrfx_uart.patch

Install the uECC library:

$ pushd sdk/nRF5_SDK_15.2.0_9412b96/external/micro-ecc
$ export GNU_INSTALL_ROOT="$PWD/../../../../toolchain/gcc-arm-none-eabi-7-2018-q2-update/bin/"
$ git clone https://github.com/kmackay/micro-ecc.git
$ make -C nrf52hf_armgcc/armgcc
$ make -C nrf52nf_armgcc/armgcc
$ popd

2 - Create the bootloader

$ cd 02_Bootloader
$ make clean
$ make
$ make hex
$ make flash_hex

A serial console connected to the nrf52 should now display @@BOOTLOADER

3 - Create application v1

$ cd ..
$ cd 01_Demo_App
$ make clean
$ make v1

4 - Create the DFU package, send it to the bootloader

$ cd dfu_zip
$ make clean
$ make v1
$ make dfu  <-- replace the serial device in the Makefile first!

5 - Create application v2

$ cd ..
$ cd 01_Demo_App
$ make clean
$ make v2

6 - Create the DFU package for v2

$ cd dfu_zip
$ make clean
$ make v2

7 - Create v2 DFU blobs:

$ cp app_dfu_package.zip /tmp
$ pushd /tmp
$ unzip app_dfu_package.zip
$ popd

$ cd ../..
$ cd 05_Firmware_Converter
$ gcc fwconvert.c
$ ./a.out /tmp/nrf52832_xxaa.bin dfu_firmware_bin.h gFirmwareBin
$ ./a.out /tmp/nrf52832_xxaa.dat dfu_firmware_dat.h gFirmwareDat

8 - Perform DFU with the demo host application:

$ cd ..
$ cd 04_Demo_Host_Application
$ cp ../05_Firmware_Converter/dfu_firmware_bin.h .
$ cp ../05_Firmware_Converter/dfu_firmware_dat.h .
$ make

Press the button on the target board to trigger the DFU process.

$ ./fwu "/dev/tty.usbserial-DN009NQG" 57600  <-- configure for your serial device

nrf52-dfu's People

Contributors

aschweiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nrf52-dfu's Issues

Missing SLIP Escaping in command transfers

Thanks a lot for sharing, that helped me a lot!
One topic I stumbled on:
There is no SLIP escaping when sending commands to the nRF bootloader. This can create problems when a command parameter contains the EOM character (0xC0). The bootloader on the nRF side then prematurely cuts the commad block, leaving possibly invalid parameters for its upper levels.
I had that problem with a specific payload length of a block to download. The last CREATE OBJECT command will use the remaining size of the block instead of the maximum block size. If that remainig blocksize generates a 0xC0 in the length parameter of the CREATE OBJECT command, the command will fail. I had that with a remaining block size of 2240 bytes, which results in a length encoding of 0xC0, 0x08, 0x00, 0x00.
Correction is easy:
Just add SLIP escaping in fwuPrepareSendBuffer(). I did it this way:

static void fwuPrepareSendBuffer(TFwu *fwu, uint8_t *data, uint8_t len)
{
    // TODO assert privateCommandState == FWU_CS_IDLE | _DONE | _FAIL
    // TODO assert len <= FWU_REQUEST_BUF_SIZE
    
    uint8_t i;
    uint8_t *p = &fwu->privateRequestBuf[0];

    fwu->privateRequestIx = 0;
    fwu->privateRequestLen = len + 1;
    fwu->privateResponseLen = 0;

    // Copy the data into our internal buffer.
    // Handle SLIP escaping.
    for (i = 0; i < len; i++) {
        // SLIP escape characters: C0->DBDC, DB->DBDD
        if ((*data == 0xC0) || (*data == 0xDB))  {
            *p++ = 0xDB;
            *p++ = (*data++ == 0xC0) ? 0xDC : 0xDD;
            fwu->privateRequestLen++;
        } else {
            *p++ = *data++;
        }
    }
    
    // Add the end-of-message marker.
    *p = FWU_EOM;
    
    // Ready to send!
    fwu->privateCommandRequest = FWU_CR_SEND;
}

Regards and many thanks for sharing!
Michael

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.