Skip to content

Commit df4fe35

Browse files
Mahesh Chandrasekharmahir-mahota
authored andcommitted
Added pressure sensor polling functionality
1 parent 42daabb commit df4fe35

17 files changed

+9840
-255
lines changed

Sensors/.mxproject

Lines changed: 6 additions & 2 deletions
Large diffs are not rendered by default.

Sensors/.project

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<projectDescription>
3-
<name>Sensors</name>
4-
<comment></comment>
5-
<projects>
6-
</projects>
7-
<buildSpec>
8-
<buildCommand>
9-
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10-
<triggers>clean,full,incremental,</triggers>
11-
<arguments>
12-
</arguments>
13-
</buildCommand>
14-
<buildCommand>
15-
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16-
<triggers>full,incremental,</triggers>
17-
<arguments>
18-
</arguments>
19-
</buildCommand>
20-
</buildSpec>
21-
<natures>
22-
<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
23-
<nature>com.st.stm32cube.ide.mcu.MCUCubeProjectNature</nature>
24-
<nature>org.eclipse.cdt.core.cnature</nature>
25-
<nature>com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature</nature>
26-
<nature>com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature</nature>
27-
<nature>com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature</nature>
28-
<nature>com.st.stm32cube.ide.mcu.MCURootProjectNature</nature>
29-
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
30-
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
31-
</natures>
32-
<linkedResources>
33-
<link>
34-
<name>Common</name>
35-
<type>2</type>
36-
<location>C:/Users/mahir/Desktop/Waterloop/G6-STM32/Common</location>
37-
</link>
38-
</linkedResources>
39-
</projectDescription>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Sensors</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10+
<triggers>clean,full,incremental,</triggers>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16+
<triggers>full,incremental,</triggers>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
</buildSpec>
21+
<natures>
22+
<nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
23+
<nature>com.st.stm32cube.ide.mcu.MCUCubeProjectNature</nature>
24+
<nature>org.eclipse.cdt.core.cnature</nature>
25+
<nature>com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature</nature>
26+
<nature>com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature</nature>
27+
<nature>com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature</nature>
28+
<nature>com.st.stm32cube.ide.mcu.MCURootProjectNature</nature>
29+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
30+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
31+
</natures>
32+
</projectDescription>

Sensors/Core/Inc/adc.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file adc.h
5+
* @brief This file contains all the function prototypes for
6+
* the adc.c file
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2024 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
/* Define to prevent recursive inclusion -------------------------------------*/
21+
#ifndef __ADC_H__
22+
#define __ADC_H__
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* Includes ------------------------------------------------------------------*/
29+
#include "main.h"
30+
31+
/* USER CODE BEGIN Includes */
32+
33+
/* USER CODE END Includes */
34+
35+
extern ADC_HandleTypeDef hadc1;
36+
37+
/* USER CODE BEGIN Private defines */
38+
39+
/* USER CODE END Private defines */
40+
41+
void MX_ADC1_Init(void);
42+
43+
/* USER CODE BEGIN Prototypes */
44+
45+
/* USER CODE END Prototypes */
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* __ADC_H__ */
52+

Sensors/Core/Inc/can_driver.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#include <stdint.h>
3+
#include "can.h"
4+
5+
#define MAX_BYTES 8
6+
7+
typedef struct {
8+
uint32_t id;
9+
uint8_t start;
10+
uint8_t end;
11+
} Data_Segment_t;
12+
13+
typedef struct {
14+
CAN_HandleTypeDef* hcan; // CAN handler (hcan1, hcan2 or hcan3)
15+
uint32_t id_type; // CAN_ID_STD or CAN_ID_EXT
16+
uint32_t rtr; // CAN_RTR_DATA or CAN_RTR_REMOTE
17+
uint32_t data_length; // 0 - MAX_BYTES
18+
uint32_t time_stamp; // time stamp returned in rx header
19+
uint32_t id; // message ID
20+
uint8_t data[MAX_BYTES]; // message data
21+
} CAN_Frame_t;
22+
23+
CAN_Frame_t CAN_frame_init(CAN_HandleTypeDef* handler, uint32_t id);
24+
void CAN_send_frame(CAN_Frame_t self);
25+
CAN_Frame_t CAN_get_frame(CAN_HandleTypeDef* handler, uint32_t fifo_number);
26+
uint32_t CAN_get_segment(CAN_Frame_t self, Data_Segment_t segment);
27+
uint8_t CAN_set_segment(CAN_Frame_t* self, Data_Segment_t segment, uint32_t bytes);

