Skip to contentSkip to conversation

Add 96Boards Nitrogen support

PATCH New Wojciech Zmuda 1 participant 6 messages Dec 10, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover Add 96Boards Nitrogen support

From: Wojciech Zmuda <[email protected]>

Hello,

v2 -> v3:
- fix accidentally broken QEMU builds. The build failed when do_deploy looked for .hex files that were generated for physical machines but not for QEMU (which does not need them). Fix the issue by reverting the change of generating .hex files. They were introduced for pyocd, but it occurs that pyocd is happy with ELFs, so this idea of .hex files was removed altogether from this patch set. Instead, zephyr-flash-pyocd gets ELFs and happily flashes Nitrogen.
- fix building zephyr-kernel-test-all targets for physical boards. Explained in commit message of patch 5/5.
v1 -> v2:
- README.txt: fix bad MACHINE examples: change _ to -, i.e. 96b_nitrogen -> 96b-nitrogen

This patch set adds support for the Nitrogen board by 96Boards. The support consists of:
- adding configs for Cortex-M4, nRF52832 SoC and Nitrogen board,
- adding bbclass with pyocd-based do_flash_usb() implementation.

Tested on Nitrogen and on QEMU so I hope I didn't accidentally break anything.

Verification:
1. Install pyocd.
2. Connect Nitrogen and make sure you can see Bus 001 Device 004: ID 0d28:0204 NXP ARM mbed in lsusb.
3. Build a sample app:

    $ MACHINE=96b-nitrogen DISTRO=zephyr bitbake zephyr-philosophers
 4. Flash app to the board:
    $ MACHINE=96b-nitrogen DISTRO=zephyr bitbake zephyr-philosophers -c flash_usb

You can also build the test suite i.e. bitbake zephyr-kernel-test-all and manually flash Nitrogen with images from the deploy directory. They are not picked up by do_flash_usb implementation from zephyur-flash-pyocd, as it works with single ELF file with the same name that the target has. The same limitation is present in the current do_flash_usb implementation from the zephyr-flash-dfu class.

Wojciech Zmuda (5):
zephyr-kernel: clone Nordic HAL
conf: machine: add support for Nordic nRF52832 Cortex-M4 chip
conf: machine: add 96boards Nitrogen support
zephyr-kernel: don't limit deploy to .elf file zephyr-flash-pyocd.bbclass: support for flashing via pyocd

 README.txt                                    | 23 +++++++++++++++++++
 classes/zephyr-flash-pyocd.bbclass            | 17 ++++++++++++++
 classes/zephyr-kernel-src.bbclass             |  7 +++---
 conf/machine/96b-nitrogen.conf                |  8 +++++++
 conf/machine/include/nrf52832.inc             | 10 ++++++++
 conf/machine/include/tune-cortexm4.inc        | 19 +++++++++++++++
 .../zephyr-kernel/zephyr-helloworld.bb        |  3 ++-
 recipes-kernel/zephyr-kernel/zephyr-image.inc |  2 +-
 .../zephyr-kernel/zephyr-kernel-common.inc    |  5 +++-
 .../zephyr-kernel/zephyr-philosophers.bb      |  3 ++-
 10 files changed, 90 insertions(+), 7 deletions(-)
 create mode 100644 classes/zephyr-flash-pyocd.bbclass
 create mode 100644 conf/machine/96b-nitrogen.conf
 create mode 100644 conf/machine/include/nrf52832.inc
 create mode 100644 conf/machine/include/tune-cortexm4.inc
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/5 zephyr-kernel: clone Nordic HAL

From: Wojciech Zmuda <[email protected]>

HAL for Nordic chipsets is one of Zephyr subprojects. It is downloaded by default by west. Clone the HAL repository so it can be used for building images for boards with Nordic chips.

---
 classes/zephyr-kernel-src.bbclass                     | 7 ++++---
 recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)
classes/zephyr-kernel-src.bbclass +4 -3
index d245223..ea9b30b 100644
@@ -5,12 +5,13 @@ PREFERRED_VERSION_zephyr-kernel ??= "2.4.0"
 SRCREV_FORMAT = "default_cmsis"
 SRCREV_default = "7a3b253ced7333f5c0269387a7f3ed1dee69739d"
 SRCREV_cmsis = "542b2296e6d515b265e25c6b7208e8fea3014f90"
-
+SRCREV_nordic = "d8a6ea9695ddf792bb18bb6035c13b1daac5d79c"
 
 SRC_URI = "git://github.com/zephyrproject-rtos/zephyr.git;protocol=https;branch=v2.4-branch;name=default \
            git://github.com/zephyrproject-rtos/cmsis.git;protocol=https;destsuffix=git/modules/cmsis;name=cmsis \
-          file://0001-cmake-add-yocto-toolchain.patch \
-        "
+           git://github.com/zephyrproject-rtos/hal_nordic.git;protocol=https;destsuffix=git/modules/hal/nordic;name=nordic \
+           file://0001-cmake-add-yocto-toolchain.patch \
+          "
 
 PV = "2.4.0+git${SRCPV}"
 
