Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions | Variables
main.c File Reference

: Main program body More...

#include "main.h"
#include "../Inc/Files/can1_dbc.h"
#include "../Inc/Scheduler/Scheduler.h"
#include "../Inc/Sensors/AnalogSensor.h"
#include "../Inc/Systems/Comms/Can/Can.h"
#include "../Inc/Systems/Controller/Apps.h"
#include "../Inc/Systems/Controller/BrakeSystemControl.h"
#include "../Inc/Systems/Controller/RTD.h"
#include "../Inc/Systems/Controller/TorqueControl.h"
#include "../Inc/Systems/External/Inverter.h"
#include "../Inc/Systems/Monitor/AppsMonitor.h"
#include "../Inc/Systems/Monitor/BrakePolice.h"
#include "../Inc/Systems/Monitor/RTDMonitor.h"
#include "../Inc/Systems/Monitor/TorquePolice.h"
#include "../Inc/Utils/Constants.h"
#include "stm32f7xx_hal_adc.h"
Include dependency graph for main.c:

Go to the source code of this file.

Functions

void SystemClock_Config (void)
 System Clock Configuration. More...
 
static void MX_GPIO_Init (void)
 GPIO Initialization Function. More...
 
static void MX_DMA_Init (void)
 
static void MX_TIM1_Init (void)
 TIM1 Initialization Function. More...
 
static void MX_ADC1_Init (void)
 ADC1 Initialization Function. More...
 
static void MX_ADC2_Init (void)
 ADC2 Initialization Function. More...
 
static void MX_ADC3_Init (void)
 ADC3 Initialization Function. More...
 
static void MX_CAN1_Init (void)
 CAN1 Initialization Function. More...
 
static void MX_CAN2_Init (void)
 CAN2 Initialization Function. More...
 
static void MX_USART3_UART_Init (void)
 USART3 Initialization Function. More...
 
static void MX_TIM2_Init (void)
 TIM2 Initialization Function. More...
 
static void MX_DAC_Init (void)
 DAC Initialization Function. More...
 
static void MX_CAN3_Init (void)
 CAN3 Initialization Function. More...
 
static void MX_I2C2_Init (void)
 I2C2 Initialization Function. More...
 
static void MX_I2C4_Init (void)
 I2C4 Initialization Function. More...
 
static void MX_SPI4_Init (void)
 SPI4 Initialization Function. More...
 
static void MX_SPI6_Init (void)
 SPI6 Initialization Function. More...
 
int main (void)
 The application entry point. More...
 
int _write (int file, char *data, int len)
 
void Error_Handler (void)
 This function is executed in case of error occurrence. More...
 

Variables

ADC_HandleTypeDef hadc1
 
ADC_HandleTypeDef hadc2
 
ADC_HandleTypeDef hadc3
 
DMA_HandleTypeDef hdma_adc1
 
DMA_HandleTypeDef hdma_adc2
 
DMA_HandleTypeDef hdma_adc3
 
CAN_HandleTypeDef hcan1
 
CAN_HandleTypeDef hcan2
 
CAN_HandleTypeDef hcan3
 
DAC_HandleTypeDef hdac
 
DMA_HandleTypeDef hdma_dac1
 
DMA_HandleTypeDef hdma_dac2
 
I2C_HandleTypeDef hi2c2
 
I2C_HandleTypeDef hi2c4
 
SPI_HandleTypeDef hspi4
 
SPI_HandleTypeDef hspi6
 
TIM_HandleTypeDef htim1
 
TIM_HandleTypeDef htim2
 
UART_HandleTypeDef huart3
 
uint32_t adc1_buffer [ADC1_CHANNEL_SIZE]
 
uint32_t adc2_buffer [ADC2_CHANNEL_SIZE]
 
uint32_t adc3_buffer [ADC3_CHANNEL_SIZE]
 
uint32_t dac1_buffer [DAC1_BUFFER_SIZE]
 
uint32_t dac2_buffer [DAC2_BUFFER_SIZE]
 
uint8_t digital_out_buffer [NUM_DIGITAL_OUTPUTS]
 
uint8_t digital_in_buffer [NUM_DIGITAL_INPUTS]
 

Detailed Description

: Main program body

Attention

Copyright (c) 2024 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.

Definition in file main.c.

Function Documentation

◆ _write()

int _write ( int  file,
char *  data,
int  len 
)

Definition at line 1395 of file main.c.

1396{
1397 // Transmit data using USART3
1398 HAL_UART_Transmit(&huart3, (uint8_t *)data, len, HAL_MAX_DELAY);
1399 return len;
1400
1401#endif // <--- DONT DELETE THIS, IT IS LINKED TO LAST LINE IN MAIN FUNCTION TO ALLOW SIL BUILDS
1402
1403}
UART_HandleTypeDef huart3
Definition: main.c:84

◆ Error_Handler()

void Error_Handler ( void  )

This function is executed in case of error occurrence.

Return values
None

Definition at line 1411 of file main.c.

1412{
1413 /* USER CODE BEGIN Error_Handler_Debug */
1414 /* User can add his own implementation to report the HAL error return state */
1415
1416 #ifndef TEST_MODE
1417 __disable_irq();
1418 #endif
1419
1420 while (1)
1421 {
1422 printf("Error_Handler\r\n");
1423 }
1424 /* USER CODE END Error_Handler_Debug */
1425}
Here is the caller graph for this function:

◆ main()

int main ( void  )

The application entry point.

Return values
int

Definition at line 127 of file main.c.

