From ecce62695061df21cbd085cb6660e1f3194a8dd5 Mon Sep 17 00:00:00 2001 From: Jeremy Wood <79875124+JeremyBCD@users.noreply.github.com> Date: Mon, 6 Dec 2021 08:43:55 -0800 Subject: [PATCH] BSP for Blue Clover PLT Demo V2, Support for BMI270 IMU (#41) * BSP for Blue Clover PLT Demo V2 * Configure BMI270 if present, enable shell. Supports both LY10DEMO and PLT Demo V2 boards. * Add PLT Demo V2 to README and make dist. * Make copyright comments consistent. --- Makefile | 8 +- README.md | 6 +- app/prj.conf | 5 + app/src/app_sensor.c | 90 +++++++++- app/src/app_sensor.h | 12 +- app/src/main.c | 10 +- .../blueclover_plt_demo_v2_nrf52832/Kconfig | 10 ++ .../Kconfig.board | 8 + .../Kconfig.defconfig | 14 ++ .../README.rst | 8 + .../blueclover_plt_demo_v2_nrf52832.dts | 163 ++++++++++++++++++ .../blueclover_plt_demo_v2_nrf52832.yaml | 20 +++ .../blueclover_plt_demo_v2_nrf52832_defconfig | 31 ++++ .../board.cmake | 10 ++ .../suite-demo-board-zephyr.yaml.template | 2 +- 15 files changed, 387 insertions(+), 10 deletions(-) create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.board create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.defconfig create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/README.rst create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.yaml create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig create mode 100644 boards/arm/blueclover_plt_demo_v2_nrf52832/board.cmake diff --git a/Makefile b/Makefile index 85d4558..7e4ef74 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ ZEPHYR_BOARD_ROOT := $(BASE_PATH) BOARDS_APP := BOARDS_APP += ly10demo -#BOARDS_APP := nrf52dk_nrf52832 +BOARDS_APP += blueclover_plt_demo_v2_nrf52832 APP_TARGETS := $(patsubst %,build.%/app/zephyr/zephyr.hex,$(BOARDS_APP)) @@ -80,7 +80,11 @@ dist: dist-clean dist-prep build install -m 666 build.ly10demo/app/zephyr/zephyr.hex dist/app-pltdemov1-$(VERSION_TAG).hex install -m 666 build.ly10demo/app/zephyr/zephyr.elf dist/app-pltdemov1-$(VERSION_TAG).elf install -m 666 build.ly10demo/app/zephyr/zephyr.map dist/app-pltdemov1-$(VERSION_TAG).map - sed 's/{{VERSION}}/$(VERSION_TAG)/g' test-suites/suite-demo-board-zephyr.yaml.template > dist/suite-demo-board-zephyr-$(VERSION_TAG).yaml + sed 's/{{BOARD}}/pltdemov1/g; s/{{VERSION}}/$(VERSION_TAG)/g' test-suites/suite-demo-board-zephyr.yaml.template > dist/suite-pltdemov1-board-zephyr-$(VERSION_TAG).yaml + install -m 666 build.blueclover_plt_demo_v2_nrf52832/app/zephyr/zephyr.hex dist/app-pltdemov2-$(VERSION_TAG).hex + install -m 666 build.blueclover_plt_demo_v2_nrf52832/app/zephyr/zephyr.elf dist/app-pltdemov2-$(VERSION_TAG).elf + install -m 666 build.blueclover_plt_demo_v2_nrf52832/app/zephyr/zephyr.map dist/app-pltdemov2-$(VERSION_TAG).map + sed 's/{{BOARD}}/pltdemov2/g; s/{{VERSION}}/$(VERSION_TAG)/g' test-suites/suite-demo-board-zephyr.yaml.template > dist/suite-pltdemov2-board-zephyr-$(VERSION_TAG).yaml .PHONY: deploy deploy: diff --git a/README.md b/README.md index 34c222e..3eb6180 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # ly10-zephyr-fw -Zephyr-based firmware for LY10DEMO +Zephyr-based firmware for LY10DEMO and PLT Demo V2 - Build platform: macOS, Linux -- Host platform: LY10DEMO(nRF52) -- Target platform: LY10DEMO(nRF52) +- Host platform: LY10DEMO(nRF52), PLT Demo V2 (nRF52) +- Target platform: LY10DEMO(nRF52), PLT Demo V2 (nRF52) ## Docker build diff --git a/app/prj.conf b/app/prj.conf index 5950de3..a1a9886 100644 --- a/app/prj.conf +++ b/app/prj.conf @@ -18,3 +18,8 @@ CONFIG_SPI=y CONFIG_NRFX_SPI=y CONFIG_LED_STRIP=y CONFIG_APA102_STRIP=y + +CONFIG_SHELL=y +CONFIG_SHELL_PROMPT_UART="plt-demo:~$ " +CONFIG_GPIO_SHELL=y +CONFIG_I2C_SHELL=y diff --git a/app/src/app_sensor.c b/app/src/app_sensor.c index f021414..b98128b 100644 --- a/app/src/app_sensor.c +++ b/app/src/app_sensor.c @@ -13,7 +13,7 @@ #include "app_sensor.h" -int app_sensor_setup(void) +int app_sensor_evironmental_setup(void) { struct sensor_value temp, hum; const struct device *dev = device_get_binding("SHT3XD"); @@ -39,3 +39,91 @@ int app_sensor_setup(void) sensor_value_to_double(&temp), sensor_value_to_double(&hum)); return 0; } + +int app_sensor_motion_setup(void) +{ + int rc; + struct sensor_value acc[3], gyr[3]; + const struct device *dev = device_get_binding("BMI270"); + struct sensor_value full_scale, sampling_freq, oversampling; + + if (dev == NULL) { + printf("Could not get BMI270 device\n"); + return -1; + } + + /* Set accelerometer scale, frequency, and mode. */ + full_scale.val1 = 2; /* 2G scale range */ + full_scale.val2 = 0; + sampling_freq.val1 = 100; /* 100Hz frequency */ + sampling_freq.val2 = 0; + oversampling.val1 = 1; /* Normal mode */ + oversampling.val2 = 0; + + rc = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_FULL_SCALE, + &full_scale); + if (rc != 0) { + printf("%s setting accel full_scale failed, rc=%d\n", __func__, rc); + return rc; + } + rc = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_OVERSAMPLING, + &oversampling); + if (rc != 0) { + printf("%s setting accel oversampling failed, rc=%d\n", __func__, rc); + return rc; + } + rc = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, + SENSOR_ATTR_SAMPLING_FREQUENCY, + &sampling_freq); + if (rc != 0) { + printf("%s setting accel sampling_freq failed, rc=%d\n", __func__, rc); + return rc; + } + + /* Set gyroscope scale, frequency, and mode. */ + full_scale.val1 = 500; /* dps */ + full_scale.val2 = 0; + sampling_freq.val1 = 100; /* 100Hz. Performance mode */ + sampling_freq.val2 = 0; + oversampling.val1 = 1; /* Normal mode */ + oversampling.val2 = 0; + + rc = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_FULL_SCALE, + &full_scale); + if (rc != 0) { + printf("%s setting gyro full_scale failed, rc=%d\n", __func__, rc); + return rc; + } + rc = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_OVERSAMPLING, + &oversampling); + if (rc != 0) { + printf("%s setting gyro oversampling failed, rc=%d\n", __func__, rc); + return rc; + } + rc = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, + SENSOR_ATTR_SAMPLING_FREQUENCY, + &sampling_freq); + if (rc != 0) { + printf("%s setting gyro sampling_freq failed, rc=%d\n", __func__, rc); + return rc; + } + + /* Wait for intial samples */ + k_sleep(K_MSEC(100)); + + sensor_sample_fetch(dev); + + sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc); + sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ, gyr); + + printf("BMI270 AX: %d.%06d; AY: %d.%06d; AZ: %d.%06d;\n" + " GX: %d.%06d; GY: %d.%06d; GZ: %d.%06d;\n", + acc[0].val1, acc[0].val2, + acc[1].val1, acc[1].val2, + acc[2].val1, acc[2].val2, + gyr[0].val1, gyr[0].val2, + gyr[1].val1, gyr[1].val2, + gyr[2].val1, gyr[2].val2); + + return 0; +} diff --git a/app/src/app_sensor.h b/app/src/app_sensor.h index 3cfde4f..b38cebe 100644 --- a/app/src/app_sensor.h +++ b/app/src/app_sensor.h @@ -4,4 +4,14 @@ // Copyright (c) 2021 Blue Clover Devices // -int app_sensor_setup(void); +/* + * @brief Setup environmental sensor, if present. + * @return 0 on success, non-zero on failure. + */ +int app_sensor_evironmental_setup(void); + +/* + * @brief Setup motion sensor, if present. + * @return 0 on success, non-zero on failure. + */ +int app_sensor_motion_setup(void); diff --git a/app/src/main.c b/app/src/main.c index d2b1491..08a2d56 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -6,6 +6,7 @@ /* main.c - Application main entry point */ +#include #include #include "app_ble.h" @@ -31,9 +32,14 @@ void main(void) return; } - err = app_sensor_setup(); + err = app_sensor_evironmental_setup(); if (err) { - return; + printf("app_sensor_evironmental_setup() failed, err=%d\n", err); + } + + err = app_sensor_motion_setup(); + if (err) { + printf("app_sensor_motion_setup() failed, err=%d\n", err); } err = app_buzzer_setup(); diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig new file mode 100644 index 0000000..ebd175a --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig @@ -0,0 +1,10 @@ +# Blue Clover PLT Demo V2 Configuration + +# Copyright (c) 2021 Blue Clover +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_ENABLE_DCDC + bool "Enable DCDC mode" + select SOC_DCDC_NRF52X + default y + depends on BOARD_BLUECLOVER_PLT_DEMO_V2_NRF52832 diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.board b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.board new file mode 100644 index 0000000..cb7d5a1 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.board @@ -0,0 +1,8 @@ +# Blue Clover PLT Demo V2 Configuration + +# Copyright (c) 2021 Blue Clover +# SPDX-License-Identifier: Apache-2.0 + +config BOARD_BLUECLOVER_PLT_DEMO_V2_NRF52832 + bool "Blue Clover PLT Demo Board V2" + depends on SOC_NRF52832_QFAA diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.defconfig b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.defconfig new file mode 100644 index 0000000..dd08877 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.defconfig @@ -0,0 +1,14 @@ +# Blue Clover PLT Demo V2 Configuration + +# Copyright (c) 2021 Blue Clover +# SPDX-License-Identifier: Apache-2.0 + +if BOARD_BLUECLOVER_PLT_DEMO_V2_NRF52832 + +config BOARD + default "blueclover_plt_demo_v2_nrf52832" + +config BT_CTLR + default BT + +endif # BOARD_BLUECLOVER_PLT_DEMO_V2_NRF52832 diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/README.rst b/boards/arm/blueclover_plt_demo_v2_nrf52832/README.rst new file mode 100644 index 0000000..d31e809 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/README.rst @@ -0,0 +1,8 @@ +.. SPDX-License-Identifier: Apache-2.0 + +blueclover_plt_demo_v2_nrf52832 +=============================== + +nRF52-based demo board for Blue Clover Production Line Tool (PLT). + +- SoC: Nordic nRF52 (arm) diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts new file mode 100644 index 0000000..bff5400 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.dts @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: Apache-2.0 + +/* + * Copyright (c) 2021 Blue Clover + */ + +/dts-v1/; +#include + +/ { + model = "Blue Clover PLT Demo Board V2"; + compatible = "nordic,blueclover-plt-demo-v2-nrf52832"; + + chosen { + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; + zephyr,uart-mcumgr = &uart0; + zephyr,bt-mon-uart = &uart0; + zephyr,bt-c2h-uart = &uart0; + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &slot0_partition; + }; + + buttons { + compatible = "gpio-keys"; + button0: button_0 { + gpios = <&gpio0 26 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button switch 0"; + }; + button1: button_1 { + gpios = <&gpio0 21 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + label = "Push button switch 1"; + }; + }; + + /* These aliases are provided for compatibility with samples */ + aliases { + sw0 = &button0; + sw1 = &button1; + pwm-buzzer = &pwm0; + }; +}; + +&adc { + status ="okay"; +}; + +&gpiote { + status ="okay"; +}; + +&gpio0 { + status ="okay"; +}; + +arduino_serial: &uart0 { + status = "okay"; + compatible = "nordic,nrf-uart"; + current-speed = <115200>; + tx-pin = <6>; + rx-pin = <8>; + rts-pin = <5>; + cts-pin = <7>; +}; + +&i2c0 { + compatible = "nordic,nrf-twi"; + status = "okay"; + sda-pin = <12>; + scl-pin = <14>; + + sht3xd@44 { + compatible = "sensirion,sht3xd"; + reg = <0x44>; + label = "SHT3XD"; + }; + + bmi270@68 { + compatible = "bosch,bmi270"; + reg = <0x68>; + label = "BMI270"; + }; +}; + +&i2c1 { + compatible = "nordic,nrf-twi"; + /* Cannot be used together with spi1. */ + /* status = "okay"; */ + sda-pin = <30>; + scl-pin = <31>; +}; + +&pwm0 { + /* buzzer */ + status = "okay"; + ch0-pin = <22>; + ch0-inverted; +}; + +&spi0 { + compatible = "nordic,nrf-spi"; + /* status = "okay"; */ + sck-pin = <27>; + mosi-pin = <26>; + miso-pin = <25>; +}; + +&spi1 { + compatible = "nordic,nrf-spi"; + status = "okay"; + sck-pin = <2>; + mosi-pin = <3>; + miso-pin = <27>; /* unused */ + + apa102@0 { + compatible = "apa,apa102"; + reg = <0>; + spi-max-frequency = <5250000>; + label = "APA102"; + }; +}; + +&spi2 { + compatible = "nordic,nrf-spi"; + /* status = "okay"; */ + sck-pin = <22>; + mosi-pin = <23>; + miso-pin = <24>; +}; + +&flash0 { + /* + * For more information, see: + * http://docs.zephyrproject.org/latest/guides/dts/index.html#flash-partitions + */ + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0xc000>; + }; + slot0_partition: partition@c000 { + label = "image-0"; + reg = <0x0000C000 0x32000>; + }; + slot1_partition: partition@3e000 { + label = "image-1"; + reg = <0x0003E000 0x32000>; + }; + scratch_partition: partition@70000 { + label = "image-scratch"; + reg = <0x00070000 0xa000>; + }; + storage_partition: partition@7a000 { + label = "storage"; + reg = <0x0007a000 0x00006000>; + }; + }; +}; diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.yaml b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.yaml new file mode 100644 index 0000000..22d61f8 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832.yaml @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: Apache-2.0 +identifier: blueclover_plt_demo_v2_nrf52832 +name: Blue Clover PLT Demo Board V2 +type: mcu +arch: arm +toolchain: + - zephyr + - gnuarmemb + - xtools +ram: 64 +flash: 512 +supported: + - adc + - ble + - counter + - nvs + - i2c + - pwm + - spi + - watchdog diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig new file mode 100644 index 0000000..05dfaf4 --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/blueclover_plt_demo_v2_nrf52832_defconfig @@ -0,0 +1,31 @@ +# Kconfig - Blue Clover PLT Demo V2 Configuration +# +# Copyright (c) 2021 Blue Clover +# +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SOC_SERIES_NRF52X=y +CONFIG_SOC_NRF52832_QFAA=y +CONFIG_BOARD_BLUECLOVER_PLT_DEMO_V2_NRF52832=y + +# Enable MPU +CONFIG_ARM_MPU=y + +# Enable RTT +CONFIG_USE_SEGGER_RTT=y + +# enable GPIO +CONFIG_GPIO=y + +# enable uart driver +CONFIG_SERIAL=y + +# enable console +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y + +# additional board options +CONFIG_GPIO_AS_PINRESET=y + +# enable accelerometer +CONFIG_BMI270=y diff --git a/boards/arm/blueclover_plt_demo_v2_nrf52832/board.cmake b/boards/arm/blueclover_plt_demo_v2_nrf52832/board.cmake new file mode 100644 index 0000000..4f6fc1f --- /dev/null +++ b/boards/arm/blueclover_plt_demo_v2_nrf52832/board.cmake @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: Apache-2.0 + +set(OPENOCD_NRF5_SUBFAMILY "nrf52") +board_runner_args(nrfjprog "--nrf-family=NRF52") +board_runner_args(jlink "--device=nrf52" "--speed=4000") +board_runner_args(pyocd "--target=nrf52" "--frequency=4000000") +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) +include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) +include(${ZEPHYR_BASE}/boards/common/openocd-nrf5.board.cmake) diff --git a/test-suites/suite-demo-board-zephyr.yaml.template b/test-suites/suite-demo-board-zephyr.yaml.template index ea605ca..e2dfcf3 100644 --- a/test-suites/suite-demo-board-zephyr.yaml.template +++ b/test-suites/suite-demo-board-zephyr.yaml.template @@ -15,7 +15,7 @@ suite: - ident: ICT-T3 title: Program PLTDemoV1 board FW steps: - - command: program nRF52 app-pltdemov1-{{VERSION}}.hex + - command: program nRF52 app-{{BOARD}}-{{VERSION}}.hex - ident: ICT-T4 title: BLE discovery steps: