aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNagesh Shamnur <nagesh.shamnur@huawei.com>2021-06-11 10:52:05 +0200
committerNaveen Saini <naveen.kumar.saini@intel.com>2021-06-15 14:14:34 +0800
commit5660376db794f400a27f50cc2ac26ea9bc56d725 (patch)
tree68d85d34c7cd3841f579be34fad35b20ce4c9003
parent6e155307b82387fd3f00b4b637499161a2ef9c3b (diff)
downloadmeta-zephyr-5660376db794f400a27f50cc2ac26ea9bc56d725.tar.gz
meta-zephyr-5660376db794f400a27f50cc2ac26ea9bc56d725.tar.bz2
meta-zephyr-5660376db794f400a27f50cc2ac26ea9bc56d725.zip
zephyr-flash-bossac.bbclass: Enable board flashing via bossac
Currently only dfu and pyocd flashing are supported. Some boards such as Arduino Nano 33 BLE can be flashed via bossac which is released by Arduino repo. Find the installed Arudino version of bossac and flash using that tool. Signed-off-by: Nagesh Shamnur <nagesh.shamnur@huawei.com> Signed-off-by: Naveen Saini <naveen.kumar.saini@intel.com>
-rw-r--r--classes/zephyr-flash-bossac.bbclass50
-rw-r--r--conf/machine/arduino-nano-33-ble.conf1
2 files changed, 51 insertions, 0 deletions
diff --git a/classes/zephyr-flash-bossac.bbclass b/classes/zephyr-flash-bossac.bbclass
new file mode 100644
index 0000000..50222d5
--- /dev/null
+++ b/classes/zephyr-flash-bossac.bbclass
@@ -0,0 +1,50 @@
+#@DESCRIPTION: class file to flash boards like Arduino Nano BLE which depends on bossac for flashing
+
+python do_flash_usb() {
+ import shutil
+ import subprocess
+ import serial.tools.list_ports
+
+ # Note: make sure the installed bossac is set to PATH before running flash_usb()
+ # Check if bossac is avaiable for flashing
+ origbbenv = d.getVar("BB_ORIGENV", False)
+ bossac_path = shutil.which("bossac", path=origbbenv.getVar('PATH'))
+
+ if not bossac_path:
+ bb.fatal("ERROR: bossac not found, please install first and add to PATH")
+
+ board = d.getVar('BOARD')
+
+ if board == 'arduino_nano_33_ble':
+ # find the serial port to which board is connected to
+ for port in serial.tools.list_ports.comports():
+ if 'Arduino Nano 33 BLE' in port.description:
+ serial_port = port.device
+ break
+ else:
+ bb.fatal("ERROR: board not connected for flashing. Connect via USB and enable permission to connected port")
+
+ image = "%s/%s.bin" % (d.getVar('DEPLOY_DIR_IMAGE'), d.getVar('PN'))
+
+ command = [bossac_path, '-p', serial_port , '-R', '-e', '-w', '-v', '-b', image]
+ else:
+ bb.fatal("ERROR: Unsupported board %s" % board)
+
+ bb.note("command: %s" % command)
+ bb.plain("Attempting to flash board: %s" % board)
+
+ # Random failure are a possibility here, retry till there is a success for finite times
+ for _ in range(10, 0, -1):
+ try:
+ subprocess.check_call(command)
+ bb.plain("Bossac Flashing board: %s Success " % board)
+ break
+ except subprocess.CalledProcessError as e:
+ bb.warn("Failed to flash %s (error code: %s). Retrying after 1 second..." % (board, e.returncode))
+ time.sleep(1)
+}
+
+addtask do_flash_usb after do_deploy
+
+do_flash_usb[nostamp] = "1"
+do_flash_usb[vardepsexclude] = "BB_ORIGENV"
diff --git a/conf/machine/arduino-nano-33-ble.conf b/conf/machine/arduino-nano-33-ble.conf
index e45cfc2..18ba056 100644
--- a/conf/machine/arduino-nano-33-ble.conf
+++ b/conf/machine/arduino-nano-33-ble.conf
@@ -4,5 +4,6 @@
#@DESCRIPTION: Machine configuration for Arudino nano 33 ble and Arduino nano 33 ble sense
require conf/machine/include/nrf52.inc
+ZEPHYR_INHERIT_CLASSES += "zephyr-flash-bossac"
ARCH_arduino-nano-33-ble = "arm"