recipes-kernel/zephyr-kernel/zephyr-kernel-common.inc +1 -0
index 3f82c20..a1f640d 100644
@@ -16,6 +16,7 @@ ZEPHYR_MAKE_OUTPUT = "zephyr.elf"
 
 EXTRA_OECMAKE = " -DZEPHYR_BASE=${S} -DZEPHYR_GCC_VARIANT=yocto -DBOARD=${BOARD} -DARCH=${ARCH} -DCROSS_COMPILE=${CROSS_COMPILE} -DZEPHYR_SYSROOT=${ZEPHYR_SYSROOT} -DZEPHYR_TOOLCHAIN_VARIANT=yocto"
 EXTRA_OECMAKE_append_arm = " -DZEPHYR_MODULES=${S}/modules/cmsis"
+EXTRA_OECMAKE_append_nordic = "\;${S}/modules/hal/nordic"
 export ZEPHYR_BASE="${S}"
 
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH v3 2/5 conf: machine: add support for Nordic nRF52832 Cortex-M4 chip

In reply to Wojciech Zmuda

From: Wojciech Zmuda <[email protected]>

Add include for Cortex-M4 tunes and nRF52832. The nRF config appends 'nordic' to MACHINEOVERRIDES, so the kernel recipe can include Nordic HAL when this override is detected.

---
 conf/machine/include/nrf52832.inc      | 10 ++++++++++
 conf/machine/include/tune-cortexm4.inc | 19 +++++++++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 conf/machine/include/nrf52832.inc
 create mode 100644 conf/machine/include/tune-cortexm4.inc
conf/machine/include/nrf52832.inc new file +10 -0
new file mode 100644
index 0000000..73e628a
@@ -0,0 +1,10 @@
+#@TYPE: Machine
+#@NAME: nrf52832
+
+#@DESCRIPTION: Machine configuration for Nordic Semiconductor nRF52832 (Cortex-M4) SoC.
+
+require conf/machine/include/tune-cortexm4.inc
+
+MACHINEOVERRIDES =. "nordic:"
+
+TUNE_FEATURES = "armv7m cortexm4"
conf/machine/include/tune-cortexm4.inc new file +19 -0
new file mode 100644
index 0000000..a823b6b
@@ -0,0 +1,19 @@
+DEFAULTTUNE ?= "cortexm4"
+
+require conf/machine/include/arm/arch-armv7a.inc
+
+TUNEVALID[cortexm4] = "Enable Cortex-M4 specific processor optimizations"
+TUNE_CCARGS .= "${@bb.utils.contains('TUNE_FEATURES', 'cortexm4', ' -mcpu=cortex-m4', '', d)}"
+AVAILTUNES += "cortexm4"
+
+TUNEVALID[armv7m] = "Enable Cortex-M4 specific processor optimizations"
+TUNE_CCARGS .= "${@bb.utils.contains('TUNE_FEATURES', 'armv7m', ' -march=armv7e-m', '', d)}"
+MACHINEOVERRIDES =. "${@bb.utils.contains('TUNE_FEATURES', 'armv7m', 'armv7m:', '' ,d)}"
+
+TUNE_PKGARCH_tune-cortexm4 = "cortexm4"
+
+ARMPKGARCH_tune-cortexm4 = "armv7m"
+PACKAGE_EXTRA_ARCHS_tune-cortexm4 ="cortexm4"
+
+TUNE_FEATURES_tune-cortexm4 = "armv7m vfp cortexm4"
+PACKAGE_EXTRA_ARCHS_tune-cortexm4 = "${PACKAGE_EXTRA_ARCHS_tune-armv7at} armv7m-vfp armv7m"
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 3/5 conf: machine: add 96boards Nitrogen support

In reply to Wojciech Zmuda

From: Wojciech Zmuda <[email protected]>

The board is based on Nordic nRF52832 Cortex-M4 chip. The support depends on Nordic HAL. It has been verified with zephyr-philosophers and zephyr-shell sample applications.

---
 conf/machine/96b-nitrogen.conf | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 conf/machine/96b-nitrogen.conf
conf/machine/96b-nitrogen.conf new file +7 -0
new file mode 100644
index 0000000..d1905f2
@@ -0,0 +1,7 @@
+#@TYPE: Machine
+#@NAME: 96b_nitrogen
+
+#@DESCRIPTION: Machine configuration for 96Boards Nitrogen Board.
+
+require conf/machine/include/nrf52832.inc
+ARCH_96b-nitrogen = "arm"
Signature · 1 line
2.25.1
#4 lore raw

PATCH v3 4/5 zephyr-flash-pyocd.bbclass: support for flashing via pyocd

In reply to Wojciech Zmuda

From: Wojciech Zmuda <[email protected]>

Implement do_flash_usb for boards supported by pyocd:

MACHINE=xxx bitbake yyy -c flash_usb

Pyocd support abundance of boards, however for now this meta-layer supports only one board that can be flashed using pyocd, that is 96Boards Nitrogen.