Sensors/Core/Inc/config.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
#include "can_driver.h"
3+
4+
// GENERAL DEFINES
5+
#define MAX_CAN_PAYLOAD_BTYES 8
6+
#define BUFF_SIZE 32
7+
#define WARN_OFFSET 0xFF
8+
9+
// MOTOR CONTROLLER
10+
#define MOTOR_CONTROLLER_1 0x10F8109A
11+
#define MOTOR_CONTROLLER_2 0x10F8108D
12+
#define MOTOR_CONTROLLER 0xFF
13+
#define MOTOR_CONTROLLER_WARN MOTOR_CONTROLLER - WARN_OFFSET
14+
// BMS
15+
#define BMS_BOARD 0xFF
16+
#define BMS_BOARD_WARN BMS_TEMP - WARN_OFFSET
17+
// SENSORS
18+
#define SENSOR_BOARD 0xFF
19+
#define SENSOR_BOARD_WARN SENSOR_BOARD - WARN_OFFSET
20+
21+
// BEGIN KELLY DEFS
22+
// FRAME 1
23+
const Data_Segment_t DRIVING_DIRECTION_K = {MOTOR_CONTROLLER_1, 1, 1};
24+
const Data_Segment_t MOTOR_SPEED_K = {MOTOR_CONTROLLER_1, 2, 3};
25+
const Data_Segment_t MOTOR_ERROR_CODE_K = {MOTOR_CONTROLLER_1, 4, 4};
26+
// FRAME 2
27+
const Data_Segment_t BATTERY_VOLTAGE_K = {MOTOR_CONTROLLER_2, 1, 2};
28+
const Data_Segment_t BATTERY_CURRENT_K = {MOTOR_CONTROLLER_2, 3, 4};
29+
const Data_Segment_t MOTOR_TEMP_K = {MOTOR_CONTROLLER_2, 5, 6};
30+
const Data_Segment_t MOTOR_CONTROLLER_TEMP_K = {MOTOR_CONTROLLER_2, 7, 8};
31+
// END KELLY DEFS
32+
33+
// BEGIN MOTOR CONTROLLER DEFS
34+
const Data_Segment_t BATTERY_VOLTAGE = {MOTOR_CONTROLLER, 1, 2};
35+
const Data_Segment_t BATTERY_CURRENT = {MOTOR_CONTROLLER, 3, 4};
36+
const Data_Segment_t MOTOR_SPEED = {MOTOR_CONTROLLER, 5, 6};
37+
const Data_Segment_t MOTOR_CONTROLLER_TEMP = {MOTOR_CONTROLLER, 7, 7};
38+
const Data_Segment_t DRIVING_DIRECTION = {MOTOR_CONTROLLER, 8, 8};
39+
const Data_Segment_t MOTOR_ERROR_CODE = {MOTOR_CONTROLLER, 8, 8};
40+
// END MOTOR CONTROLLER DEFS
41+
42+
// BEGIN BMS DEFS
43+
const Data_Segment_t MUX1_TEMP = {BMS_BOARD, 1, 1};
44+
const Data_Segment_t MUX2_TEMP = {BMS_BOARD, 2, 2};
45+
const Data_Segment_t MUX3_TEMP = {BMS_BOARD, 3, 3};
46+
const Data_Segment_t MUX4_TEMP = {BMS_BOARD, 4, 4};
47+
const Data_Segment_t MUX5_TEMP = {BMS_BOARD, 5, 5};
48+
const Data_Segment_t MUX6_TEMP = {BMS_BOARD, 6, 6};
49+
const Data_Segment_t BMS_ERROR_CODE = {BMS_BOARD, 7, 7};
50+
// END BMS DEFS
51+
52+
// BEGIN SENSORS BOARD DEFS
53+
const Data_Segment_t PRESSURE_SENSOR_DATA = {SENSOR_BOARD, 1, 1};
54+
const Data_Segment_t IMU_DATA = {SENSOR_BOARD, 2, 3};
55+
const Data_Segment_t LIM_ONE_TEMP = {SENSOR_BOARD, 4, 5};
56+
const Data_Segment_t LIM_TWO_TEMP = {SENSOR_BOARD, 6, 7};
57+
const Data_Segment_t SENSORS_ERROR_CODE = {SENSOR_BOARD, 8, 8};
58+
// END SENSORS BOARD DEFS

