-
Notifications
You must be signed in to change notification settings - Fork 2
Csm bringup #233
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
Closed
Closed
Csm bringup #233
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3376001
Added suspension potentiometer, strain gauge, and imu code
Firefudge1 d5bf117
Added ride height sensor support in SPI mode 3, IMU SPI mutex, and lo…
Firefudge1 b3c771b
Changed the tasks in my freertos to match the can packets
Firefudge1 ff73030
some CAN changes
Firefudge1 1ad3c5e
Add gyro CAN packets, consolidate sensor tasks, fix CAN debug loop
Firefudge1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,32 @@ load("//tools:outputs/build_outputs.bzl", "firmware_project_g4") | |
|
|
||
| firmware_project_g4( | ||
| name = "csm_firmware_2026", | ||
| linker_script = "STM32G474XX_FLASH.ld", | ||
| startup_script = "startup_stm32g474xx.s", | ||
| linker_script = "STM32G491XX_FLASH.ld", | ||
| startup_script = "startup_stm32g491xx.s", | ||
| defines = [ | ||
| "STM32G474xx", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ], | ||
| enable_dfu = True, | ||
| enable_freertos = True, | ||
| enable_usb = True, | ||
| usb_device_name = "Corner Sensor Module", | ||
| extra_includes = [ | ||
| "Core/Inc", | ||
| "Libs/AFBR-S50/Include", | ||
| "Libs/AFBR-S50/Include/platform", | ||
| "Libs/AFBR-S50/Test", | ||
| ], | ||
| extra_srcs = glob([ | ||
| "Libs/AFBR-S50/Include/platform/*.c", | ||
| "Libs/AFBR-S50/Test/*.c", | ||
| ]), | ||
| extra_deps = [ | ||
| "//CSM/firmware/Libs/AFBR-S50/Lib:afbrs50", | ||
| ], | ||
| locations = [ | ||
| "RR", | ||
| "RL", | ||
| "FR", | ||
| "FL", | ||
| "RR", | ||
| "RL", | ||
| "FR", | ||
| "FL", | ||
| ], | ||
| ) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #ifndef CSM_CAN_H | ||
| #define CSM_CAN_H | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| void csm_can_init(void); | ||
| void csm_can_update_strain_gauge_sus_pot(float suspot_travel, float strain_voltage); | ||
| void csm_can_update_accel_ride_height(float x, float y, float z, float ride_height_mm); | ||
| void csm_can_update_gyro(float x, float y, float z); | ||
| void csm_can_debug(void); | ||
|
|
||
| #endif // CSM_CAN_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* USER CODE BEGIN Header */ | ||
| /** | ||
| ****************************************************************************** | ||
| * @file dma.h | ||
| * @brief This file contains all the function prototypes for | ||
| * the dma.c file | ||
| ****************************************************************************** | ||
| * @attention | ||
| * | ||
| * Copyright (c) 2025 STMicroelectronics. | ||
| * All rights reserved. | ||
| * | ||
| * This software is licensed under terms that can be found in the LICENSE file | ||
| * in the root directory of this software component. | ||
| * If no LICENSE file comes with this software, it is provided AS-IS. | ||
| * | ||
| ****************************************************************************** | ||
| */ | ||
| /* USER CODE END Header */ | ||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||
| #ifndef __DMA_H__ | ||
| #define __DMA_H__ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Includes ------------------------------------------------------------------*/ | ||
| #include "main.h" | ||
|
|
||
| /* DMA memory to memory transfer handles -------------------------------------*/ | ||
|
|
||
| /* USER CODE BEGIN Includes */ | ||
|
|
||
| /* USER CODE END Includes */ | ||
|
|
||
| /* USER CODE BEGIN Private defines */ | ||
|
|
||
| /* USER CODE END Private defines */ | ||
|
|
||
| void MX_DMA_Init(void); | ||
|
|
||
| /* USER CODE BEGIN Prototypes */ | ||
|
|
||
| /* USER CODE END Prototypes */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __DMA_H__ */ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #ifndef IMU_H | ||
| #define IMU_H | ||
|
|
||
| #include "stm32g4xx_hal.h" | ||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
|
|
||
| /******************************************************************************* | ||
| * Data Structures | ||
| ******************************************************************************/ | ||
|
|
||
| typedef struct { | ||
| float x; | ||
| float y; | ||
| float z; | ||
| } xyz_t; | ||
|
|
||
| typedef struct { | ||
| xyz_t accel; // m/s^2 | ||
| xyz_t gyro; // rad/s | ||
| } imu_data_t; | ||
|
|
||
| /******************************************************************************* | ||
| * Public Functions | ||
| ******************************************************************************/ | ||
|
|
||
| /** | ||
| * @brief Initializes the IMU over SPI and runs gyro bias calibration. | ||
| * @param hspi Pointer to SPI handle (pass &hspi1) | ||
| * @retval 0 on success, non-zero on failure (returns WHO_AM_I value if wrong) | ||
| */ | ||
| int IMU_Init(SPI_HandleTypeDef *hspi); | ||
|
|
||
| /** | ||
| * @brief Calibrates gyroscope bias at startup. | ||
| * @note Call while car is stationary. Accel is not calibrated since | ||
| * car may not be level at startup. | ||
| */ | ||
| void IMU_Calibrate(void); | ||
|
|
||
| /** | ||
| * @brief Checks if new accelerometer data is available. | ||
| * @retval true if ready | ||
| */ | ||
| bool IMU_AccelStatus(void); | ||
|
|
||
| /** | ||
| * @brief Checks if new gyroscope data is available. | ||
| * @retval true if ready | ||
| */ | ||
| bool IMU_GyroStatus(void); | ||
|
|
||
| /** | ||
| * @brief Reads accelerometer data with gyro bias removed. | ||
| * @param vec Pointer to xyz_t to store result in m/s^2 | ||
| */ | ||
| void IMU_GetAccel(xyz_t *vec); | ||
|
|
||
| /** | ||
| * @brief Reads gyroscope data with bias removed. | ||
| * @param vec Pointer to xyz_t to store result in rad/s | ||
| */ | ||
| void IMU_GetGyro(xyz_t *vec); | ||
|
|
||
| /** | ||
| * @brief Reads both accel and gyro in one call. | ||
| * @param out Pointer to imu_data_t to store result | ||
| */ | ||
| void IMU_GetData(imu_data_t *out); | ||
|
|
||
| uint8_t imu_read(uint8_t reg); | ||
|
|
||
| #endif /* IMU_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #ifndef CSM_FIRMWARE_RIDE_HEIGHT_H | ||
| #define CSM_FIRMWARE_RIDE_HEIGHT_H | ||
|
|
||
| #include "main.h" | ||
|
|
||
| void ride_height_init(); | ||
| float ride_height_get_distance_mm(); | ||
| uint8_t ride_height_get_quality(); | ||
|
|
||
|
|
||
| #endif // CSM_FIRMWARE_RIDE_HEIGHT_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* USER CODE BEGIN Header */ | ||
| /** | ||
| ****************************************************************************** | ||
| * @file spi.h | ||
| * @brief This file contains all the function prototypes for | ||
| * the spi.c file | ||
| ****************************************************************************** | ||
| * @attention | ||
| * | ||
| * Copyright (c) 2026 STMicroelectronics. | ||
| * All rights reserved. | ||
| * | ||
| * This software is licensed under terms that can be found in the LICENSE file | ||
| * in the root directory of this software component. | ||
| * If no LICENSE file comes with this software, it is provided AS-IS. | ||
| * | ||
| ****************************************************************************** | ||
| */ | ||
| /* USER CODE END Header */ | ||
| /* Define to prevent recursive inclusion -------------------------------------*/ | ||
| #ifndef __SPI_H__ | ||
| #define __SPI_H__ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /* Includes ------------------------------------------------------------------*/ | ||
| #include "main.h" | ||
|
|
||
| /* USER CODE BEGIN Includes */ | ||
|
|
||
| /* USER CODE END Includes */ | ||
|
|
||
| extern SPI_HandleTypeDef hspi1; | ||
|
|
||
| /* USER CODE BEGIN Private defines */ | ||
|
|
||
| /* USER CODE END Private defines */ | ||
|
|
||
| void MX_SPI1_Init(void); | ||
|
|
||
| /* USER CODE BEGIN Prototypes */ | ||
|
|
||
| /* USER CODE END Prototypes */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* __SPI_H__ */ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #ifndef SPI_MUTEX_H | ||
| #define SPI_MUTEX_H | ||
| #include "cmsis_os.h" | ||
|
|
||
| extern osMutexId_t spi1_mutex; | ||
| void spi_mutex_init(void); | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge conflict markers detected in the file. Please resolve the conflict and remove the markers before committing.