128{
129
130 /* USER CODE BEGIN 1 */
131
132 #ifndef TEST_MODE
133
134 /* USER CODE END 1 */
135
136 /* MCU Configuration--------------------------------------------------------*/
137
138 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
139 HAL_Init();
140
141 /* USER CODE BEGIN Init */
142
143 /* USER CODE END Init */
144
145 /* Configure the system clock */
147
148 /* USER CODE BEGIN SysInit */
149
150 /* USER CODE END SysInit */
151
152 /* Initialize all configured peripherals */
153 MX_GPIO_Init();
154 MX_DMA_Init();
155 MX_TIM1_Init();
156 MX_ADC1_Init();
157 MX_ADC2_Init();
158 MX_ADC3_Init();
159 MX_CAN1_Init();
160 MX_CAN2_Init();
162 MX_TIM2_Init();
163 MX_DAC_Init();
164 MX_CAN3_Init();
165 MX_I2C2_Init();
166 MX_I2C4_Init();
167 MX_SPI4_Init();
168 MX_SPI6_Init();
169 /* USER CODE BEGIN 2 */
170
171 // Clear the screen
172 printf("\033[2J\033[1;1H");
173 printf("Welcome to VCU!!!\r\n");
174 if (init_CANBus(CAN_1) != 0) {
175 printf("CAN1 init failed\r\n");
176 }
177
178 // Begin ADC DMA
179 if(HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc1_buffer, 7) != HAL_OK) {
181 }
182
183 if(HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2_buffer, 7) != HAL_OK) {
185 }
186
187 if(HAL_ADC_Start_DMA(&hadc3, (uint32_t*)adc3_buffer, 8) != HAL_OK) {
189 }
190
191 // Begin DAC DMA
192 if(HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t*)dac1_buffer, DAC1_BUFFER_SIZE, DAC_ALIGN_12B_R) != HAL_OK) {
194 }
195
196 uint32_t multi_mode = (ADC123_COMMON->CCR & ADC_CCR_MULTI);
197 printf("ADC Multi-mode: 0x%08lX\r\n", multi_mode);
198
199 #endif
200
201 // Add a message to the CAN message list
202 CAN_Signal_Template signals[8] = {
203 { .name = "VDD", .start_bit = 0, .length = 8, .endian = 0, .isSigned = 0, .scale = 0.1, .offset = 0, .min = 0, .max = 255, .unit = "voltage", .reciever = "reciever" },
204 { .name = "Char 2", .start_bit = 8, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
205 { .name = "Char 3", .start_bit = 16, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
206 { .name = "Char 4", .start_bit = 24, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
207 { .name = "Char 5", .start_bit = 32, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
208 { .name = "Char 6", .start_bit = 40, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
209 { .name = "Char 7", .start_bit = 48, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" },
210 { .name = "Char 8", .start_bit = 56, .length = 8, .endian = 0, .isSigned = 0, .scale = 1, .offset = 0, .min = 0, .max = 255, .unit = "unit", .reciever = "reciever" }
211 };
212
213 add_message_lop(CAN_1, 0x123, 8, 0, 0, "Message 1", "AD3", 8, signals);
214
215
216 add_message_lop(CAN_1, 0x124, 8, 0, 0, "Message 2", "VCU", 8, signals);
217
218 // Print the CAN message list
220
221 uint8_t txdata[8] = {0, 1, 2, 3, 4, 5, 6, 7};
222 send_CAN_message(CAN_1, CAN_2A, 124, txdata, 8);
223
224 // Make Apps Controller and Monitor
225 Apps apps;
226 initApps(&apps, 10, 8, 4);
227
228 AppsMonitor am;
229 initAppsMonitor(&am, &apps, 10);
230
231 // Bind Appsmonitor to Apps
232 apps.base.addMonitor(&apps, &am);
233
234 // Start the Apps Monitor
235 startAppsMonitor(&am);
236
237 // Make Break Controller and Monitor
239 initBrakeSystemControl(&bsc, 10, 200, 400, 1000, 10, 5, 6, 0);
240
241 BrakePolice bp;
242 initBrakePolice(&bp, &bsc, 100, 200);
243
244 // Bind BrakePolice to BrakeSystemControl
245 bsc.base.addMonitor(&bsc, &bp);
246
247 // Start the Brake Controller and Monitor
249 startBrakePolice(&bp);
250
251 // Make RTD Controller and Monitor
252 RTD rtd;
253 initRTD(&rtd, &apps, &bsc, 10, 0, 1);
254
255 RTDMonitor rm;
256 initRTDMonitor(&rm, &rtd, 10);
257
258 // Bind RTDMonitor to RTD
259 rtd.base.addMonitor(&rtd, &rm);
260
261 // Start the RTD Controller and Monitor
262 startRTD(&rtd);
263 startRTDMonitor(&rm);
264
265 // Make Torque Controller and Monitor
266 TorqueControl tc;
267 initTorqueControl(&tc, &apps, 10, 240);
268
269 TorquePolice tp;
270 initTorquePolice(&tp, &tc, &bsc, &rtd, 100, 240);
271
272 // Bind TorquePolice to TorqueControl
273 tc.base.addMonitor(&tc, &tp);
274
275 // Start the Torque Controller and Monitor
278
279 // Make Inverter
280 Inverter inverter;
281 initInverter(&inverter, &tc, 10, 200, 100, 400);
282
283 // Make Scheduler from updateable array
284 Scheduler scheduler;
285
286 Updateable* updateables[6];
287 updateables[0] = &apps.base.system.updateable;
288 updateables[1] = &bsc.base.system.updateable;
289 updateables[2] = &rtd.base.system.updateable;
290 updateables[3] = &tc.base.system.updateable;
291 updateables[4] = &inverter.base.system.updateable;
292 updateables[5] = NULL;
293
294 SchedulerInit(&scheduler, updateables);
295
296 // Start the Scheduler
297 SchedulerRun(&scheduler);
298 /* USER CODE END 2 */
299
300 /* Infinite loop */
301 /* USER CODE BEGIN WHILE */
302 while (1)
303 {
304 /* USER CODE END WHILE */
305
306 /* USER CODE BEGIN 3 */
307 }
308 /* USER CODE END 3 */
309
310 #ifndef TEST_MODE
311}
void initAppsMonitor(AppsMonitor *am, Apps *apps, int hz)
Definition: AppsMonitor.c:6
int startAppsMonitor(AppsMonitor *am)
Definition: AppsMonitor.c:13
void initApps(Apps *apps, int hz, int channel1, int channel2)
Initializes the APPs with the given frequency and channel.
Definition: Apps.c:7
int startBrakePolice(BrakePolice *bp)
Definition: BrakePolice.c:13
void initBrakePolice(BrakePolice *bp, BrakeSystemControl *bsc, int hz, int maxTemp)
Definition: BrakePolice.c:5
void initBrakeSystemControl(BrakeSystemControl *bsc, int hz, int maxTemp, int brakeLightActivationPoint, int heavyBrakingActivationPoint, int fbp_channel, int rbp_channel, int temp_channel, int light_port)
Initializes the Braking System with initial settings.
int startBrakeSystemControl(BrakeSystemControl *bsc)
Starts the Brake System Controller.
int init_CANBus(CANBus bus)
Initializes the CANBus struct.
Definition: Can.c:17
@ CAN_1
Definition: Can.h:99
int add_message_lop(CANBus bus, int id, int dlc, int ide, int rtr, const char *name, const char *sender, int signal_count, CAN_Signal_Template *signals)
Adds a message to the CAN message list by passing in the individual message parameters hence "LOP" (L...
Definition: Can.c:55
int send_CAN_message(CANBus bus, CANProtocol protocol, uint32_t id, uint8_t *data, uint8_t len)
Sends a CAN message.
Definition: Can.c:79
@ CAN_2A
Definition: Can.h:105
void print_CAN_Messages_Lists()
Prints the CAN message list.
Definition: Can.c:190
#define DAC1_BUFFER_SIZE
Definition: Constants.h:9
void initInverter(Inverter *inverter, TorqueControl *tc, int hz, int maxCurrent, int maxTemp, int maxVoltage)
Initializes the Inverter with initial settings.
Definition: Inverter.c:6
void initRTDMonitor(RTDMonitor *rtdm, RTD *rtd, int hz)
Initializes the RTD Monitor with initial settings.
Definition: RTDMonitor.c:4
int startRTDMonitor(RTDMonitor *rtdm)
Starts the RTD Monitor.
Definition: RTDMonitor.c:9
int startRTD(RTD *rtd)
Starts the RTD Actuator.
Definition: RTD.c:23
void initRTD(RTD *rtd, Apps *apps, BrakeSystemControl *bsc, int hz, int buttonPort, int piezoPort)
Initializes the RTD Actuator with initial settings.
Definition: RTD.c:6
void SchedulerInit(Scheduler *scheduler, Updateable *updatableArray[])
Initializes the scheduler with the given sensors.
Definition: Scheduler.c:14
void SchedulerRun(Scheduler *scheduler)
Runs the scheduler, executing tasks based on their priority.
Definition: Scheduler.c:49
static void MX_CAN3_Init(void)
CAN3 Initialization Function.
Definition: main.c:814
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition: main.c:1411
uint32_t adc3_buffer[ADC3_CHANNEL_SIZE]
Definition: main.c:115
static void MX_USART3_UART_Init(void)
USART3 Initialization Function.
Definition: main.c:1168
static void MX_TIM1_Init(void)
TIM1 Initialization Function.
Definition: main.c:1074
ADC_HandleTypeDef hadc1
Definition: main.c:60
static void MX_CAN1_Init(void)
CAN1 Initialization Function.
Definition: main.c:694
DAC_HandleTypeDef hdac
Definition: main.c:71
static void MX_ADC2_Init(void)
ADC2 Initialization Function.
Definition: main.c:473
static void MX_SPI6_Init(void)
SPI6 Initialization Function.
Definition: main.c:1034
static void MX_DMA_Init(void)
Definition: main.c:1201
uint32_t adc2_buffer[ADC2_CHANNEL_SIZE]
Definition: main.c:114
void SystemClock_Config(void)
System Clock Configuration.
Definition: main.c:317
static void MX_CAN2_Init(void)
CAN2 Initialization Function.
Definition: main.c:754
ADC_HandleTypeDef hadc3
Definition: main.c:62
static void MX_ADC1_Init(void)
ADC1 Initialization Function.
Definition: main.c:368
ADC_HandleTypeDef hadc2
Definition: main.c:61
static void MX_ADC3_Init(void)
ADC3 Initialization Function.
Definition: main.c:579
static void MX_SPI4_Init(void)
SPI4 Initialization Function.
Definition: main.c:994
static void MX_GPIO_Init(void)
GPIO Initialization Function.
Definition: main.c:1232
static void MX_DAC_Init(void)
DAC Initialization Function.
Definition: main.c:851
static void MX_I2C4_Init(void)
I2C4 Initialization Function.
Definition: main.c:946
static void MX_I2C2_Init(void)
I2C2 Initialization Function.
Definition: main.c:898
uint32_t adc1_buffer[ADC1_CHANNEL_SIZE]
Definition: main.c:113
static void MX_TIM2_Init(void)
TIM2 Initialization Function.
Definition: main.c:1121
uint32_t dac1_buffer[DAC1_BUFFER_SIZE]
Definition: main.c:116
int startTorqueControl(TorqueControl *tc)
Starts the Torque Control Actuator.
Definition: TorqueControl.c:13
void initTorqueControl(TorqueControl *tc, Apps *apps, int hz, float maxTorque)
Initializes the Torque Control Actuator with initial settings.
Definition: TorqueControl.c:6
void initTorquePolice(TorquePolice *tp, TorqueControl *tc, BrakeSystemControl *bsc, RTD *rtd, int hz, float maxTorque)
Definition: TorquePolice.c:5
int startTorquePolice(TorquePolice *tp)
Definition: TorquePolice.c:15
Definition: Apps.h:22
ControllerSystem base
Definition: Apps.h:23
ControllerSystem base
char name[MAX_SIGNAL_NAME_LENGTH]
Definition: Can.h:20
int(* addMonitor)(struct ControllerSystem *controller, MonitorSystem *monitor)
ExternalSystem base
Definition: Inverter.h:9
Definition: RTD.h:11
ControllerSystem base
Definition: RTD.h:12
Updateable updateable
Definition: System.h:18
ControllerSystem base
Definition: TorqueControl.h:19
Here is the call graph for this function:

◆ MX_ADC1_Init()

static void MX_ADC1_Init ( void  )
static

ADC1 Initialization Function.

Parameters
None
Return values
None

Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Definition at line 368 of file main.c.

369{
370
371 /* USER CODE BEGIN ADC1_Init 0 */
372
373 /* USER CODE END ADC1_Init 0 */
374
375 ADC_ChannelConfTypeDef sConfig = {0};
376
377 /* USER CODE BEGIN ADC1_Init 1 */
378
379 /* USER CODE END ADC1_Init 1 */
380
383 hadc1.Instance = ADC1;
384 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
385 hadc1.Init.Resolution = ADC_RESOLUTION_12B;
386 hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
387 hadc1.Init.ContinuousConvMode = DISABLE;
388 hadc1.Init.DiscontinuousConvMode = DISABLE;
389 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
390 hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
391 hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
392 hadc1.Init.NbrOfConversion = 7;
393 hadc1.Init.DMAContinuousRequests = ENABLE;
394 hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
395 if (HAL_ADC_Init(&hadc1) != HAL_OK)
396 {
398 }
399
402 sConfig.Channel = ADC_CHANNEL_0;
403 sConfig.Rank = ADC_REGULAR_RANK_1;
404 sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
405 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
406 {
408 }
409
412 sConfig.Channel = ADC_CHANNEL_2;
413 sConfig.Rank = ADC_REGULAR_RANK_2;
414 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
415 {
417 }
418
421 sConfig.Channel = ADC_CHANNEL_6;
422 sConfig.Rank = ADC_REGULAR_RANK_3;
423 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
424 {
426 }
427
430 sConfig.Channel = ADC_CHANNEL_8;
431 sConfig.Rank = ADC_REGULAR_RANK_4;
432 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
433 {
435 }
436
439 sConfig.Channel = ADC_CHANNEL_10;
440 sConfig.Rank = ADC_REGULAR_RANK_5;
441 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
442 {
444 }
445
448 sConfig.Channel = ADC_CHANNEL_12;
449 sConfig.Rank = ADC_REGULAR_RANK_6;
450 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
451 {
453 }
454
457 sConfig.Rank = ADC_REGULAR_RANK_7;
458 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
459 {
461 }
462 /* USER CODE BEGIN ADC1_Init 2 */
463
464 /* USER CODE END ADC1_Init 2 */
465
466}
#define ENABLE(item_)
Definition: Updateable.h:10
#define DISABLE(item_)
Definition: Updateable.h:11
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_ADC2_Init()

static void MX_ADC2_Init ( void  )
static

ADC2 Initialization Function.

Parameters
None
Return values
None

Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Definition at line 473 of file main.c.

474{
475
476 /* USER CODE BEGIN ADC2_Init 0 */
477
478 /* USER CODE END ADC2_Init 0 */
479
480 ADC_ChannelConfTypeDef sConfig = {0};
481
482 /* USER CODE BEGIN ADC2_Init 1 */
483
484 /* USER CODE END ADC2_Init 1 */
485
488 hadc2.Instance = ADC2;
489 hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
490 hadc2.Init.Resolution = ADC_RESOLUTION_12B;
491 hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
492 hadc2.Init.ContinuousConvMode = DISABLE;
493 hadc2.Init.DiscontinuousConvMode = DISABLE;
494 hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
495 hadc2.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
496 hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
497 hadc2.Init.NbrOfConversion = 7;
498 hadc2.Init.DMAContinuousRequests = ENABLE;
499 hadc2.Init.EOCSelection = ADC_EOC_SEQ_CONV;
500 if (HAL_ADC_Init(&hadc2) != HAL_OK)
501 {
503 }
504
507 sConfig.Channel = ADC_CHANNEL_1;
508 sConfig.Rank = ADC_REGULAR_RANK_1;
509 sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
510 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
511 {
513 }
514
517 sConfig.Channel = ADC_CHANNEL_3;
518 sConfig.Rank = ADC_REGULAR_RANK_2;
519 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
520 {
522 }
523
526 sConfig.Channel = ADC_CHANNEL_7;
527 sConfig.Rank = ADC_REGULAR_RANK_3;
528 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
529 {
531 }
532
535 sConfig.Channel = ADC_CHANNEL_9;
536 sConfig.Rank = ADC_REGULAR_RANK_4;
537 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
538 {
540 }
541
544 sConfig.Channel = ADC_CHANNEL_11;
545 sConfig.Rank = ADC_REGULAR_RANK_5;
546 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
547 {
549 }
550
553 sConfig.Channel = ADC_CHANNEL_13;
554 sConfig.Rank = ADC_REGULAR_RANK_6;
555 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
556 {
558 }
559
562 sConfig.Channel = ADC_CHANNEL_15;
563 sConfig.Rank = ADC_REGULAR_RANK_7;
564 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
565 {
567 }
568 /* USER CODE BEGIN ADC2_Init 2 */
569
570 /* USER CODE END ADC2_Init 2 */
571
572}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_ADC3_Init()

static void MX_ADC3_Init ( void  )
static

ADC3 Initialization Function.

Parameters
None
Return values
None

Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

Definition at line 579 of file main.c.

580{
581
582 /* USER CODE BEGIN ADC3_Init 0 */
583
584 /* USER CODE END ADC3_Init 0 */
585
586 ADC_ChannelConfTypeDef sConfig = {0};
587
588 /* USER CODE BEGIN ADC3_Init 1 */
589
590 /* USER CODE END ADC3_Init 1 */
591
594 hadc3.Instance = ADC3;
595 hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
596 hadc3.Init.Resolution = ADC_RESOLUTION_12B;
597 hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
598 hadc3.Init.ContinuousConvMode = DISABLE;
599 hadc3.Init.DiscontinuousConvMode = DISABLE;
600 hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
601 hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
602 hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
603 hadc3.Init.NbrOfConversion = 8;
604 hadc3.Init.DMAContinuousRequests = ENABLE;
605 hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
606 if (HAL_ADC_Init(&hadc3) != HAL_OK)
607 {
609 }
610
613 sConfig.Channel = ADC_CHANNEL_4;
614 sConfig.Rank = ADC_REGULAR_RANK_1;
615 sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES;
616 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
617 {
619 }
620
623 sConfig.Channel = ADC_CHANNEL_5;
624 sConfig.Rank = ADC_REGULAR_RANK_2;
625 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
626 {
628 }
629
632 sConfig.Channel = ADC_CHANNEL_6;
633 sConfig.Rank = ADC_REGULAR_RANK_3;
634 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
635 {
637 }
638
641 sConfig.Channel = ADC_CHANNEL_7;
642 sConfig.Rank = ADC_REGULAR_RANK_4;
643 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
644 {
646 }
647
650 sConfig.Channel = ADC_CHANNEL_8;
651 sConfig.Rank = ADC_REGULAR_RANK_5;
652 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
653 {
655 }
656
659 sConfig.Channel = ADC_CHANNEL_9;
660 sConfig.Rank = ADC_REGULAR_RANK_6;
661 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
662 {
664 }
665
668 sConfig.Channel = ADC_CHANNEL_14;
669 sConfig.Rank = ADC_REGULAR_RANK_7;
670 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
671 {
673 }
674
677 sConfig.Channel = ADC_CHANNEL_15;
678 sConfig.Rank = ADC_REGULAR_RANK_8;
679 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
680 {
682 }
683 /* USER CODE BEGIN ADC3_Init 2 */
684
685 /* USER CODE END ADC3_Init 2 */
686
687}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_CAN1_Init()

static void MX_CAN1_Init ( void  )
static

CAN1 Initialization Function.

Parameters
None
Return values
None

Definition at line 694 of file main.c.

695{
696
697 /* USER CODE BEGIN CAN1_Init 0 */
698
699 /* USER CODE END CAN1_Init 0 */
700
701 /* USER CODE BEGIN CAN1_Init 1 */
702
703 /* USER CODE END CAN1_Init 1 */
704 hcan1.Instance = CAN1;
705 hcan1.Init.Prescaler = 3;
706 hcan1.Init.Mode = CAN_MODE_NORMAL;
707 hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
708 hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
709 hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
710 hcan1.Init.TimeTriggeredMode = DISABLE;
711 hcan1.Init.AutoBusOff = DISABLE;
712 hcan1.Init.AutoWakeUp = DISABLE;
713 hcan1.Init.AutoRetransmission = DISABLE;
714 hcan1.Init.ReceiveFifoLocked = DISABLE;
715 hcan1.Init.TransmitFifoPriority = DISABLE;
716 if (HAL_CAN_Init(&hcan1) != HAL_OK)
717 {
719 }
720 /* USER CODE BEGIN CAN1_Init 2 */
721 CAN_FilterTypeDef sFilterConfig;
722 sFilterConfig.FilterBank = 0;
723 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
724 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
725 sFilterConfig.FilterIdHigh = 0x0000;
726 sFilterConfig.FilterIdLow = 0x0000;
727 sFilterConfig.FilterMaskIdHigh = 0x0000;
728 sFilterConfig.FilterMaskIdLow = 0x0000;
729 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
730 sFilterConfig.FilterActivation = ENABLE;
731 sFilterConfig.SlaveStartFilterBank = 14;
732 HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);
733
734 // Stop CAN
735 HAL_CAN_Stop(&hcan1);
736 // Start CAN
737 if (HAL_CAN_Start(&hcan1) != HAL_OK) {
738 printf("CAN1 Start Error: ErrorCode = 0x%lX\r\n", hcan1.ErrorCode);
739 }
740
741 // Start IRQ for CAN Rx
742 if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
743 printf("interrupt CAN1 init failed\r\n");
744 }
745 /* USER CODE END CAN1_Init 2 */
746
747}
CAN_HandleTypeDef hcan1
Definition: main.c:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_CAN2_Init()

static void MX_CAN2_Init ( void  )
static

CAN2 Initialization Function.

Parameters
None
Return values
None

Definition at line 754 of file main.c.

755{
756
757 /* USER CODE BEGIN CAN2_Init 0 */
758
759 /* USER CODE END CAN2_Init 0 */
760
761 /* USER CODE BEGIN CAN2_Init 1 */
762
763 /* USER CODE END CAN2_Init 1 */
764 hcan2.Instance = CAN2;
765 hcan2.Init.Prescaler = 4;
766 hcan2.Init.Mode = CAN_MODE_NORMAL;
767 hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
768 hcan2.Init.TimeSeg1 = CAN_BS1_10TQ;
769 hcan2.Init.TimeSeg2 = CAN_BS2_1TQ;
770 hcan2.Init.TimeTriggeredMode = DISABLE;
771 hcan2.Init.AutoBusOff = DISABLE;
772 hcan2.Init.AutoWakeUp = DISABLE;
773 hcan2.Init.AutoRetransmission = DISABLE;
774 hcan2.Init.ReceiveFifoLocked = DISABLE;
775 hcan2.Init.TransmitFifoPriority = DISABLE;
776 if (HAL_CAN_Init(&hcan2) != HAL_OK)
777 {
779 }
780 /* USER CODE BEGIN CAN2_Init 2 */
781 CAN_FilterTypeDef sFilterConfig;
782 sFilterConfig.FilterBank = 0;
783 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
784 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
785 sFilterConfig.FilterIdHigh = 0x0000;
786 sFilterConfig.FilterIdLow = 0x0000;
787 sFilterConfig.FilterMaskIdHigh = 0x0000;
788 sFilterConfig.FilterMaskIdLow = 0x0000;
789 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
790 sFilterConfig.FilterActivation = ENABLE;
791 sFilterConfig.SlaveStartFilterBank = 14;
792 HAL_CAN_ConfigFilter(&hcan2, &sFilterConfig);
793
794 // Stop CAN
795 HAL_CAN_Stop(&hcan2);
796 // Start CAN
797 if (HAL_CAN_Start(&hcan2) != HAL_OK) {
798 printf("CAN2 Start Error: ErrorCode = 0x%lX\r\n", hcan2.ErrorCode);
799 }
800
801 // Start IRQ for CAN Rx
802 if (HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) {
803 printf("interrupt CAN2 init failed\r\n");
804 }
805 /* USER CODE END CAN2_Init 2 */
806
807}
CAN_HandleTypeDef hcan2
Definition: main.c:68
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_CAN3_Init()

static void MX_CAN3_Init ( void  )
static

CAN3 Initialization Function.

Parameters
None
Return values
None

Definition at line 814 of file main.c.

815{
816
817 /* USER CODE BEGIN CAN3_Init 0 */
818
819 /* USER CODE END CAN3_Init 0 */
820
821 /* USER CODE BEGIN CAN3_Init 1 */
822
823 /* USER CODE END CAN3_Init 1 */
824 hcan3.Instance = CAN3;
825 hcan3.Init.Prescaler = 16;
826 hcan3.Init.Mode = CAN_MODE_NORMAL;
827 hcan3.Init.SyncJumpWidth = CAN_SJW_1TQ;
828 hcan3.Init.TimeSeg1 = CAN_BS1_1TQ;
829 hcan3.Init.TimeSeg2 = CAN_BS2_1TQ;
830 hcan3.Init.TimeTriggeredMode = DISABLE;
831 hcan3.Init.AutoBusOff = DISABLE;
832 hcan3.Init.AutoWakeUp = DISABLE;
833 hcan3.Init.AutoRetransmission = DISABLE;
834 hcan3.Init.ReceiveFifoLocked = DISABLE;
835 hcan3.Init.TransmitFifoPriority = DISABLE;
836 if (HAL_CAN_Init(&hcan3) != HAL_OK)
837 {
839 }
840 /* USER CODE BEGIN CAN3_Init 2 */
841
842 /* USER CODE END CAN3_Init 2 */
843
844}
CAN_HandleTypeDef hcan3
Definition: main.c:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_DAC_Init()

static void MX_DAC_Init ( void  )
static

DAC Initialization Function.

Parameters
None
Return values
None

DAC Initialization

DAC channel OUT1 config

DAC channel OUT2 config

Definition at line 851 of file main.c.

852{
853
854 /* USER CODE BEGIN DAC_Init 0 */
855
856 /* USER CODE END DAC_Init 0 */
857
858 DAC_ChannelConfTypeDef sConfig = {0};
859
860 /* USER CODE BEGIN DAC_Init 1 */
861
862 /* USER CODE END DAC_Init 1 */
863
866 hdac.Instance = DAC;
867 if (HAL_DAC_Init(&hdac) != HAL_OK)
868 {
870 }
871
874 sConfig.DAC_Trigger = DAC_TRIGGER_T2_TRGO;
875 sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
876 if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)
877 {
879 }
880
883 if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_2) != HAL_OK)
884 {
886 }
887 /* USER CODE BEGIN DAC_Init 2 */
888
889 /* USER CODE END DAC_Init 2 */
890
891}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_DMA_Init()

static void MX_DMA_Init ( void  )
static

Enable DMA controller clock

Definition at line 1201 of file main.c.

1202{
1203
1204 /* DMA controller clock enable */
1205 __HAL_RCC_DMA2_CLK_ENABLE();
1206 __HAL_RCC_DMA1_CLK_ENABLE();
1207
1208 /* DMA interrupt init */
1209 /* DMA1_Stream5_IRQn interrupt configuration */
1210 HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0);
1211 HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn);
1212 /* DMA1_Stream6_IRQn interrupt configuration */
1213 HAL_NVIC_SetPriority(DMA1_Stream6_IRQn, 0, 0);
1214 HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn);
1215 /* DMA2_Stream0_IRQn interrupt configuration */
1216 HAL_NVIC_SetPriority(DMA2_Stream0_IRQn, 0, 0);
1217 HAL_NVIC_EnableIRQ(DMA2_Stream0_IRQn);
1218 /* DMA2_Stream1_IRQn interrupt configuration */
1219 HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);
1220 HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
1221 /* DMA2_Stream2_IRQn interrupt configuration */
1222 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
1223 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
1224
1225}
Here is the caller graph for this function:

