Add Arduino Nano 33 BLE and BLE Sense support
cover Add Arduino Nano 33 BLE and BLE Sense support
From: Wojciech Zmuda <[email protected]>
This patch set adds support for nRF52-based Arduino boards - Nano 33 BLE and BLE Sense - to both build and flash Zephyr applications.
The board support itself is a trivial MACHINE config. Flashing is done with a new bbclass, that is a wrapper around bossac flashing tool. One general kernel recipe fix was necessary to produce and copy over the .bin file, as the flasher requires input in that format. This does not affect scenarios where .elf file is required.
Tested on an actual Arduino Nano 33 BLE dev board.
Nagesh Shamnur (3):
zephyr-kernel: install .bin image if available arduino-nano-33-ble.conf: Add Arduino Nano 33 BLE and BLE Sense
support
zephyr-flash-bossac.bbclass: Enable board flashing via bossac
classes/zephyr-flash-bossac.bbclass | 50 +++++++++++++++++++ conf/machine/arduino-nano-33-ble.conf | 9 ++++ .../zephyr-kernel/zephyr-kernel-common.inc | 1 + .../zephyr-kernel/zephyr-sample.inc | 4 ++ 4 files changed, 64 insertions(+) create mode 100644 classes/zephyr-flash-bossac.bbclass create mode 100644 conf/machine/arduino-nano-33-ble.conf
Signature · 1 line
2.25.1
PATCH 1/3 zephyr-kernel: install .bin image if available
From: Nagesh Shamnur <[email protected]>
Some boards (e.g. Arduino Nano 33 BLE) require image in bin format for flashing with -c flash_usb. Provide that image along with ELF image on do_deploy step.
--- recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc | 1 + recipes-kernel/zephyr-kernel/zephyr-sample.inc | 4 ++++ 2 files changed, 5 insertions(+)
recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc +1 -0
@@ -12,6 +12,7 @@ ZEPHYR_GCC_VARIANT="yocto" ZEPHYR_SYSROOT="${STAGING_DIR_TARGET}" ZEPHYR_MAKE_OUTPUT = "zephyr.elf" +ZEPHYR_MAKE_BIN_OUTPUT = "zephyr.bin" EXTRA_OECMAKE = "\ -DZEPHYR_BASE=${S} \
recipes-kernel/zephyr-kernel/zephyr-sample.inc +4 -0
@@ -9,5 +9,9 @@ do_install[noexec] = "1" do_deploy () { install -D ${B}/zephyr/${ZEPHYR_MAKE_OUTPUT} ${DEPLOYDIR}/${PN}.elf + if [ -f ${B}/zephyr/${ZEPHYR_MAKE_BIN_OUTPUT} ] + then + install -D ${B}/zephyr/${ZEPHYR_MAKE_BIN_OUTPUT} ${DEPLOYDIR}/${PN}.bin + fi } addtask deploy after do_compile
Signature · 1 line
2.25.1
PATCH 2/3 arduino-nano-33-ble.conf: Add Arduino Nano 33 BLE and BLE Sense support
In reply to Wojciech ZmudaFrom: Nagesh Shamnur <[email protected]>
--- conf/machine/arduino-nano-33-ble.conf | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 conf/machine/arduino-nano-33-ble.conf
conf/machine/arduino-nano-33-ble.conf new file +8 -0
@@ -0,0 +1,8 @@ +#@TYPE: Machine +#@NAME: arduino-nano-33-ble + +#@DESCRIPTION: Machine configuration for Arudino nano 33 ble and Arduino nano 33 ble sense + +require conf/machine/include/nrf52.inc +ARCH_arduino-nano-33-ble = "arm" +
Signature · 1 line
2.25.1
PATCH 3/3 zephyr-flash-bossac.bbclass: Enable board flashing via bossac
In reply to Wojciech ZmudaFrom: Nagesh Shamnur <[email protected]>
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.
--- classes/zephyr-flash-bossac.bbclass | 50 +++++++++++++++++++++++++++ conf/machine/arduino-nano-33-ble.conf | 1 + 2 files changed, 51 insertions(+) create mode 100644 classes/zephyr-flash-bossac.bbclass
classes/zephyr-flash-bossac.bbclass new file +50 -0
@@ -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"
conf/machine/arduino-nano-33-ble.conf +1 -0
@@ -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"
Signature · 1 line
2.25.1