From 711e281fe7e8a9ab3458f48f7ecc79d617d4a872 Mon Sep 17 00:00:00 2001 From: Christian Vejlbo Date: Mon, 8 May 2023 20:14:48 +0200 Subject: [PATCH 1/2] Fix SW reboot for BMI270, retry BMI270 init in case of failure --- .../NDP/examples/SensorTest/SensorTest.ino | 92 +++++++++++-------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/libraries/NDP/examples/SensorTest/SensorTest.ino b/libraries/NDP/examples/SensorTest/SensorTest.ino index 74959c925..ab89fe30f 100644 --- a/libraries/NDP/examples/SensorTest/SensorTest.ino +++ b/libraries/NDP/examples/SensorTest/SensorTest.ino @@ -37,6 +37,7 @@ int loopCounter = 0; void setup() { int s; uint8_t __attribute__((aligned(4))) sensor_data[16]; + int retry_sensor_init = 0; Serial.begin(115200); nicla::begin(); @@ -56,51 +57,68 @@ void setup() { NDP.turnOnMicrophone(); NDP.interrupts(); - // 1st read will place the sensor in SPI mode, 2nd read is real read - s = NDP.sensorBMI270Read(0x0, 1, sensor_data); - CHECK_STATUS(s); + do { + if (retry_sensor_init) { + Serial.print("Init attempt "); + Serial.println(retry_sensor_init); + } + // 1st read will place the sensor in SPI mode, 2nd read is real read + s = NDP.sensorBMI270Read(0x0, 1, sensor_data); + CHECK_STATUS(s); - s = NDP.sensorBMI270Read(0x0, 1, sensor_data); - CHECK_STATUS(s); - Serial.print("BMI270 chip ID is (expected is 0x24): "); - Serial.println(sensor_data[0], HEX); + s = NDP.sensorBMI270Read(0x0, 1, sensor_data); + CHECK_STATUS(s); + Serial.print("BMI270 chip ID is (expected is 0x24): "); + Serial.println(sensor_data[0], HEX); - // soft reset - s = NDP.sensorBMI270Write(0x7e, 0x6b); - CHECK_STATUS(s); - delay(20); //delay 20ms much longer than reqired 450us + // soft reset + s = NDP.sensorBMI270Write(0x7e, 0xb6); + CHECK_STATUS(s); + delay(200); - // back to SPI mode after software reset - s = NDP.sensorBMI270Read(0x0, 1, sensor_data); - CHECK_STATUS(s); - s = NDP.sensorBMI270Read(0x0, 1, sensor_data); - CHECK_STATUS(s); + // back to SPI mode after software reset + s = NDP.sensorBMI270Read(0x0, 1, sensor_data); + CHECK_STATUS(s); + s = NDP.sensorBMI270Read(0x0, 1, sensor_data); + CHECK_STATUS(s); - // disable PWR_CONF.adv_power_save - s = NDP.sensorBMI270Write(0x7c, 0x00); - CHECK_STATUS(s); - delay(20); //delay 20ms much longer than reqired 450us + s = NDP.sensorBMI270Read(0x21, 1, sensor_data); + CHECK_STATUS(s); + Serial.print("[After reset] BMI270 Status Register at address 0x21 is (expected is 0x00): 0x"); + Serial.println(sensor_data[0], HEX); - // prepare config load INIT_CTRL = 0x00 - s = NDP.sensorBMI270Write(0x59, 0x00); - CHECK_STATUS(s); + // disable PWR_CONF.adv_power_save + s = NDP.sensorBMI270Write(0x7c, 0x00); + CHECK_STATUS(s); + delay(20); - // burst write to INIT_DATA - Serial.print("BMI270 init starting..."); - s = NDP.sensorBMI270Write(0x5e, - sizeof(bmi270_maximum_fifo_config_file), - (uint8_t*)bmi270_maximum_fifo_config_file); - CHECK_STATUS(s); - Serial.println("... done!"); + // prepare config load INIT_CTRL = 0x00 + s = NDP.sensorBMI270Write(0x59, 0x00); + CHECK_STATUS(s); + delay(200); - s = NDP.sensorBMI270Write(0x59, 0x01); - CHECK_STATUS(s); - delay(200); + // burst write to INIT_DATA + Serial.print("BMI270 init starting..."); + s = NDP.sensorBMI270Write(0x5e, + sizeof(bmi270_maximum_fifo_config_file), + (uint8_t*)bmi270_maximum_fifo_config_file); + CHECK_STATUS(s); + Serial.println("... done!"); - s = NDP.sensorBMI270Read(0x21, 1, sensor_data); - CHECK_STATUS(s); - Serial.print("BMI270 Status Register at address 0x21 is (expected is 0x01): 0x"); - Serial.println(sensor_data[0], HEX); + s = NDP.sensorBMI270Write(0x59, 0x01); + CHECK_STATUS(s); + delay(200); + + s = NDP.sensorBMI270Read(0x21, 1, sensor_data); + CHECK_STATUS(s); + Serial.print("BMI270 Status Register at address 0x21 is (expected is 0x01): 0x"); + Serial.println(sensor_data[0], HEX); + if (sensor_data[0] != 1) { + retry_sensor_init++; + } else { + retry_sensor_init = 0; + } + } while (retry_sensor_init); // configuring device to normal power mode with both Accelerometer and gyroscope working s = NDP.sensorBMI270Write(0x7d, 0x0e); From 2c3ab2e765833e99a1985a800f791d94d17b6f2d Mon Sep 17 00:00:00 2001 From: Christian Vejlbo Date: Tue, 9 May 2023 10:27:39 +0200 Subject: [PATCH 2/2] Use lower rate SPI clock --- libraries/NDP/examples/SensorTest/SensorTest.ino | 4 ++-- libraries/syntiant_ilib/src/syntiant_tiny_cspi.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/NDP/examples/SensorTest/SensorTest.ino b/libraries/NDP/examples/SensorTest/SensorTest.ino index ab89fe30f..df00e8400 100644 --- a/libraries/NDP/examples/SensorTest/SensorTest.ino +++ b/libraries/NDP/examples/SensorTest/SensorTest.ino @@ -59,7 +59,7 @@ void setup() { do { if (retry_sensor_init) { - Serial.print("Init attempt "); + Serial.print("Reinit attempt "); Serial.println(retry_sensor_init); } // 1st read will place the sensor in SPI mode, 2nd read is real read @@ -74,7 +74,7 @@ void setup() { // soft reset s = NDP.sensorBMI270Write(0x7e, 0xb6); CHECK_STATUS(s); - delay(200); + delay(20); // back to SPI mode after software reset s = NDP.sensorBMI270Read(0x0, 1, sensor_data); diff --git a/libraries/syntiant_ilib/src/syntiant_tiny_cspi.c b/libraries/syntiant_ilib/src/syntiant_tiny_cspi.c index 41d94c98e..1ec78eda6 100644 --- a/libraries/syntiant_ilib/src/syntiant_tiny_cspi.c +++ b/libraries/syntiant_ilib/src/syntiant_tiny_cspi.c @@ -39,7 +39,7 @@ #define SYNTIANT_NDP120_SPI_OP 0 #define SYNTIANT_NDP120_MCU_OP 1 -#define MSPI_CLK_DIV 2 +#define MSPI_CLK_DIV 6 #define MSSB_OE_USED 7 static int _cspi_read(struct syntiant_ndp120_tiny_device_s *ndp, int ssb, int num_bytes, uint8_t *data, int end_packet);