Skip to content

Commit

Permalink
BSP for Blue Clover PLT Demo V2, Support for BMI270 IMU (#41)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
JeremyBCD authored Dec 6, 2021
1 parent f09334f commit ecce626
Show file tree
Hide file tree
Showing 15 changed files with 387 additions and 10 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
90 changes: 89 additions & 1 deletion app/src/app_sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
12 changes: 11 additions & 1 deletion app/src/app_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 8 additions & 2 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* main.c - Application main entry point */

#include <stdio.h>
#include <zephyr.h>

#include "app_ble.h"
Expand All @@ -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();
Expand Down
10 changes: 10 additions & 0 deletions boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.board
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions boards/arm/blueclover_plt_demo_v2_nrf52832/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions boards/arm/blueclover_plt_demo_v2_nrf52832/README.rst
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// SPDX-License-Identifier: Apache-2.0

/*
* Copyright (c) 2021 Blue Clover
*/

/dts-v1/;
#include <nordic/nrf52832_qfaa.dtsi>

/ {
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>;
};
};
};
Loading

0 comments on commit ecce626

Please sign in to comment.