Describe the feature in README.

---
 README.txt                         | 23 +++++++++++++++++++++++
 classes/zephyr-flash-pyocd.bbclass | 16 ++++++++++++++++
 conf/machine/96b-nitrogen.conf     |  1 +
 3 files changed, 40 insertions(+)
 create mode 100644 classes/zephyr-flash-pyocd.bbclass
README.txt +23 -0
index 6463339..bda872b 100644
@@ -43,6 +43,29 @@ The same sample, for Nios2 image:
     $ MACHINE=qemu-nios2 bitbake zephyr-philosophers
     $ runqemu qemu-nios2
 
+Flashing
+=================================
+
+You can flash Zephyr samples to boards. Currently, the following MACHINEs
+are supported:
+ * DFU:
+  - arduino-101-sss
+  - arduino-101
+  - arduino-101-ble
+ * pyocd:
+  - 96b-nitrogen
+
+To flash the example you built with command e.g.
+
+    $ MACHINE=96b-nitrogen bitbake zephyr-philosophers
+
+call similar command with explicit flash_usb command:
+
+    $ MACHINE=96b-nitrogen bitbake zephyr-philosophers -c flash_usb
+
+dfu-util and/or pyocd need to be installed in your system. If you observe
+permission errors or the flashing process seem to hang, follow those instructions:
+https://github.com/pyocd/pyOCD/tree/master/udev
 
 Building and Running Zephyr Tests
 =================================
classes/zephyr-flash-pyocd.bbclass new file +16 -0
new file mode 100644
index 0000000..04500af
@@ -0,0 +1,16 @@
+python do_flash_usb() {
+    from pyocd.core.helpers import ConnectHelper
+    from pyocd.flash.file_programmer import FileProgrammer
+
+    image = f"{d.getVar('DEPLOY_DIR_IMAGE')}/{d.getVar('PN')}.elf"
+    bb.plain(f"Attempting to flash {image} to board {d.getVar('BOARD')}")
+
+    with ConnectHelper.session_with_chosen_probe() as session:
+        FileProgrammer(session).program(image)
+        session.board.target.reset()
+}
+
+addtask do_flash_usb
+
+do_flash_usb[nostamp] = "1"
+do_flash_usb[vardepsexclude] = "BB_ORIGENV"
conf/machine/96b-nitrogen.conf +1 -0
index d1905f2..998db4c 100644
@@ -4,4 +4,5 @@
 #@DESCRIPTION: Machine configuration for 96Boards Nitrogen Board.
 
 require conf/machine/include/nrf52832.inc
+ZEPHYR_INHERIT_CLASSES += "zephyr-flash-pyocd"
 ARCH_96b-nitrogen = "arm"
Signature · 1 line
2.25.1
#5 lore raw

PATCH v3 5/5 classes: build zephyr-kernel-test-all for non-qemu boards

In reply to Wojciech Zmuda

From: Wojciech Zmuda <[email protected]>

Machines not inheriting zephyr-qemuboot did not have IMGDEPLOYDIR variable set, which is required for building zephyr-kernel-test-all. The build was fine for qemu-xxx machines, but for physical boards it failed somewhere inside python code when .join() got an empty argument incoming from IMGDEPLOYDIR. Move IMGDEPLOYDIR to zephyr class, so it's defined for qemu and non-qemu machines.

---
 classes/zephyr-qemuboot.bbclass | 3 ---
 classes/zephyr.bbclass          | 3 +++
 2 files changed, 3 insertions(+), 3 deletions(-)
classes/zephyr-qemuboot.bbclass +0 -3
index 39de3f0..5ac1c86 100644
@@ -11,9 +11,6 @@ IMAGE_LINK_NAME = "${PN}-image-${MACHINE}"
 # Create a link with "-image-" in the name just to keep runqemu happy
 QEMU_IMAGE_LINK = "${DEPLOY_DIR_IMAGE}/${PN}-image-${MACHINE}.elf"
 
-# qemuboot writes into IMGDEPLOYDIR, force to write to DEPLOY_DIR_IMAGE
-IMGDEPLOYDIR = "${DEPLOY_DIR_IMAGE}"
-
 CLEANFUNCS += "bootconf_clean"
 
 python bootconf_clean() {
classes/zephyr.bbclass +3 -0
index ead762a..6fceb04 100644
@@ -10,6 +10,9 @@ TERMINFO = "${STAGING_DATADIR_NATIVE}/terminfo"
 KCONFIG_CONFIG_COMMAND ??= "menuconfig"
 ZEPHYR_BOARD ?= "${MACHINE}"
 
+# qemuboot writes into IMGDEPLOYDIR, force to write to DEPLOY_DIR_IMAGE
+IMGDEPLOYDIR = "${DEPLOY_DIR_IMAGE}"
+
 python () {
     # Translate MACHINE into Zephyr BOARD
     # Zephyr BOARD is basically our MACHINE, except we must use "-" instead of "_"
Signature · 1 line
2.25.1