IMU | LSM6DSV320X SPI DMA Driver#28
Conversation
|
Ah sorry I just saw this! I've pinged myself as a reviewer and will take a look when I get a minute. Changing your target branch to reflect our move to an unstable trunk system. |
|
Also, I've added @266-750Balloons as this introduces DMA, which I'm less familiar with than CPU-bound interrupts. |
ETSells
left a comment
There was a problem hiding this comment.
dude this is actually crazy...
lgtm honestly, ignore my CR comments below, I'd take this as-is...
| * @param len: Number of data bytes (address byte excluded). | ||
| * @retval 0 on success, 1 on HAL error or oversized request. | ||
| */ | ||
| static int32_t platform_spi_write |
There was a problem hiding this comment.
cr: Please use a status type in your final version (you can reuse the old IMU status enum if you want, else if this stays separate you'll need a new one.) <-- ignore; all external interfaces follow the status return convention which is good enough for me
| memcpy( &tx[1], buf, len ); | ||
|
|
||
| HAL_GPIO_WritePin( IMU_CS_GPIO_PORT, IMU_CS_PIN, GPIO_PIN_RESET ); | ||
| __NOP(); __NOP(); |
There was a problem hiding this comment.
Interesting that these are needed here -- we've never had to do NOPs since the procedure call overhead is usually sufficient delay between writing CS low.
|
|
||
| (void)handle; | ||
|
|
||
| if ( len >= SPI_WRITE_BUF_MAX ) { |
There was a problem hiding this comment.
nit: max implies that the upper bound is inclusive.
| __NOP(); __NOP(); | ||
| HAL_GPIO_WritePin( IMU_CS_GPIO_PORT, IMU_CS_PIN, GPIO_PIN_SET ); | ||
|
|
||
| return ( hal_status == HAL_OK ) ? 0 : 1; |
There was a problem hiding this comment.
nit: we don't usually like inline logic like this since its harder to parse through
| uint16_t len | ||
| ) | ||
| { | ||
| #define SPI_WRITE_BUF_MAX ( 64U ) |
There was a problem hiding this comment.
Can we define this scoped to the header file for visibility? Either that or I guess leave like an implNote in your doxygen header.
| Initializations | ||
| --------------------------------------------------------------------------*/ | ||
| imu_sflp_enabled = false; | ||
| imu_dma_ready = false; |
There was a problem hiding this comment.
doesn't look like we have DMA r/w callbacks available but i'm glad we've started laying the groundwork for them!
| xl_bdr = LSM6DSV320X_XL_BATCHED_AT_7680Hz; | ||
| g_bdr = LSM6DSV320X_GY_BATCHED_AT_7680Hz; | ||
| break; | ||
| case IMU_ODR_1920HZ: /* fall-through to default */ |
There was a problem hiding this comment.
for defensive programming, consider using a debug assert here that ODR == 1920, that way in debug mode we catch that an improper param was passed.
the construct was just added in mod/error_sdr/error_sdr.h:debug_assert
| pid_status |= lsm6dsv320x_gy_data_rate_set( &imu_ctx, g_odr ); | ||
|
|
||
| /* | ||
| * Full-scale and ODR configuration - two separate accelerometer chains. |
There was a problem hiding this comment.
just a heads up that in the future we'll want this to be runtime configurable! i'll probably ask you to write the config api for that when we're ready, but we'd want high-G mode during boost and switch to low-G in coast and beyond.
| * high-G to low-G: clears XL_HG_REGOUT_EN, restores low-G batching. | ||
| * DS14623 Rev3 §6.1.2, Tables 70, 149, 150; COUNTER_BDR_REG1 (0Bh). | ||
| */ | ||
| IMU_STATUS imu_set_accel_fs |
There was a problem hiding this comment.
oh dang, ignore me earlier, you already did it!!
| /* Assert CS and launch DMA - CS de-asserted in imu_process_async_cb() */ | ||
| HAL_GPIO_WritePin( IMU_CS_GPIO_PORT, IMU_CS_PIN, GPIO_PIN_RESET ); | ||
| __NOP(); __NOP(); | ||
| hal_status = HAL_SPI_TransmitReceive_DMA( &IMU_SPI, |
There was a problem hiding this comment.
ohhhh dang! you've got the async interface too?!
|
Also -- because of the divergence between this version and the old IMU, we should consider keeping these separate with maybe a guard at the top of imu.h that points to imu_t.h if we're not using the legacy IMU. Don't worry about merging to the old platform unless you feel its the smarter design choice. Because this is kept separate from the old IMU, we can merge as-is once the PID driver is imported somewhere (either driver or lib) |
547fdbc to
7682028
Compare
|
This is in my review queue, but it might take me a second to get there, just as a heads up. |
ETSells
left a comment
There was a problem hiding this comment.
Significant build errors present. Please resolve these before requesting re-review.
I have added this driver to the build system via your FCF child PR. Please pull that up and test by invoking
cd app/rev3
make -jX # X = number of parallel processes you want for compilation
Build error log attached: build_err_log.txt
| * https://opensource.org/license/bsd-3-clause | ||
| * | ||
| *******************************************************************************/ | ||
| #if !defined( A0010 ) |
There was a problem hiding this comment.
Consider:
#ifndef( A0002_REV2 )
#error "Unsupported hardware platform
#endif
rather than wrapping the whole thing in a preprocessor directive.
| } IMU_RAW; | ||
|
|
||
| /* Processed IMU aata */ | ||
| typedef struct _STATE_ESTIMATION { |
There was a problem hiding this comment.
note for myself: beware of conflicts
There was a problem hiding this comment.
Assumption: I'm assuming this has been copied over with no functional changes from the previous iteration. If I'm wrong, then please fix.
There was a problem hiding this comment.
Assumption: I'm assuming this has been copied over with no functional changes from the previous iteration. If I'm wrong, then please fix.
…nt/rename changes
f64060f to
41ed939
Compare
|
Still have debug_assert to fix + maybe do more tinkering to avoid deprecated silly warnings. Will verify if effort is worth it or not (of warnings) |
Description
This PR introduces the initial driver implementation for the LSM6DSV320X high-g IMU, specifically targeting the STM32H733 (A0010, Rev 3 PCB).
The driver is currently implemented as imu_t.c/h to allow for a focused code review of the new DMA-based architecture and SFLP integration before it is merged/optimized with the existing old IMU.
Summary of functions:
Asynchronous DMA Path: (HAL_SPI_TransmitReceive_DMA) for FIFO burst reads to minimize CPU overhead during flight.
SFLP Integration: Support for the Sensor Fusion Low Power (SFLP) engine, providing game rotation vectors (quaternions), gravity vectors, and gyroscope bias estimates directly from the IMU.
Dynamic Range Handling: Includes logic for transitioning between the Low-G (up to ±16g) and High-G (up to ±320g) @ runtime.
Documentation is, frankly intense, so bare patience. Recommended to have associated datasheet open as citations are made heavily. I expect readability issues, but want to ensure nothing critical as at foot [Mainly if imu has unnecessary functions or is goes beyond scope etc.]
Issue Link
Associated issue IMU R3
Child PRs:
PR#1 Library Import
External lsm6dsv320x-pid library (STMicroelectronics).
https://github.com/SunDevilRocketry/lib/tree/feat/add-lsm6dsv320x-submodule
PR#2: DMA linker
Modifying linker script
https://github.com/SunDevilRocketry/Flight-Computer-Firmware/tree/feat/add-DMA-linker
Testing [NOT APPLICABLE]
Attach any test artifacts here, if relevant.
Other
Leave any additional notes here
Reviewer Checklist
Standards
Error Handling
Memory
Performance