Skip to content

STMicro LSM6DSV16X IMU support #13046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged

Conversation

SteveCEvans
Copy link
Member

@SteveCEvans SteveCEvans commented Aug 22, 2023

This PR adds support for the STMicro LSM6DSV16X IMU.

Filter settings are at default and may need adjustment.

Outstanding issue is that use of the High-accuracy ODR mode should enable selection of 8kHz gyro data rate, however use of the DRDY_PULSED bit in the CTRL4 register results in a pulse of 66us followed by a low of 66us which gives a cycle time of 132us rather than the desired 125us.

image

Driver developed using a MATEKH743 with the following config.h changes.

diff --git a/configs/MATEKH743/config.h b/configs/MATEKH743/config.h
index ac0fd43..21ad550 100644
--- a/configs/MATEKH743/config.h
+++ b/configs/MATEKH743/config.h
@@ -36,6 +36,9 @@
 #define USE_GYRO_SPI_MPU6500
 #define USE_GYRO_SPI_ICM42605
 #define USE_GYRO_SPI_ICM42688P
+#define USE_ACCGYRO_LSM6DSO
+#define USE_ACCGYRO_LSM6DSV16X
+
 #define USE_BARO
 #define USE_BARO_BMP280
 #define USE_BARO_DPS310
@@ -106,7 +109,12 @@
 #define GYRO_2_EXTI_PIN      PE15
 #define GYRO_1_CS_PIN        PC15
 #define GYRO_2_CS_PIN        PE11
-#define USB_DETECT_PIN       PE2
+
+/* CS1/CS2 pads for SPI3 connection:
+ *
+ * CS1 D04
+ * CS2 E02
+ */
 
 #define TIMER_PIN_MAPPING \
     TIMER_PIN_MAP( 0, PB0 , 2,  0) \

IMG_4261

@SteveCEvans SteveCEvans requested a review from KarateBrot August 22, 2023 00:48
@SteveCEvans SteveCEvans self-assigned this Aug 22, 2023
@github-actions
Copy link

Do you want to test this code? You can flash it directly from Betaflight Configurator:

  • Simply put #13046 (this pull request number) in the Select commit field of the Configurator firmware flasher tab (you need to Enable expert mode, Show release candidates and Development).

WARNING: It may be unstable. Use only for testing!

@SteveCEvans SteveCEvans changed the title LSM6DSV16X STMicro LSM6DSV16X IMU support Aug 22, 2023
@haslinghuis haslinghuis added this to the 4.5 milestone Aug 22, 2023
@blckmn
Copy link
Member

blckmn commented Aug 22, 2023

AUTOMERGE: (FAIL)

  • github identifies PR as mergeable -> FAIL
  • assigned to a milestone -> PASS
  • cooling off period lapsed -> PASS
  • commit count less or equal to three -> PASS
  • Don't merge label NOT found -> PASS
  • at least one RN: label found -> PASS
  • Tested label found -> FAIL
  • assigned to an approver -> PASS
  • approver count at least three -> FAIL

// TODO this pulse lasts 66us followed by a low of 66us, so we get 132us cycle time, not 125us
spiWriteReg(dev, LSM6DSV_CTRL4, LSM6DSV_CTRL4_DRDY_PULSED);

gyro->scale = GYRO_SCALE_2000DPS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the data sheet (section 4.1 symbol G_So) the LSM6DSV16X should use a sensitivity of 70 milli-degrees / LSB.
IIRC GYRO_SCALE_2000DPS is about 63.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting observation. Thank you.

2000 / 0x8000 = 0.061 deg/LSB. So that would be the ideal.

From https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf I see that the MPU6000 has a figure of 0.066, for example, but no other driver set this figure according to their datasheet.

#define GYRO_SCALE_2000DPS (2000.0f / (1 << 15))

That said I've set the scale for this device according to the datasheet and will raise a PR to improve calibration for all others.

On a similar note the acc has a sensitivity of 0.488 mg/LSB with FS = ±16 g. 0x8000 * 0.488/1000 = 15.99, so that is not in need of special consideration.

#define LSM6DSV_DECODE_BITS(val, mask, shift) ((val & mask) >> shift)

// Enable embedded functions register (R/W)
#define LSM6DSV_FUNC_CFG_ACCESS 0x01
Copy link
Member

@haslinghuis haslinghuis Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(multiple occurrences of) nonaligned indentation 👾

I reckon @KarateBrot will complain too 😛

@tbolin
Copy link
Contributor

tbolin commented Aug 22, 2023

Outstanding issue is that use of the High-accuracy ODR mode should enable selection of 8kHz gyro data rate, however use of the DRDY_PULSED bit in the CTRL4 register results in a pulse of 66us followed by a low of 66us which gives a cycle time of 132us rather than the desired 125us.

Isn't the highest supported data rate supposed to be 7.68 kHz / ~130 us (section 4.1, symbol G_ODR)? O a'm I missing something?

@SteveCEvans
Copy link
Member Author

Outstanding issue is that use of the High-accuracy ODR mode should enable selection of 8kHz gyro data rate, however use of the DRDY_PULSED bit in the CTRL4 register results in a pulse of 66us followed by a low of 66us which gives a cycle time of 132us rather than the desired 125us.

Isn't the highest supported data rate supposed to be 7.68 kHz / ~130 us (section 4.1, symbol G_ODR)? O a'm I missing something?

See section 6.5, High-accuracy ODR mode.

image

@sugaarK
Copy link
Member

sugaarK commented Nov 29, 2023

im getting some aios next week @SteveCEvans that have this gyro.. what do we do about the ODR mode

@SteveCEvans
Copy link
Member Author

SteveCEvans commented Nov 29, 2023 via email

@sugaarK sugaarK requested review from haslinghuis and tbolin December 2, 2023 05:42
@sugaarK
Copy link
Member

sugaarK commented Dec 2, 2023

@SteveCEvans if this is good to go we should merge it now so it’s in rc1 and mess with the ODR modes if needed in the next RC. As far as I know there are no production hardware using the gyro and only the team have any usable hardware that they should receive in the next week or so

@haslinghuis haslinghuis merged commit e126f1c into betaflight:master Dec 4, 2023
freasy pushed a commit to freasy/betaflight that referenced this pull request Jan 22, 2024
davidbitton pushed a commit to davidbitton/betaflight that referenced this pull request Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

6 participants