update nrfutil

This commit is contained in:
hathach committed 2018-05-16 16:27:01 +07:00
1 parent 68e403a44b
commit 28517e6917
3 files changed
+69 -42

No files matched your search

+58 -24
View File
@@ -1,41 +1,75 @@
nrfutil
==========
nrfutil is a Python package that includes the nrfutil command line utility and the nordicsemi library.
# nrfutil
About
-----
The library is written for Python 2.7.
`nrfutil` is a Python package that includes the nrfutil command line utility
and the nordicsemi library.
Prerequisites
-------------
To install nrfutil the following prerequisites must be satisfied:
This tool can be used used with the [Adafruit nRF52 Feather](https://www.adafruit.com/product/3406)
to flash firmware images onto the device using the simple serial port.
* Python 2.7 (2.7.6 or newer, not Python 3)
* pip (https://pip.pypa.io/en/stable/installing.html)
* setuptools (upgrade to latest version: pip install -U setuptools)
* install required modules: pip install -r requirements.txt
This library is written for Python 2.7.
py2exe prerequisites (Windows only):
# Installation
* py2exe (Windows only) (v0.6.9) (pip install http://sourceforge.net/projects/py2exe/files/latest/download?source=files)
* VC compiler for Python (Windows only) (http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266)
Run the following commands to make `nrfutil` available from the command line
or to development platforms like the Arduino IDE or CircuitPython:
**Notes** : Do **NOT** install nrfutil from the pip package (ex. `sudo pip
install nrfutil`). The latest nrfutil does not support DFU via Serial, and you
should install version 0.5.2 from a local copy of this repo via the methods
detailed below:
### OS X and Linux
Installation
------------
To install the library to the local Python site-packages and script folder:
```
$ sudo pip install -r requirements.txt
$ sudo python setup.py install
```
### Windows
#### Option 1: Pre-Built Binary
A pre-built 32-bit version of nrfutil is included as part of this repo in the
`binaries/win32` folder. You can use this pre-built binary by adding it to your
systems `$PATH` variable.
#### Option 2: Build nrfutil from Source
- Make sure that you have **Python 2.7** available on your system.
- Manually install **py2exe version 0.6.9** from this link (selecting
the 32-bit or 64-bit version depending on your Python installation):
[Download py2exe 0.6.9](https://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/).
- VC compiler for Python (Windows only) (http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266)
- From the command prompt, install nrfutil via pip as follows:
```
pip install -r requirements.txt
python setup.py install
```
To generate a self-contained Windows exe version of the utility (Windows only):
To generate a self-contained Windows exe version of the utility (Windows only):
```
python setup.py py2exe
```
NOTE: Some anti-virus programs will stop py2exe from executing correctly when it modifies the .exe file.
Usage
-----
To get info on usage of nrfutil:
# Usage
To get info on usage of nrfutil:
```
nrfutil --help
```
To convert an nRF52 .hex file into a DFU pkg file that the serial bootloader
can make use of:
```
nrfutil dfu genpkg --dev-type 0x0052 --application firmware.hex dfu-package.zip
```
To flash a DFU pkg file over serial:
```
nrfutil dfu serial --package dfu-package.zip -p /dev/tty.SLAB_USBtoUART -b 115200
```
@@ -31,7 +31,6 @@ import time
from datetime import datetime, timedelta
import binascii
import logging
import click
# Python 3rd party imports
from serial import Serial
@@ -59,18 +58,16 @@ class DfuTransportSerial(DfuTransport):
# SEND_START_DFU_WAIT_TIME = 10.0 # Time to wait before communicating with bootloader after start DFU packet is sent
# ADADFRUIT:
# - After Start packet is sent, nrf5x will start to erase flash page, each page takes 2.05 - 89.7 ms
# nrfutil need to wait accordingly for the image size, but not less than this value (0.5) second
# - Afterwards, command to activate new firmware --> nrf52 erase bank0 and copy image from bank1 to bank 0
# nrfutil need to wait otherwise and re-open serial could cause flash corruption
# nrfutil need to wait accordingly for the image size
# - After sending all data -> send command to activate new firmware --> nrf52 erase bank0 and copy image
# from bank1 to bank0 (if dual bank) nrfutil need to wait otherwise and re-open serial could cause flash corruption
SEND_START_DFU_MIN_WAIT_TIME = 0.5
# T erase page for nrf52832 is (2.05 to 89.7 ms), nrf52840 is ~85 ms max
FLASH_PAGE_ERASE_MAX_TIME = 0.085
FLASH_PAGE_ERASE_MAX_TIME = 0.09 # Worst time to erase a page 90 ms (89 ms)
#FLASH_PAGE_ERASE_MIN_TIME = 0.00205 # Best time to erase a page 2.05 ms
FLASH_PAGE_ERASE_MIN_TIME = 0.09
FLASH_WORD_WRITE_MAX_TIME = 0.000338 # Worst time to write one word 338 us
FLASH_WORD_WRITE_MIN_TIME = 0.0000675 # Best time to write one word 67.5 us
# T write word for nrf52832 is (6.7 to 338 us), nrf52840 is ~41 us max
FLASH_WORD_WRITE_MAX_TIME = 0.000338
FLASH_WORD_WRITE_MIN_TIME = 0.0000675
FLASH_OP_WAIT_RATIO = 0.5 # Ratio in % for flash operation (erase, write) comparing to the MAX(worst) scenario
@@ -143,16 +140,12 @@ class DfuTransportSerial(DfuTransport):
time.sleep(DfuTransportSerial.SEND_INIT_PACKET_WAIT_TIME)
def get_erase_wait_time(self):
avg_flash_erase = (self.FLASH_PAGE_ERASE_MAX_TIME - self.FLASH_PAGE_ERASE_MIN_TIME) * self.FLASH_OP_WAIT_RATIO + self.FLASH_PAGE_ERASE_MIN_TIME
erase_wait_time = (((self.total_size)//self.FLASH_PAGE_SIZE)+1)*avg_flash_erase
erase_wait_time = max(erase_wait_time, self.SEND_START_DFU_MIN_WAIT_TIME)
return erase_wait_time
return (((self.total_size)//self.FLASH_PAGE_SIZE)+1)*self.FLASH_PAGE_ERASE_MAX_TIME
def get_activate_wait_time(self):
# Activate wait time including time to erase bank 0 and writing bank 0
avg_flash_write = (self.FLASH_WORD_WRITE_MAX_TIME - self.FLASH_WORD_WRITE_MIN_TIME) * self.FLASH_OP_WAIT_RATIO + self.FLASH_WORD_WRITE_MIN_TIME
write_wait_time = ((self.total_size // 4) + 1) * avg_flash_write
write_wait_time = max(write_wait_time, self.SEND_START_DFU_MIN_WAIT_TIME)
return self.get_erase_wait_time() + write_wait_time
def send_start_dfu(self, mode, softdevice_size=None, bootloader_size=None, app_size=None):
@@ -174,7 +167,7 @@ class DfuTransportSerial(DfuTransport):
# nrf52 will erase the bank 0 up to Application size & Transfer App size from bank1 to bank0
# There must a enough delay before finished to prevent Arduino IDE reopen Serial Monitor
click.echo("\nActivating new firmware")
logger.info("\nActivating new firmware")
#logger.info("Wait after activating %s second", self.get_activate_wait_time())
time.sleep( self.get_activate_wait_time() )
+1 -1
View File
@@ -30,4 +30,4 @@
""" Version definition for nrfutil. """
NRFUTIL_VERSION = "0.5.2"
NRFUTIL_VERSION = "0.5.2d"