◆ MX_GPIO_Init()

static void MX_GPIO_Init ( void  )
static

GPIO Initialization Function.

Parameters
None
Return values
None

Definition at line 1232 of file main.c.

1233{
1234 GPIO_InitTypeDef GPIO_InitStruct = {0};
1235/* USER CODE BEGIN MX_GPIO_Init_1 */
1236/* USER CODE END MX_GPIO_Init_1 */
1237
1238 /* GPIO Ports Clock Enable */
1239 __HAL_RCC_GPIOE_CLK_ENABLE();
1240 __HAL_RCC_GPIOC_CLK_ENABLE();
1241 __HAL_RCC_GPIOF_CLK_ENABLE();
1242 __HAL_RCC_GPIOH_CLK_ENABLE();
1243 __HAL_RCC_GPIOA_CLK_ENABLE();
1244 __HAL_RCC_GPIOB_CLK_ENABLE();
1245 __HAL_RCC_GPIOG_CLK_ENABLE();
1246 __HAL_RCC_GPIOD_CLK_ENABLE();
1247
1248 /*Configure GPIO pin Output Level */
1249 HAL_GPIO_WritePin(GPIOF, GPIO_PIN_12|GPIO_PIN_13, GPIO_PIN_RESET);
1250
1251 /*Configure GPIO pin Output Level */
1252 HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11
1253 |GPIO_PIN_13, GPIO_PIN_RESET);
1254
1255 /*Configure GPIO pin Output Level */
1256 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
1257
1258 /*Configure GPIO pin Output Level */
1259 HAL_GPIO_WritePin(GPIOG, GPIO_PIN_9, GPIO_PIN_RESET);
1260
1261 /*Configure GPIO pin Output Level */
1262 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
1263
1264 /*Configure GPIO pins : PE3 PE4 PE10 PE12
1265 PE14 PE15 PE0 PE1 */
1266 GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_10|GPIO_PIN_12
1267 |GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_0|GPIO_PIN_1;
1268 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1269 GPIO_InitStruct.Pull = GPIO_NOPULL;
1270 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
1271
1272 /*Configure GPIO pin : USER_Btn_Pin */
1273 GPIO_InitStruct.Pin = USER_Btn_Pin;
1274 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
1275 GPIO_InitStruct.Pull = GPIO_NOPULL;
1276 HAL_GPIO_Init(USER_Btn_GPIO_Port, &GPIO_InitStruct);
1277
1278 /*Configure GPIO pins : PF2 PF11 */
1279 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_11;
1280 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1281 GPIO_InitStruct.Pull = GPIO_NOPULL;
1282 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
1283
1284 /*Configure GPIO pins : PB2 PB10 PB11 PB12
1285 PB14 PB15 PB4 PB6 */
1286 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12
1287 |GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_4|GPIO_PIN_6;
1288 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1289 GPIO_InitStruct.Pull = GPIO_NOPULL;
1290 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
1291
1292 /*Configure GPIO pins : PF12 PF13 */
1293 GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13;
1294 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1295 GPIO_InitStruct.Pull = GPIO_NOPULL;
1296 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1297 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
1298
1299 /*Configure GPIO pins : PG0 PG1 PG2 PG3
1300 PG4 PG5 PG6 PG8
1301 PG10 PG11 PG15 */
1302 GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
1303 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_8
1304 |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_15;
1305 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1306 GPIO_InitStruct.Pull = GPIO_NOPULL;
1307 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
1308
1309 /*Configure GPIO pins : PE7 PE8 PE9 PE11
1310 PE13 */
1311 GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11
1312 |GPIO_PIN_13;
1313 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1314 GPIO_InitStruct.Pull = GPIO_NOPULL;
1315 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1316 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
1317
1318 /*Configure GPIO pins : PD10 PD11 PD12 PD13
1319 PD3 PD4 PD5 PD6
1320 PD7 */
1321 GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13
1322 |GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
1323 |GPIO_PIN_7;
1324 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1325 GPIO_InitStruct.Pull = GPIO_NOPULL;
1326 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
1327
1328 /*Configure GPIO pins : PD14 PD15 */
1329 GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
1330 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1331 GPIO_InitStruct.Pull = GPIO_NOPULL;
1332 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1333 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
1334
1335 /*Configure GPIO pin : USB_OverCurrent_Pin */
1336 GPIO_InitStruct.Pin = USB_OverCurrent_Pin;
1337 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
1338 GPIO_InitStruct.Pull = GPIO_NOPULL;
1339 HAL_GPIO_Init(USB_OverCurrent_GPIO_Port, &GPIO_InitStruct);
1340
1341 /*Configure GPIO pins : PC6 PC7 PC8 PC9
1342 PC10 PC11 PC12 */
1343 GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9
1344 |GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
1345 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1346 GPIO_InitStruct.Pull = GPIO_NOPULL;
1347 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1348 GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
1349 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
1350
1351 /*Configure GPIO pins : PA8 PA9 PA10 PA11
1352 PA12 */
1353 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
1354 |GPIO_PIN_12;
1355 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1356 GPIO_InitStruct.Pull = GPIO_NOPULL;
1357 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
1358
1359 /*Configure GPIO pin : PD2 */
1360 GPIO_InitStruct.Pin = GPIO_PIN_2;
1361 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1362 GPIO_InitStruct.Pull = GPIO_NOPULL;
1363 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1364 GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
1365 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
1366
1367 /*Configure GPIO pin : PG9 */
1368 GPIO_InitStruct.Pin = GPIO_PIN_9;
1369 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1370 GPIO_InitStruct.Pull = GPIO_NOPULL;
1371 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1372 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
1373
1374 /*Configure GPIO pin : LD2_Pin */
1375 GPIO_InitStruct.Pin = LD2_Pin;
1376 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1377 GPIO_InitStruct.Pull = GPIO_NOPULL;
1378 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1379 HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
1380
1381 /*Configure GPIO pins : PB8 PB9 */
1382 GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
1383 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
1384 GPIO_InitStruct.Pull = GPIO_NOPULL;
1385 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
1386 GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
1387 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
1388
1389/* USER CODE BEGIN MX_GPIO_Init_2 */
1390/* USER CODE END MX_GPIO_Init_2 */
1391}
#define USB_OverCurrent_GPIO_Port
Definition: main.h:75
#define LD2_GPIO_Port
Definition: main.h:81
#define USB_OverCurrent_Pin
Definition: main.h:74
#define USER_Btn_Pin
Definition: main.h:66
#define USER_Btn_GPIO_Port
Definition: main.h:67
#define LD2_Pin
Definition: main.h:80
Here is the caller graph for this function:

