Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
<<<<<<< HEAD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

Merge conflict markers detected in the file. Please resolve the conflict and remove the markers before committing.

"configurations": [
{
"name": "Firmware",
Expand All @@ -11,4 +12,31 @@
}
],
"version": 4
=======
"configurations": [
{
"name": "STM32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/CSM/firmware/Core/Inc",
"${workspaceFolder}/CSM/firmware/Core/Src",
"${workspaceFolder}/CSM/firmware/Libs/AFBR-S50",
"${workspaceFolder}/CSM/firmware/Libs/AFBR-S50/Include",
"${workspaceFolder}/CSM/firmware/Drivers/STM32G4xx_HAL_Driver/Inc",
"${workspaceFolder}/CSM/firmware/Drivers/CMSIS/Device/ST/STM32G4xx/Include",
"${workspaceFolder}/CSM/firmware/Drivers/CMSIS/Include",
"${workspaceFolder}/CSM/firmware/Middlewares/Third_Party/FreeRTOS/Source/include",
"${workspaceFolder}/CSM/firmware/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2"
],
"defines": [
"STM32G491xx",
"USE_HAL_DRIVER"
],
"compilerPath": "arm-none-eabi-gcc",
"cStandard": "c11",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
>>>>>>> 00f9461c (Added suspension potentiometer, strain gauge, and imu code)
}
28 changes: 21 additions & 7 deletions CSM/firmware/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The defines list still contains STM32G474xx, but the linker script and startup script have been updated to STM32G491xx. This mismatch might lead to incorrect peripheral configurations or missing features if the target hardware is indeed the G491.

Suggested change
"STM32G474xx",
"STM32G491xx",

],
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",
],
)
)
2 changes: 1 addition & 1 deletion CSM/firmware/Core/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES ( 56 )
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configTOTAL_HEAP_SIZE ((size_t)16384)
#define configTOTAL_HEAP_SIZE ((size_t)65536)
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
Expand Down
3 changes: 0 additions & 3 deletions CSM/firmware/Core/Inc/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ extern ADC_HandleTypeDef hadc1;

extern ADC_HandleTypeDef hadc2;

extern ADC_HandleTypeDef hadc3;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_ADC1_Init(void);
void MX_ADC2_Init(void);
void MX_ADC3_Init(void);

/* USER CODE BEGIN Prototypes */

Expand Down
12 changes: 12 additions & 0 deletions CSM/firmware/Core/Inc/csm_can.h
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
52 changes: 52 additions & 0 deletions CSM/firmware/Core/Inc/dma.h
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__ */

3 changes: 0 additions & 3 deletions CSM/firmware/Core/Inc/fdcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ extern "C" {

/* USER CODE END Includes */

extern FDCAN_HandleTypeDef hfdcan1;

extern FDCAN_HandleTypeDef hfdcan2;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_FDCAN1_Init(void);
void MX_FDCAN2_Init(void);

/* USER CODE BEGIN Prototypes */
Expand Down
73 changes: 73 additions & 0 deletions CSM/firmware/Core/Inc/imu.h
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 */
21 changes: 21 additions & 0 deletions CSM/firmware/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ void Error_Handler(void);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define IMU_INT1_Pin GPIO_PIN_13
#define IMU_INT1_GPIO_Port GPIOC
#define IMU_INT1_EXTI_IRQn EXTI15_10_IRQn
#define IMU_INT2_Pin GPIO_PIN_14
#define IMU_INT2_GPIO_Port GPIOC
#define IMU_INT2_EXTI_IRQn EXTI15_10_IRQn
#define STRAIN_GAUGE_VA_IN_Pin GPIO_PIN_3
#define STRAIN_GAUGE_VA_IN_GPIO_Port GPIOA
#define RH_CS_Pin GPIO_PIN_0
#define RH_CS_GPIO_Port GPIOB
#define IMU_CS_Pin GPIO_PIN_1
#define IMU_CS_GPIO_Port GPIOB
#define SUS_POT_VWIPER_Pin GPIO_PIN_2
#define SUS_POT_VWIPER_GPIO_Port GPIOB
#define STRAIN_GAUGE_VB_IN_Pin GPIO_PIN_14
#define STRAIN_GAUGE_VB_IN_GPIO_Port GPIOB
#define RH_IRQ_Pin GPIO_PIN_15
#define RH_IRQ_GPIO_Port GPIOB
#define RH_IRQ_EXTI_IRQn EXTI15_10_IRQn
#define BOOT0trig_Pin GPIO_PIN_9
#define BOOT0trig_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */

Expand Down
11 changes: 11 additions & 0 deletions CSM/firmware/Core/Inc/ride_height.h
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
52 changes: 52 additions & 0 deletions CSM/firmware/Core/Inc/spi.h
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__ */

7 changes: 7 additions & 0 deletions CSM/firmware/Core/Inc/spi_mutex.h
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
6 changes: 3 additions & 3 deletions CSM/firmware/Core/Inc/stm32g4xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
#define HAL_SPI_MODULE_ENABLED
/*#define HAL_SRAM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
/*#define HAL_UART_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
Expand Down Expand Up @@ -115,7 +115,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */
#define HSE_VALUE (16000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

#if !defined (HSE_STARTUP_TIMEOUT)
Expand Down
4 changes: 4 additions & 0 deletions CSM/firmware/Core/Inc/stm32g4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void DMA1_Channel1_IRQHandler(void);
void DMA1_Channel2_IRQHandler(void);
void USB_LP_IRQHandler(void);
void EXTI15_10_IRQHandler(void);
void TIM6_DAC_IRQHandler(void);
void TIM20_UP_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
Loading
Loading