Sensors/Core/Inc/stm32f7xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define HAL_MODULE_ENABLED
3939

4040
/* #define HAL_CRYP_MODULE_ENABLED */
41-
/* #define HAL_ADC_MODULE_ENABLED */
41+
#define HAL_ADC_MODULE_ENABLED
4242
#define HAL_CAN_MODULE_ENABLED
4343
/* #define HAL_CEC_MODULE_ENABLED */
4444
/* #define HAL_CRC_MODULE_ENABLED */

Sensors/Core/Src/adc.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file adc.c
5+
* @brief This file provides code for the configuration
6+
* of the ADC instances.
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2024 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
/* Includes ------------------------------------------------------------------*/
21+
#include "adc.h"
22+
23+
/* USER CODE BEGIN 0 */
24+
25+
/* USER CODE END 0 */
26+
27+
ADC_HandleTypeDef hadc1;
28+
29+
/* ADC1 init function */
30+
void MX_ADC1_Init(void)
31+
{
32+
33+
/* USER CODE BEGIN ADC1_Init 0 */
34+
35+
/* USER CODE END ADC1_Init 0 */
36+
37+
ADC_ChannelConfTypeDef sConfig = {0};
38+
39+
/* USER CODE BEGIN ADC1_Init 1 */
40+
41+
/* USER CODE END ADC1_Init 1 */
42+
43+
/** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
44+
*/
45+
hadc1.Instance = ADC1;
46+
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
47+
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
48+
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
49+
hadc1.Init.ContinuousConvMode = DISABLE;
50+
hadc1.Init.DiscontinuousConvMode = DISABLE;
51+
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
52+
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
53+
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
54+
hadc1.Init.NbrOfConversion = 1;
55+
hadc1.Init.DMAContinuousRequests = DISABLE;
56+
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
57+
if (HAL_ADC_Init(&hadc1) != HAL_OK)
58+
{
59+
Error_Handler();
60+
}
61+
62+
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
63+
*/
64+
sConfig.Channel = ADC_CHANNEL_5;
65+
sConfig.Rank = ADC_REGULAR_RANK_1;
66+
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
67+
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
68+
{
69+
Error_Handler();
70+
}
71+
/* USER CODE BEGIN ADC1_Init 2 */
72+
73+
/* USER CODE END ADC1_Init 2 */
74+
75+
}
76+
77+
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
78+
{
79+
80+
GPIO_InitTypeDef GPIO_InitStruct = {0};
81+
if(adcHandle->Instance==ADC1)
82+
{
83+
/* USER CODE BEGIN ADC1_MspInit 0 */
84+
85+
/* USER CODE END ADC1_MspInit 0 */
86+
/* ADC1 clock enable */
87+
__HAL_RCC_ADC1_CLK_ENABLE();
88+
89+
__HAL_RCC_GPIOA_CLK_ENABLE();
90+
/**ADC1 GPIO Configuration
91+
PA5 ------> ADC1_IN5
92+
*/
93+
GPIO_InitStruct.Pin = GPIO_PIN_5;
94+
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
95+
GPIO_InitStruct.Pull = GPIO_NOPULL;
96+
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
97+
98+
/* USER CODE BEGIN ADC1_MspInit 1 */
99+
100+
/* USER CODE END ADC1_MspInit 1 */
101+
}
102+
}
103+
104+
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
105+
{
106+
107+
if(adcHandle->Instance==ADC1)
108+
{
109+
/* USER CODE BEGIN ADC1_MspDeInit 0 */
110+
111+
/* USER CODE END ADC1_MspDeInit 0 */
112+
/* Peripheral clock disable */
113+
__HAL_RCC_ADC1_CLK_DISABLE();
114+
115+
/**ADC1 GPIO Configuration
116+
PA5 ------> ADC1_IN5
117+
*/
118+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
119+
120+
/* USER CODE BEGIN ADC1_MspDeInit 1 */
121+
122+
/* USER CODE END ADC1_MspDeInit 1 */
123+
}
124+
}
125+
126+
/* USER CODE BEGIN 1 */
127+
128+
/* USER CODE END 1 */

0 commit comments

Comments
 (0)