◆ MX_I2C2_Init()

static void MX_I2C2_Init ( void  )
static

I2C2 Initialization Function.

Parameters
None
Return values
None

Configure Analogue filter

Configure Digital filter

Definition at line 898 of file main.c.

899{
900
901 /* USER CODE BEGIN I2C2_Init 0 */
902
903 /* USER CODE END I2C2_Init 0 */
904
905 /* USER CODE BEGIN I2C2_Init 1 */
906
907 /* USER CODE END I2C2_Init 1 */
908 hi2c2.Instance = I2C2;
909 hi2c2.Init.Timing = 0x00506682;
910 hi2c2.Init.OwnAddress1 = 0;
911 hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
912 hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
913 hi2c2.Init.OwnAddress2 = 0;
914 hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
915 hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
916 hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
917 if (HAL_I2C_Init(&hi2c2) != HAL_OK)
918 {
920 }
921
924 if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
925 {
927 }
928
931 if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
932 {
934 }
935 /* USER CODE BEGIN I2C2_Init 2 */
936
937 /* USER CODE END I2C2_Init 2 */
938
939}
I2C_HandleTypeDef hi2c2
Definition: main.c:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_I2C4_Init()

static void MX_I2C4_Init ( void  )
static

I2C4 Initialization Function.

Parameters
None
Return values
None

Configure Analogue filter

Configure Digital filter

Definition at line 946 of file main.c.

947{
948
949 /* USER CODE BEGIN I2C4_Init 0 */
950
951 /* USER CODE END I2C4_Init 0 */
952
953 /* USER CODE BEGIN I2C4_Init 1 */
954
955 /* USER CODE END I2C4_Init 1 */
956 hi2c4.Instance = I2C4;
957 hi2c4.Init.Timing = 0x00506682;
958 hi2c4.Init.OwnAddress1 = 0;
959 hi2c4.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
960 hi2c4.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
961 hi2c4.Init.OwnAddress2 = 0;
962 hi2c4.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
963 hi2c4.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
964 hi2c4.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
965 if (HAL_I2C_Init(&hi2c4) != HAL_OK)
966 {
968 }
969
972 if (HAL_I2CEx_ConfigAnalogFilter(&hi2c4, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
973 {
975 }
976
979 if (HAL_I2CEx_ConfigDigitalFilter(&hi2c4, 0) != HAL_OK)
980 {
982 }
983 /* USER CODE BEGIN I2C4_Init 2 */
984
985 /* USER CODE END I2C4_Init 2 */
986
987}
I2C_HandleTypeDef hi2c4
Definition: main.c:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_SPI4_Init()

static void MX_SPI4_Init ( void  )
static

SPI4 Initialization Function.

Parameters
None
Return values
None

Definition at line 994 of file main.c.

995{
996
997 /* USER CODE BEGIN SPI4_Init 0 */
998
999 /* USER CODE END SPI4_Init 0 */
1000
1001 /* USER CODE BEGIN SPI4_Init 1 */
1002
1003 /* USER CODE END SPI4_Init 1 */
1004 /* SPI4 parameter configuration*/
1005 hspi4.Instance = SPI4;
1006 hspi4.Init.Mode = SPI_MODE_MASTER;
1007 hspi4.Init.Direction = SPI_DIRECTION_2LINES;
1008 hspi4.Init.DataSize = SPI_DATASIZE_4BIT;
1009 hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
1010 hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
1011 hspi4.Init.NSS = SPI_NSS_SOFT;
1012 hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
1013 hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
1014 hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
1015 hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
1016 hspi4.Init.CRCPolynomial = 7;
1017 hspi4.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
1018 hspi4.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
1019 if (HAL_SPI_Init(&hspi4) != HAL_OK)
1020 {
1021 Error_Handler();
1022 }
1023 /* USER CODE BEGIN SPI4_Init 2 */
1024
1025 /* USER CODE END SPI4_Init 2 */
1026
1027}
SPI_HandleTypeDef hspi4
Definition: main.c:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_SPI6_Init()

static void MX_SPI6_Init ( void  )
static

SPI6 Initialization Function.

Parameters
None
Return values
None

Definition at line 1034 of file main.c.

1035{
1036
1037 /* USER CODE BEGIN SPI6_Init 0 */
1038
1039 /* USER CODE END SPI6_Init 0 */
1040
1041 /* USER CODE BEGIN SPI6_Init 1 */
1042
1043 /* USER CODE END SPI6_Init 1 */
1044 /* SPI6 parameter configuration*/
1045 hspi6.Instance = SPI6;
1046 hspi6.Init.Mode = SPI_MODE_MASTER;
1047 hspi6.Init.Direction = SPI_DIRECTION_2LINES;
1048 hspi6.Init.DataSize = SPI_DATASIZE_4BIT;
1049 hspi6.Init.CLKPolarity = SPI_POLARITY_LOW;
1050 hspi6.Init.CLKPhase = SPI_PHASE_1EDGE;
1051 hspi6.Init.NSS = SPI_NSS_SOFT;
1052 hspi6.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
1053 hspi6.Init.FirstBit = SPI_FIRSTBIT_MSB;
1054 hspi6.Init.TIMode = SPI_TIMODE_DISABLE;
1055 hspi6.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
1056 hspi6.Init.CRCPolynomial = 7;
1057 hspi6.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
1058 hspi6.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
1059 if (HAL_SPI_Init(&hspi6) != HAL_OK)
1060 {
1061 Error_Handler();
1062 }
1063 /* USER CODE BEGIN SPI6_Init 2 */
1064
1065 /* USER CODE END SPI6_Init 2 */
1066
1067}
SPI_HandleTypeDef hspi6
Definition: main.c:79
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM1_Init()

static void MX_TIM1_Init ( void  )
static

TIM1 Initialization Function.

Parameters
None
Return values
None

Definition at line 1074 of file main.c.

1075{
1076
1077 /* USER CODE BEGIN TIM1_Init 0 */
1078
1079 /* USER CODE END TIM1_Init 0 */
1080
1081 TIM_ClockConfigTypeDef sClockSourceConfig = {0};
1082 TIM_MasterConfigTypeDef sMasterConfig = {0};
1083
1084 /* USER CODE BEGIN TIM1_Init 1 */
1085
1086 /* USER CODE END TIM1_Init 1 */
1087 htim1.Instance = TIM1;
1088 htim1.Init.Prescaler = 47999;
1089 htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
1090 htim1.Init.Period = 999;
1091 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
1092 htim1.Init.RepetitionCounter = 0;
1093 htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
1094 if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
1095 {
1096 Error_Handler();
1097 }
1098 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
1099 if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
1100 {
1101 Error_Handler();
1102 }
1103 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
1104 sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
1105 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1106 if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
1107 {
1108 Error_Handler();
1109 }
1110 /* USER CODE BEGIN TIM1_Init 2 */
1111
1112 /* USER CODE END TIM1_Init 2 */
1113
1114}
TIM_HandleTypeDef htim1
Definition: main.c:81
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM2_Init()

static void MX_TIM2_Init ( void  )
static

TIM2 Initialization Function.

Parameters
None
Return values
None

Definition at line 1121 of file main.c.

1122{
1123
1124 /* USER CODE BEGIN TIM2_Init 0 */
1125
1126 /* USER CODE END TIM2_Init 0 */
1127
1128 TIM_ClockConfigTypeDef sClockSourceConfig = {0};
1129 TIM_MasterConfigTypeDef sMasterConfig = {0};
1130
1131 /* USER CODE BEGIN TIM2_Init 1 */
1132
1133 /* USER CODE END TIM2_Init 1 */
1134 htim2.Instance = TIM2;
1135 htim2.Init.Prescaler = 0;
1136 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
1137 htim2.Init.Period = 479999;
1138 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
1139 htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
1140 if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
1141 {
1142 Error_Handler();
1143 }
1144 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
1145 if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
1146 {
1147 Error_Handler();
1148 }
1149 sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
1150 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1151 if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
1152 {
1153 Error_Handler();
1154 }
1155 /* USER CODE BEGIN TIM2_Init 2 */
1156 if (HAL_TIM_Base_Start_IT(&htim2) != HAL_OK) {
1157 Error_Handler();
1158 }
1159 /* USER CODE END TIM2_Init 2 */
1160
1161}
TIM_HandleTypeDef htim2
Definition: main.c:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_USART3_UART_Init()

static void MX_USART3_UART_Init ( void  )
static

USART3 Initialization Function.

Parameters
None
Return values
None

Definition at line 1168 of file main.c.

1169{
1170
1171 /* USER CODE BEGIN USART3_Init 0 */
1172
1173 /* USER CODE END USART3_Init 0 */
1174
1175 /* USER CODE BEGIN USART3_Init 1 */
1176
1177 /* USER CODE END USART3_Init 1 */
1178 huart3.Instance = USART3;
1179 huart3.Init.BaudRate = 115200;
1180 huart3.Init.WordLength = UART_WORDLENGTH_8B;
1181 huart3.Init.StopBits = UART_STOPBITS_1;
1182 huart3.Init.Parity = UART_PARITY_NONE;
1183 huart3.Init.Mode = UART_MODE_TX_RX;
1184 huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1185 huart3.Init.OverSampling = UART_OVERSAMPLING_16;
1186 huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
1187 huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
1188 if (HAL_UART_Init(&huart3) != HAL_OK)
1189 {
1190 Error_Handler();
1191 }
1192 /* USER CODE BEGIN USART3_Init 2 */
1193
1194 /* USER CODE END USART3_Init 2 */
1195
1196}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SystemClock_Config()

void SystemClock_Config ( void  )

System Clock Configuration.

Return values
None

Configure LSE Drive Capability

Configure the main internal regulator output voltage

Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure.

Initializes the CPU, AHB and APB buses clocks

Definition at line 317 of file main.c.

318{
319 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
320 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
321
324 HAL_PWR_EnableBkUpAccess();
325
328 __HAL_RCC_PWR_CLK_ENABLE();
329 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
330
334 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
335 RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
336 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
337 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
338 RCC_OscInitStruct.PLL.PLLM = 4;
339 RCC_OscInitStruct.PLL.PLLN = 96;
340 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
341 RCC_OscInitStruct.PLL.PLLQ = 4;
342 RCC_OscInitStruct.PLL.PLLR = 2;
343 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
344 {
346 }
347
350 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
351 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
352 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
353 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
354 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
355 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
356
357 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
358 {
360 }
361}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ adc1_buffer

uint32_t adc1_buffer[ADC1_CHANNEL_SIZE]

Definition at line 113 of file main.c.

◆ adc2_buffer

uint32_t adc2_buffer[ADC2_CHANNEL_SIZE]

Definition at line 114 of file main.c.

◆ adc3_buffer

uint32_t adc3_buffer[ADC3_CHANNEL_SIZE]

Definition at line 115 of file main.c.

◆ dac1_buffer

uint32_t dac1_buffer[DAC1_BUFFER_SIZE]

Definition at line 116 of file main.c.

◆ dac2_buffer

uint32_t dac2_buffer[DAC2_BUFFER_SIZE]

Definition at line 117 of file main.c.

◆ digital_in_buffer

uint8_t digital_in_buffer[NUM_DIGITAL_INPUTS]

Definition at line 119 of file main.c.

◆ digital_out_buffer

uint8_t digital_out_buffer[NUM_DIGITAL_OUTPUTS]

Definition at line 118 of file main.c.

◆ hadc1

ADC_HandleTypeDef hadc1

Definition at line 60 of file main.c.

◆ hadc2

ADC_HandleTypeDef hadc2

Definition at line 61 of file main.c.

◆ hadc3

ADC_HandleTypeDef hadc3

Definition at line 62 of file main.c.

◆ hcan1

CAN_HandleTypeDef hcan1

Definition at line 67 of file main.c.

◆ hcan2

CAN_HandleTypeDef hcan2

Definition at line 68 of file main.c.

◆ hcan3

CAN_HandleTypeDef hcan3

Definition at line 69 of file main.c.

◆ hdac

DAC_HandleTypeDef hdac

Definition at line 71 of file main.c.

◆ hdma_adc1

DMA_HandleTypeDef hdma_adc1

Definition at line 63 of file main.c.

◆ hdma_adc2

DMA_HandleTypeDef hdma_adc2

Definition at line 64 of file main.c.

◆ hdma_adc3

DMA_HandleTypeDef hdma_adc3

Definition at line 65 of file main.c.

◆ hdma_dac1

DMA_HandleTypeDef hdma_dac1

Definition at line 72 of file main.c.

◆ hdma_dac2

DMA_HandleTypeDef hdma_dac2

Definition at line 73 of file main.c.

◆ hi2c2

I2C_HandleTypeDef hi2c2

Definition at line 75 of file main.c.

◆ hi2c4

I2C_HandleTypeDef hi2c4

Definition at line 76 of file main.c.

◆ hspi4

SPI_HandleTypeDef hspi4

Definition at line 78 of file main.c.

◆ hspi6

SPI_HandleTypeDef hspi6

Definition at line 79 of file main.c.

◆ htim1

TIM_HandleTypeDef htim1

Definition at line 81 of file main.c.

◆ htim2

TIM_HandleTypeDef htim2

Definition at line 82 of file main.c.

◆ huart3

UART_HandleTypeDef huart3

Definition at line 84 of file main.c.