Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
20/* USER CODE END Header */
21/* Includes ------------------------------------------------------------------*/
22#include "main.h"
23#include "cmsis_os.h"
24
25/* Private includes ----------------------------------------------------------*/
26/* USER CODE BEGIN Includes */
27#include "kalmanFilter.h"
28#include "mekf.h"
29#include "OptimalAngle.h"
30#include "z_qflash_W25QXXX.h"
31#include "attitude_estimation.h"
32#include "buzzer.h"
33#include "profiler.h"
34/* USER CODE END Includes */
35
36/* Private typedef -----------------------------------------------------------*/
37/* USER CODE BEGIN PTD */
38
39/* USER CODE END PTD */
40
41/* Private define ------------------------------------------------------------*/
42/* USER CODE BEGIN PD */
43
44/* USER CODE END PD */
45
46/* Private macro -------------------------------------------------------------*/
47/* USER CODE BEGIN PM */
48
49/* USER CODE END PM */
50
51/* Private variables ---------------------------------------------------------*/
52ADC_HandleTypeDef hadc1;
53ADC_HandleTypeDef hadc2;
54ADC_HandleTypeDef hadc3;
55
56FDCAN_HandleTypeDef hfdcan1;
57
58QSPI_HandleTypeDef hqspi;
59MDMA_HandleTypeDef hmdma_quadspi_fifo_th;
60
61SPI_HandleTypeDef hspi1;
62SPI_HandleTypeDef hspi2;
63SPI_HandleTypeDef hspi3;
64
65TIM_HandleTypeDef htim2;
66TIM_HandleTypeDef htim6;
67TIM_HandleTypeDef htim7;
68TIM_HandleTypeDef htim13;
69TIM_HandleTypeDef htim15;
70
71UART_HandleTypeDef huart4;
72UART_HandleTypeDef huart1;
73DMA_HandleTypeDef hdma_usart1_rx;
74DMA_HandleTypeDef hdma_usart1_tx;
75
76PCD_HandleTypeDef hpcd_USB_OTG_FS;
77
78/* Definitions for Sensor_Task */
79osThreadId_t Sensor_TaskHandle;
80const osThreadAttr_t Sensor_Task_attributes = {
81 .name = "Sensor_Task",
82 .stack_size = 128 * 4,
83 .priority = (osPriority_t) osPriorityRealtime7,
84};
85/* Definitions for FSM */
86osThreadId_t FSMHandle;
87const osThreadAttr_t FSM_attributes = {
88 .name = "FSM",
89 .stack_size = 128 * 4,
90 .priority = (osPriority_t) osPriorityNormal,
91};
92/* Definitions for Kalman_mkf */
93osThreadId_t Kalman_mkfHandle;
94const osThreadAttr_t Kalman_mkf_attributes = {
95 .name = "Kalman_mkf",
96 .stack_size = 512 * 4,
97 .priority = (osPriority_t) osPriorityNormal,
98};
99/* Definitions for MPC_Task */
100osThreadId_t MPC_TaskHandle;
101const osThreadAttr_t MPC_Task_attributes = {
102 .name = "MPC_Task",
103 .stack_size = 128 * 4,
104 .priority = (osPriority_t) osPriorityNormal,
105};
106/* Definitions for ReceiveVel_Task */
108const osThreadAttr_t ReceiveVel_Task_attributes = {
109 .name = "ReceiveVel_Task",
110 .stack_size = 128 * 4,
111 .priority = (osPriority_t) osPriorityNormal,
112};
113/* USER CODE BEGIN PV */
114//---------------------------------------------------------------------------------------State Machine tied variables
115flight_phase_t flight_phase = CALIBRATING; //Variable for initializing our state machine
116
118//---------------------------------------------------------------------------------------State Machine tied variables
119
120//---------------------------------------------------------------------------------------------Sensor and buzzer tied vars
122struct bmp3_dev bmp390_1 = {0}, bmp390_2 = {0}; //our barometer structs (main and backup)
123
124stmdev_ctx_t imu_1 = {0}, imu_2 = {0}; //IMU structs (main and backup)
125
126struct bmp3_data barometer_data_1 = {-1, -1}; //variable we use to get data from the main baro sensors
127struct bmp3_data barometer_data_2 = {-1, -1}; //variable we use to get data from the backup baro sensors
128
129static int16_t data_raw_angular_rate_1[3] = {0}; //variable we use to get angular acc from the imu sensor
130static int16_t data_raw_acceleration_1[3] = {0}; //variable we use to get linear acc from the imu sensor
131
132static float_t acceleration_mg_1[3] = {0}; //variable in which we save linear acc in milli-gs
133static float_t angular_rate_mdps_1[3] = {0}; //variable in which we save angular acc in milli-gs
134
135stmdev_ctx_t lis2mdl_dev_ctx; //main magnetometer sensor object
136stmdev_ctx_t lis2mdl_dev_ctx_2; //backup magnetometer sensor object
137int16_t raw_mag_data[3]; // X, Y, Z //variable we use to get magnetic values from the magnetometer
138//---------------------------------------------------------------------------------------------Sensor and buzzer tied vars
139
140
148#pragma pack(push, 1)
149typedef struct {
150 float_t acc_x;
151 float_t acc_y;
152 float_t acc_z;
154#pragma pack(pop)
155
156
157
165#pragma pack(push, 1)
166typedef struct {
167 float_t dps_x;
168 float_t dps_y;
169 float_t dps_z;
170
171 float_t mag_x;
172 float_t mag_y;
173 float_t mag_z;
174
175 float_t temperature;
176 float_t pressure;
177
178 float_t altitude;
179 float_t velocity;
180 float_t phase;
181 float_t deg;
183#pragma pack(pop)
184
185
193#pragma pack(push, 1)
194typedef struct {
195 float_t acc_x;
196 float_t acc_y;
197 float_t acc_z;
198
199 float_t dps_x;
200 float_t dps_y;
201 float_t dps_z;
202
203 float_t mag_x;
204 float_t mag_y;
205 float_t mag_z;
206
207 float_t temperature;
208 float_t pressure;
209 float_t altitude;
210
211 float_t velocity;
212 uint8_t phase;
213
215 float_t deg;
216
217 uint8_t parachute_1;
218 uint8_t parachute_2;
220#pragma pack(pop)
221
222
223
224float_t altitude = 0.0; //variable in which we save altitude
225float_t velocity = 0.0; //variable in which we store kalman adjusted velocity
226float_t Pressure_1 = 0.0; //variable holding the pressure we measured at ground level
227float_t Temperature_1 = 0.0; //variable holding the temperature we measured at ground level
228Data_Package_For_Marconi message = {0}; //variable holding the values we will send to the Marconi
229uint8_t drogue = 0; // flag indicating whether the drogue parachutes are open or not
230uint8_t mainp = 0; // flag indicating whether the main parachutes are open or not
231float max_alt = 0; //variable holding our highest measured altitude so far
232float max_vel =0; //variable holding our highest measured speed so far
233bool first_measure = true; //flag allowing us to understand if we're handling the first measure or not, useful for saving pressure and temperature and ground level
234
235
236//-------------------------------------------------------------------------------------------------------- MSA's variables, you must have a call with them before every flight to decide what values to put there
237double q[] = {0.7061377159181262, -0.03700710955926802, 0.03700710955926802, -0.7061377159181262};// quaternione di rotazione del razzo, da inizializzare con MSA, prodotto in output dal controllore (q_new precedente)
238double beta[] = {0, 0, 0}; //bias del gyroscopio, sentirsi con MSA per settare i valori
239static double P[] __attribute__((aligned(4))) = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0,0.0, 1.0, 0.0, 0.0, 0.0, 0.0,0.0, 0.0, 1.0, 0.0, 0.0, 0.0,0.0, 0.0, 0.0, 1.0, 0.0, 0.0,0.0, 0.0, 0.0, 0.0, 1.0, 0.0,0.0, 0.0, 0.0, 0.0, 0.0, 1.0};// covarianza del gyroscopio + magnetometro
240double omega[] = {3.760494829166693e-05, -1.4118446451604494e-07, 0.0003572545679652845}; //gyro dal sensore
241double b_B[] = {0,0,0};//{6669.23590038,-23984.08306486,39107.60772102}; //magnetometro dal sensore
242//double height_AGL = 0;// altezza dall'x_est //COmmented because temporarly unused
243double q_new[] = {0,0,0,0};// risultato del mekf, quaternione nuovo
244double beta_new[] = {0,0,0};// risultato del mekf, da sovrascrivere al beta vecchio
245static double P_new[] __attribute__((aligned(4)))= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};// come il precedente
246//double x_pred[] = {5000,300}; //x_est dell'iterazione precedente -> inizializzati prima della gara con i dati forniti da MSA
247double P_2[] = {5,0,0,5}; //Da settare con i dati di noise del GNSS
248double z[] = {5003.24140978,329.14706741};//dati in input, altitudine (da calcolare con la pressione) e velocita del barometro e GNSS
249double alpha = 0.0; //angolo rispetto alla verticale del razzo
250double a_m = -12.09; //accelerazione longitudinale
251double Ts = 0.01; // periodo del filtro di Kalman -> vogliamo che il filtro si esegua ogni 10 ms
252const double Q[] = {2769,1846,1846,1385}; //per calcolare covarianza del noise(legato a P2)
253const double R[] = {5.54e-3,0,0,0.121}; // per calcolare covarianza del noise(legato a P2) //
254double x_est[] = {5000,330}; // risultati del filtro di Kalman , altitudine e velocita filtrate
255double time_step = 0.5; // periodo di esecuzione dell'MPC
256double sim_time_step = 0.5; // periodo di simulazione interna
257double current_delta = 0; // ultimo grado inviato agli airbrakes
258double target_apogee = 8900; //apogeo che vogliamo
259double tolerance = 1; // tolleranza sull'angolo, angolo minimo che possiamo inviare
260double tilt_angle = 0.24556997475102937; //Angolo rispetto alla verticale del razzo
261const double mach_states[] = {0.1,0.2,0.3,0.4,0.5};// legato alla lookup table per il ct
262const double deployment_states[] ={0.0,40.5000,69.7500,94.5000,108.0000,173.8000}; //lookup table
263static double cd_table[] ={0.4510,0.3940,0.3610,0.3390,0.3320,0.5430,0.4960,0.4690,0.4250,0.4170,0.6240,0.5790,0.5550,0.5350,0.5280, 0.7450,0.7140,0.6780,0.6760,0.6720,0.7520,0.7230,0.6980,0.6850,0.6820,0.85,0.81,0.8,0.8,0.8}; //lookup table
264double z_component = 0.0; //component use to calculate the alpha, will be reintroduced alongside the magnetometers
265//-----------------------------------------------------------------------------------------------------------------
266
267//------------------------------------------ Handles of the tasks
269TaskHandle_t xMPCTaskHandle = NULL;
272//------------------------------------------ Handles of the tasks
273
274//----------------------------------------- Thread ids of the tasks
275osThreadId_t xReceived_VelID =NULL;
276osThreadId_t xMPCTaskID = NULL;
277osThreadId_t xSensorsTaskID = NULL;
278osThreadId_t xKalman_TaskID = NULL;
279//----------------------------------------- Thread ids of the tasks
280
281
282//---------------------------------------------- Flags for thread management
283#define SENSOR_FLAG (1U << 0) // 0x0001
284#define MPC_FLAG (1U << 1) // 0x0002
285#define RECEIVED_VEL_FLAG (1U << 2)
286#define KALMAN_FLAG (1U << 3)
287#define FSM_FLAG (1U << 4)
288#define UART_RX_ERROR_FLAG (1U << 5)
289//---------------------------------------------- Flags for thread management
290
291//----------------------------------------------------------------------------GNSS velocity/Marconi Rx tied vars
292uint8_t vel[4]; //variable in which we receive the gps measured velocity
293float gps_vel = 0.0f; //variable in which we store the gps measured velocity
294//----------------------------------------------------------------------------GNSS velocity/Marconi Rx tied vars
295
296uint8_t array[63]; //variable used to transform the message struct into an array of byte and send it over UART with correct byte order
297
298
299//---------------------------------------------------------------------------Controller tied flags
300bool gnss_flag = false; //flag indicating whether we just received a velocity from the gnss or not, it influences which Kalman filter we use
301bool flag_kf = false; //flag indicating whether we are in a phase of the flight state machine which requires to use the Kalman filter or not
302bool flag_attitude = false; //flag indicating whether we are in a phase of the flight state machine which requires to use the attitude controller or not
303bool flag_MPC = false; //flag indicating whether we are in a phase of the flight state machine which requires to use the MPC or not
304//---------------------------------------------------------------------------Controller tied flags
305
306//-----------------------------------------------------------------------------------------------------Flash tied variables
307bool flag_flash = false; //flag indicating whether we write data in the flash or not //TODO : set to flight conditions later (flase)
308uint32_t flash_address = 4; // variable in which we save the address of the winbond in which we save the data
309uint8_t data_buffer[4224] ={0}; //data buffer that we use to transform our structs into single byte to preserve order while saving in the winbond
310uint8_t cpy_buffer[2112] = {0}; //buffer used to copy the structure and saving it into the winbond
311uint32_t num_of_lin_acc_saved = 0; // variable keeping track of the saved linear accelerations so far
312uint32_t num_of_saved_rest_packages = 0; // variable keeping track of the saved structures not containing linear acceleration so far
313uint32_t num_of_saved_rest_packages_locked = 0; // counter of how many packages minus linear accelerations have been saved in the temporary buffer before we save them in the flash (we save at 4 and 8 then flush at 8)
314uint32_t num_of_lin_acc_saved_flash = 0; // variable keeping track of the saved linear acceleration so far in the winbond
315uint32_t num_of_saved_rest_packages_flash = 0; // variable keeping track of the saved structures not containing linear acceleration so far in the winbond
316float initial_flag_value = 0.0f; //flag indicating us whether we need to flush the winbond at startup or not
317//-----------------------------------------------------------------------------------------------------Flash tied variables
318
319
320//-------------------------------------------------------------------------------------Voltage calculation
321float Vin =0; //Variable used to calculate the voltage of the battery
322float Vr =0; //Variable used to calculate the voltage of the battery
323uint32_t adcVal = 0; //variable holding the voltage of the battery
324//-------------------------------------------------------------------------------------Voltage calculation
325
326
327/* USER CODE END PV */
328
329/* Private function prototypes -----------------------------------------------*/
330void SystemClock_Config(void);
331void PeriphCommonClock_Config(void);
332static void MPU_Config(void);
333static void MX_GPIO_Init(void);
334static void MX_DMA_Init(void);
335static void MX_MDMA_Init(void);
336static void MX_USART1_UART_Init(void);
337static void MX_USB_OTG_FS_PCD_Init(void);
338static void MX_FDCAN1_Init(void);
339static void MX_QUADSPI_Init(void);
340static void MX_SPI1_Init(void);
341static void MX_SPI2_Init(void);
342static void MX_SPI3_Init(void);
343static void MX_TIM2_Init(void);
344static void MX_TIM15_Init(void);
345static void MX_UART4_Init(void);
346static void MX_ADC1_Init(void);
347static void MX_ADC2_Init(void);
348static void MX_ADC3_Init(void);
349static void MX_TIM7_Init(void);
350static void MX_TIM6_Init(void);
351static void MX_TIM13_Init(void);
352void StartSensor_Task(void *argument);
353void StartFSM(void *argument);
354void StartKalman_mkf(void *argument);
355void StartMPC_Task(void *argument);
356void StartReceiveVel_Task(void *argument);
357
358/* USER CODE BEGIN PFP */
359
360/* USER CODE END PFP */
361
362/* Private user code ---------------------------------------------------------*/
363/* USER CODE BEGIN 0 */
364
368
369
370void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
371 if (huart->Instance == USART1) {
372
373 osThreadFlagsSet(ReceiveVel_TaskHandle, RECEIVED_VEL_FLAG);
374
375
376 }
377}
378
379void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart){
380 if (huart->Instance == USART1){
381 uint32_t error = HAL_UART_GetError(huart);
382 __HAL_UART_CLEAR_OREFLAG(huart);
383 HAL_UART_AbortReceive(huart); // This should handle associated DMA abort too
384
385
386 if (ReceiveVel_TaskHandle != NULL) { // Ensure task handle is valid
387 osThreadFlagsSet(ReceiveVel_TaskHandle, UART_RX_ERROR_FLAG);
388 }
389 }
390}
391
392
393/* USER CODE END 0 */
394
399int main(void)
400{
401
402 /* USER CODE BEGIN 1 */
403
404 /* USER CODE END 1 */
405
406 /* MPU Configuration--------------------------------------------------------*/
407 MPU_Config();
408
409 /* MCU Configuration--------------------------------------------------------*/
410
411 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
412 HAL_Init();
413
414 /* USER CODE BEGIN Init */
415
416 /* USER CODE END Init */
417
418 /* Configure the system clock */
420
421 /* Configure the peripherals common clocks */
423
424 /* USER CODE BEGIN SysInit */
425 initDWT();
426 /* USER CODE END SysInit */
427
428 /* Initialize all configured peripherals */
429 MX_GPIO_Init();
430 MX_DMA_Init();
431 MX_MDMA_Init();
436 MX_SPI1_Init();
437 MX_SPI2_Init();
438 MX_SPI3_Init();
439 MX_TIM2_Init();
442 MX_ADC1_Init();
443 MX_ADC2_Init();
444 MX_ADC3_Init();
445 MX_TIM7_Init();
446 MX_TIM6_Init();
448 /* USER CODE BEGIN 2 */
449 //----------------------------------------------------------------------------------------------------------------------------------------
450//TODO CODICE PER INIZIALIZZARE I MAGNETOMETRI, COMMENTATO FINQUANDO AVREMO UNA SCHEDA CON I MAGNETOMETRI GIRATI NEL VERSO GIUSTO
451 //uint8_t result = lis2mdl_init(&lis2mdl_dev_ctx);
452 //uint8_t result_7 = lis2mdl_init_2(&lis2mdl_dev_ctx_2);
453//TODO: SETTAGGIO DELL'SPI IN 4WAY PIUTTOSTO CHE 3WAY, SERVE A GESTIRE LA QUESTIONE DEL REGISTRO DEL MAGNETOMETRO, SE GIA STA SU 4WAY NO NEED
454 // HAL_SPI_DeInit(&hspi2);
455 // HAL_Delay(10);
456 // hspi2.Init.Direction = SPI_DIRECTION_2LINES;
457 // HAL_SPI_Init(&hspi2);
458 //----------------------------------------------------------------------------------------------------------------------------------------
459
460 LED_ON(GPIO_LED_FLASH_GPIO_Port, GPIO_LED_FLASH_Pin);
461
462
463
464 IMU_CS_HIGH;
465 MAG_CS_HIGH;
466 BMP390_CS_HIGH;
467
468 HAL_Delay(100);
469
470
471 uint8_t result_4 = init_bmp390_B(&bmp390_2);
472
474
475 //TODO: the result of the init of the backup of the imu and of the barometer are currently not checked, we can add a very similar snippet of code to the lines 494 to 498 but using a different LED
476
477 uint8_t result_3 = init_bmp390_p(&bmp390_1);
478
480
481
482 if(result_1 != 0 || result_3 != 0){
483 LED_ON(GPIO_LED2_GPIO_Port, GPIO_LED2_Pin);
484 }
485
486 calibrateIMU(&imu_1, 1000, HWOFFSET);
487 calibrateIMU(&imu_2, 1000, HWOFFSET);
488
489
490 buzzer_init(bz, &htim15, TIM_CHANNEL_2);
491
492 musica_maestro(bz,Partition,sizeof(Partition)/sizeof(note_t));
493
494
495 if (QFlash_Init() != 0) {
496 // Handle initialization error
498 }
499
500
501 uint8_t small_buffer[4];
502 if (QFlash_Read(0, (uint8_t*)small_buffer, 4) != HAL_OK) {
503 // Handle read error
505 }
506
507 memcpy(&initial_flag_value, (uint8_t*)small_buffer, 4);
508
509 if(initial_flag_value != 1.0) {
510 HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
511
512 for(int i = 0; i < 10; i++) {
513 __HAL_TIM_SET_PRESCALER(&htim15, NOTE_B5);
514 HAL_Delay(100);
515 __HAL_TIM_SET_PRESCALER(&htim15, 0);
516 HAL_Delay(100);
517 __HAL_TIM_SET_PRESCALER(&htim15, NOTE_B5);
518 HAL_Delay(100);
519 __HAL_TIM_SET_PRESCALER(&htim15, 0);
520
521 HAL_Delay(700);
522 }
523
524 __HAL_TIM_SET_PRESCALER(&htim15, NOTE_B5);
525 HAL_Delay(1000);
526
527 HAL_TIM_PWM_Stop(&htim15, TIM_CHANNEL_2);
528
530
531 HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
532
533 __HAL_TIM_SET_PRESCALER(&htim15, NOTE_B5);
534 HAL_Delay(700);
535
536 HAL_TIM_PWM_Stop(&htim15, TIM_CHANNEL_2);
537 }
538
539 LED_ON(GPIO_LED1_GPIO_Port, GPIO_LED1_Pin);
541
542
543
544 /* USER CODE END 2 */
545
546 /* Init scheduler */
547 osKernelInitialize();
548
549 /* USER CODE BEGIN RTOS_MUTEX */
550 /* add mutexes, ... */
551 /* USER CODE END RTOS_MUTEX */
552
553 /* USER CODE BEGIN RTOS_SEMAPHORES */
554 /* add semaphores, ... */
555 /* USER CODE END RTOS_SEMAPHORES */
556
557 /* USER CODE BEGIN RTOS_TIMERS */
558 /* start timers, add new ones, ... */
559 /* USER CODE END RTOS_TIMERS */
560
561 /* USER CODE BEGIN RTOS_QUEUES */
562 /* add queues, ... */
563 /* USER CODE END RTOS_QUEUES */
564
565 /* Create the thread(s) */
566 /* creation of Sensor_Task */
568
569 /* creation of FSM */
570 FSMHandle = osThreadNew(StartFSM, NULL, &FSM_attributes);
571
572 /* creation of Kalman_mkf */
574
575 /* creation of MPC_Task */
577
578 /* creation of ReceiveVel_Task */
580
581 /* USER CODE BEGIN RTOS_THREADS */
582 /* add threads, ... */
583 /* USER CODE END RTOS_THREADS */
584
585 /* USER CODE BEGIN RTOS_EVENTS */
586 /* add events, ... */
587
588 /* USER CODE END RTOS_EVENTS */
589
590 /* Start scheduler */
591 osKernelStart();
592
593 /* We should never get here as control is now taken by the scheduler */
594
595 /* Infinite loop */
596 /* USER CODE BEGIN WHILE */
597
598 while (1)
599 {
600 /* USER CODE END WHILE */
601
602 /* USER CODE BEGIN 3 */
603 }
604 /* USER CODE END 3 */
605}
606
612{
613 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
614 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
615
618 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
619
622 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
623
624 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
625
629 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
630 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
631 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
632 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
633 RCC_OscInitStruct.PLL.PLLM = 1;
634 RCC_OscInitStruct.PLL.PLLN = 60;
635 RCC_OscInitStruct.PLL.PLLP = 2;
636 RCC_OscInitStruct.PLL.PLLQ = 15;
637 RCC_OscInitStruct.PLL.PLLR = 2;
638 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
639 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
640 RCC_OscInitStruct.PLL.PLLFRACN = 0;
641 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
642 {
644 }
645
648 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
649 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
650 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
651 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
652 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
653 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
654 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
655 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
656 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
657 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
658
659 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
660 {
662 }
663}
664
670{
671 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
672
675 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
676 PeriphClkInitStruct.PLL2.PLL2M = 1;
677 PeriphClkInitStruct.PLL2.PLL2N = 10;
678 PeriphClkInitStruct.PLL2.PLL2P = 2;
679 PeriphClkInitStruct.PLL2.PLL2Q = 2;
680 PeriphClkInitStruct.PLL2.PLL2R = 2;
681 PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3;
682 PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOMEDIUM;
683 PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
684 PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
685 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
686 {
688 }
689}
690
696static void MX_ADC1_Init(void)
697{
698
699 /* USER CODE BEGIN ADC1_Init 0 */
700
701 /* USER CODE END ADC1_Init 0 */
702
703 ADC_MultiModeTypeDef multimode = {0};
704 ADC_ChannelConfTypeDef sConfig = {0};
705
706 /* USER CODE BEGIN ADC1_Init 1 */
707
708 /* USER CODE END ADC1_Init 1 */
709
712 hadc1.Instance = ADC1;
713 hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
714 hadc1.Init.Resolution = ADC_RESOLUTION_16B;
715 hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
716 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
717 hadc1.Init.LowPowerAutoWait = DISABLE;
718 hadc1.Init.ContinuousConvMode = DISABLE;
719 hadc1.Init.NbrOfConversion = 1;
720 hadc1.Init.DiscontinuousConvMode = DISABLE;
721 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
722 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
723 hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
724 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
725 hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
726 hadc1.Init.OversamplingMode = DISABLE;
727 hadc1.Init.Oversampling.Ratio = 1;
728 if (HAL_ADC_Init(&hadc1) != HAL_OK)
729 {
731 }
732
735 multimode.Mode = ADC_MODE_INDEPENDENT;
736 if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
737 {
739 }
740
743 sConfig.Channel = ADC_CHANNEL_11;
744 sConfig.Rank = ADC_REGULAR_RANK_1;
745 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
746 sConfig.SingleDiff = ADC_SINGLE_ENDED;
747 sConfig.OffsetNumber = ADC_OFFSET_NONE;
748 sConfig.Offset = 0;
749 sConfig.OffsetSignedSaturation = DISABLE;
750 if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
751 {
753 }
754 /* USER CODE BEGIN ADC1_Init 2 */
755
756 /* USER CODE END ADC1_Init 2 */
757
758}
759
765static void MX_ADC2_Init(void)
766{
767
768 /* USER CODE BEGIN ADC2_Init 0 */
769
770 /* USER CODE END ADC2_Init 0 */
771
772 ADC_ChannelConfTypeDef sConfig = {0};
773
774 /* USER CODE BEGIN ADC2_Init 1 */
775
776 /* USER CODE END ADC2_Init 1 */
777
780 hadc2.Instance = ADC2;
781 hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
782 hadc2.Init.Resolution = ADC_RESOLUTION_16B;
783 hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
784 hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
785 hadc2.Init.LowPowerAutoWait = DISABLE;
786 hadc2.Init.ContinuousConvMode = DISABLE;
787 hadc2.Init.NbrOfConversion = 1;
788 hadc2.Init.DiscontinuousConvMode = DISABLE;
789 hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
790 hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
791 hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
792 hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
793 hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
794 hadc2.Init.OversamplingMode = DISABLE;
795 hadc2.Init.Oversampling.Ratio = 1;
796 if (HAL_ADC_Init(&hadc2) != HAL_OK)
797 {
799 }
800
803 sConfig.Channel = ADC_CHANNEL_9;
804 sConfig.Rank = ADC_REGULAR_RANK_1;
805 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
806 sConfig.SingleDiff = ADC_SINGLE_ENDED;
807 sConfig.OffsetNumber = ADC_OFFSET_NONE;
808 sConfig.Offset = 0;
809 sConfig.OffsetSignedSaturation = DISABLE;
810 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
811 {
813 }
814 /* USER CODE BEGIN ADC2_Init 2 */
815
816 /* USER CODE END ADC2_Init 2 */
817
818}
819
825static void MX_ADC3_Init(void)
826{
827
828 /* USER CODE BEGIN ADC3_Init 0 */
829
830 /* USER CODE END ADC3_Init 0 */
831
832 ADC_ChannelConfTypeDef sConfig = {0};
833
834 /* USER CODE BEGIN ADC3_Init 1 */
835
836 /* USER CODE END ADC3_Init 1 */
837
840 hadc3.Instance = ADC3;
841 hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
842 hadc3.Init.Resolution = ADC_RESOLUTION_12B;
843 hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
844 hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
845 hadc3.Init.LowPowerAutoWait = DISABLE;
846 hadc3.Init.ContinuousConvMode = DISABLE;
847 hadc3.Init.NbrOfConversion = 1;
848 hadc3.Init.DiscontinuousConvMode = DISABLE;
849 hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
850 hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
851 hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
852 hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
853 hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
854 hadc3.Init.OversamplingMode = DISABLE;
855 hadc3.Init.Oversampling.Ratio = 1;
856 if (HAL_ADC_Init(&hadc3) != HAL_OK)
857 {
859 }
860
863 sConfig.Channel = ADC_CHANNEL_11;
864 sConfig.Rank = ADC_REGULAR_RANK_1;
865 sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
866 sConfig.SingleDiff = ADC_SINGLE_ENDED;
867 sConfig.OffsetNumber = ADC_OFFSET_NONE;
868 sConfig.Offset = 0;
869 sConfig.OffsetSignedSaturation = DISABLE;
870 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
871 {
873 }
874 /* USER CODE BEGIN ADC3_Init 2 */
875
876 /* USER CODE END ADC3_Init 2 */
877
878}
879
885static void MX_FDCAN1_Init(void)
886{
887
888 /* USER CODE BEGIN FDCAN1_Init 0 */
889
890 /* USER CODE END FDCAN1_Init 0 */
891
892 /* USER CODE BEGIN FDCAN1_Init 1 */
893
894 /* USER CODE END FDCAN1_Init 1 */
895 hfdcan1.Instance = FDCAN1;
896 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
897 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
898 hfdcan1.Init.AutoRetransmission = DISABLE;
899 hfdcan1.Init.TransmitPause = DISABLE;
900 hfdcan1.Init.ProtocolException = DISABLE;
901 hfdcan1.Init.NominalPrescaler = 16;
902 hfdcan1.Init.NominalSyncJumpWidth = 1;
903 hfdcan1.Init.NominalTimeSeg1 = 1;
904 hfdcan1.Init.NominalTimeSeg2 = 1;
905 hfdcan1.Init.DataPrescaler = 1;
906 hfdcan1.Init.DataSyncJumpWidth = 1;
907 hfdcan1.Init.DataTimeSeg1 = 1;
908 hfdcan1.Init.DataTimeSeg2 = 1;
909 hfdcan1.Init.MessageRAMOffset = 0;
910 hfdcan1.Init.StdFiltersNbr = 0;
911 hfdcan1.Init.ExtFiltersNbr = 0;
912 hfdcan1.Init.RxFifo0ElmtsNbr = 0;
913 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
914 hfdcan1.Init.RxFifo1ElmtsNbr = 0;
915 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
916 hfdcan1.Init.RxBuffersNbr = 0;
917 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
918 hfdcan1.Init.TxEventsNbr = 0;
919 hfdcan1.Init.TxBuffersNbr = 0;
920 hfdcan1.Init.TxFifoQueueElmtsNbr = 0;
921 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
922 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
923 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
924 {
926 }
927 /* USER CODE BEGIN FDCAN1_Init 2 */
928
929 /* USER CODE END FDCAN1_Init 2 */
930
931}
932
938static void MX_QUADSPI_Init(void)
939{
940
941 /* USER CODE BEGIN QUADSPI_Init 0 */
942
943 /* USER CODE END QUADSPI_Init 0 */
944
945 /* USER CODE BEGIN QUADSPI_Init 1 */
946
947 /* USER CODE END QUADSPI_Init 1 */
948 /* QUADSPI parameter configuration*/
949 hqspi.Instance = QUADSPI;
950 hqspi.Init.ClockPrescaler = 1;
951 hqspi.Init.FifoThreshold = 32;
952 hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
953 hqspi.Init.FlashSize = 25;
954 hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
955 hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
956 hqspi.Init.FlashID = QSPI_FLASH_ID_2;
957 hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
958 if (HAL_QSPI_Init(&hqspi) != HAL_OK)
959 {
961 }
962 /* USER CODE BEGIN QUADSPI_Init 2 */
963
964 /* USER CODE END QUADSPI_Init 2 */
965
966}
967
973static void MX_SPI1_Init(void)
974{
975
976 /* USER CODE BEGIN SPI1_Init 0 */
977
978 /* USER CODE END SPI1_Init 0 */
979
980 /* USER CODE BEGIN SPI1_Init 1 */
981
982 /* USER CODE END SPI1_Init 1 */
983 /* SPI1 parameter configuration*/
984 hspi1.Instance = SPI1;
985 hspi1.Init.Mode = SPI_MODE_MASTER;
986 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
987 hspi1.Init.DataSize = SPI_DATASIZE_4BIT;
988 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
989 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
990 hspi1.Init.NSS = SPI_NSS_SOFT;
991 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
992 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
993 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
994 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
995 hspi1.Init.CRCPolynomial = 0x0;
996 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
997 hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
998 hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
999 hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1000 hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1001 hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
1002 hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
1003 hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
1004 hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
1005 hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
1006 if (HAL_SPI_Init(&hspi1) != HAL_OK)
1007 {
1008 Error_Handler();
1009 }
1010 /* USER CODE BEGIN SPI1_Init 2 */
1011
1012 /* USER CODE END SPI1_Init 2 */
1013
1014}
1015
1021static void MX_SPI2_Init(void)
1022{
1023
1024 /* USER CODE BEGIN SPI2_Init 0 */
1025
1026 /* USER CODE END SPI2_Init 0 */
1027
1028 /* USER CODE BEGIN SPI2_Init 1 */
1029
1030 /* USER CODE END SPI2_Init 1 */
1031 /* SPI2 parameter configuration*/
1032 hspi2.Instance = SPI2;
1033 hspi2.Init.Mode = SPI_MODE_MASTER;
1034 hspi2.Init.Direction = SPI_DIRECTION_2LINES;
1035 hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
1036 hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
1037 hspi2.Init.CLKPhase = SPI_PHASE_2EDGE;
1038 hspi2.Init.NSS = SPI_NSS_SOFT;
1039 hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
1040 hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
1041 hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
1042 hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
1043 hspi2.Init.CRCPolynomial = 0x0;
1044 hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
1045 hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
1046 hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
1047 hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1048 hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1049 hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
1050 hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
1051 hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
1052 hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
1053 hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
1054 if (HAL_SPI_Init(&hspi2) != HAL_OK)
1055 {
1056 Error_Handler();
1057 }
1058 /* USER CODE BEGIN SPI2_Init 2 */
1059
1060 /* USER CODE END SPI2_Init 2 */
1061
1062}
1063
1069static void MX_SPI3_Init(void)
1070{
1071
1072 /* USER CODE BEGIN SPI3_Init 0 */
1073
1074 /* USER CODE END SPI3_Init 0 */
1075
1076 /* USER CODE BEGIN SPI3_Init 1 */
1077
1078 /* USER CODE END SPI3_Init 1 */
1079 /* SPI3 parameter configuration*/
1080 hspi3.Instance = SPI3;
1081 hspi3.Init.Mode = SPI_MODE_MASTER;
1082 hspi3.Init.Direction = SPI_DIRECTION_2LINES;
1083 hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
1084 hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
1085 hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;
1086 hspi3.Init.NSS = SPI_NSS_SOFT;
1087 hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
1088 hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
1089 hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
1090 hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
1091 hspi3.Init.CRCPolynomial = 0x0;
1092 hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
1093 hspi3.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
1094 hspi3.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
1095 hspi3.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1096 hspi3.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
1097 hspi3.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
1098 hspi3.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
1099 hspi3.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
1100 hspi3.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
1101 hspi3.Init.IOSwap = SPI_IO_SWAP_DISABLE;
1102 if (HAL_SPI_Init(&hspi3) != HAL_OK)
1103 {
1104 Error_Handler();
1105 }
1106 /* USER CODE BEGIN SPI3_Init 2 */
1107
1108 /* USER CODE END SPI3_Init 2 */
1109
1110}
1111
1117static void MX_TIM2_Init(void)
1118{
1119
1120 /* USER CODE BEGIN TIM2_Init 0 */
1121
1122 /* USER CODE END TIM2_Init 0 */
1123
1124 TIM_MasterConfigTypeDef sMasterConfig = {0};
1125 TIM_OC_InitTypeDef sConfigOC = {0};
1126
1127 /* USER CODE BEGIN TIM2_Init 1 */
1128
1129 /* USER CODE END TIM2_Init 1 */
1130 htim2.Instance = TIM2;
1131 htim2.Init.Prescaler = 0;
1132 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
1133 htim2.Init.Period = 4294967295;
1134 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
1135 htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
1136 if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
1137 {
1138 Error_Handler();
1139 }
1140 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
1141 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1142 if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
1143 {
1144 Error_Handler();
1145 }
1146 sConfigOC.OCMode = TIM_OCMODE_PWM1;
1147 sConfigOC.Pulse = 0;
1148 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
1149 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
1150 if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
1151 {
1152 Error_Handler();
1153 }
1154 /* USER CODE BEGIN TIM2_Init 2 */
1155
1156 /* USER CODE END TIM2_Init 2 */
1158
1159}
1160
1166static void MX_TIM6_Init(void)
1167{
1168
1169 /* USER CODE BEGIN TIM6_Init 0 */
1170
1171 /* USER CODE END TIM6_Init 0 */
1172
1173 TIM_MasterConfigTypeDef sMasterConfig = {0};
1174
1175 /* USER CODE BEGIN TIM6_Init 1 */
1176
1177 /* USER CODE END TIM6_Init 1 */
1178 htim6.Instance = TIM6;
1179 htim6.Init.Prescaler = 5999;
1180 htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
1181 htim6.Init.Period = 9;
1182 htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
1183 if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
1184 {
1185 Error_Handler();
1186 }
1187 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
1188 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1189 if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK)
1190 {
1191 Error_Handler();
1192 }
1193 /* USER CODE BEGIN TIM6_Init 2 */
1194
1195 /* USER CODE END TIM6_Init 2 */
1196
1197}
1198
1204static void MX_TIM7_Init(void)
1205{
1206
1207 /* USER CODE BEGIN TIM7_Init 0 */
1208
1209 /* USER CODE END TIM7_Init 0 */
1210
1211 TIM_MasterConfigTypeDef sMasterConfig = {0};
1212
1213 /* USER CODE BEGIN TIM7_Init 1 */
1214
1215 /* USER CODE END TIM7_Init 1 */
1216 htim7.Instance = TIM7;
1217 htim7.Init.Prescaler = 23999;
1218 htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
1219 htim7.Init.Period = 4999;
1220 htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
1221 if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
1222 {
1223 Error_Handler();
1224 }
1225 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
1226 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1227 if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
1228 {
1229 Error_Handler();
1230 }
1231 /* USER CODE BEGIN TIM7_Init 2 */
1232
1233 /* USER CODE END TIM7_Init 2 */
1234
1235}
1236
1242static void MX_TIM13_Init(void)
1243{
1244
1245 /* USER CODE BEGIN TIM13_Init 0 */
1246
1247 /* USER CODE END TIM13_Init 0 */
1248
1249 /* USER CODE BEGIN TIM13_Init 1 */
1250
1251 /* USER CODE END TIM13_Init 1 */
1252 htim13.Instance = TIM13;
1253 htim13.Init.Prescaler = 239;
1254 htim13.Init.CounterMode = TIM_COUNTERMODE_UP;
1255 htim13.Init.Period = 9999;
1256 htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
1257 htim13.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
1258 if (HAL_TIM_Base_Init(&htim13) != HAL_OK)
1259 {
1260 Error_Handler();
1261 }
1262 /* USER CODE BEGIN TIM13_Init 2 */
1263
1264 /* USER CODE END TIM13_Init 2 */
1265
1266}
1267
1273static void MX_TIM15_Init(void)
1274{
1275
1276 /* USER CODE BEGIN TIM15_Init 0 */
1277
1278 /* USER CODE END TIM15_Init 0 */
1279
1280 TIM_MasterConfigTypeDef sMasterConfig = {0};
1281 TIM_OC_InitTypeDef sConfigOC = {0};
1282 TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
1283
1284 /* USER CODE BEGIN TIM15_Init 1 */
1285
1286 /* USER CODE END TIM15_Init 1 */
1287 htim15.Instance = TIM15;
1288 htim15.Init.Prescaler = 239;
1289 htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
1290 htim15.Init.Period = 999;
1291 htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
1292 htim15.Init.RepetitionCounter = 0;
1293 htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
1294 if (HAL_TIM_PWM_Init(&htim15) != HAL_OK)
1295 {
1296 Error_Handler();
1297 }
1298 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
1299 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
1300 if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
1301 {
1302 Error_Handler();
1303 }
1304 sConfigOC.OCMode = TIM_OCMODE_PWM1;
1305 sConfigOC.Pulse = 499;
1306 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
1307 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
1308 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
1309 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
1310 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
1311 if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
1312 {
1313 Error_Handler();
1314 }
1315 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
1316 sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
1317 sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
1318 sBreakDeadTimeConfig.DeadTime = 0;
1319 sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
1320 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
1321 sBreakDeadTimeConfig.BreakFilter = 0;
1322 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
1323 if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
1324 {
1325 Error_Handler();
1326 }
1327 /* USER CODE BEGIN TIM15_Init 2 */
1328
1329 /* USER CODE END TIM15_Init 2 */
1331
1332}
1333
1339static void MX_UART4_Init(void)
1340{
1341
1342 /* USER CODE BEGIN UART4_Init 0 */
1343
1344 /* USER CODE END UART4_Init 0 */
1345
1346 /* USER CODE BEGIN UART4_Init 1 */
1347
1348 /* USER CODE END UART4_Init 1 */
1349 huart4.Instance = UART4;
1350 huart4.Init.BaudRate = 115200;
1351 huart4.Init.WordLength = UART_WORDLENGTH_8B;
1352 huart4.Init.StopBits = UART_STOPBITS_1;
1353 huart4.Init.Parity = UART_PARITY_NONE;
1354 huart4.Init.Mode = UART_MODE_TX_RX;
1355 huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1356 huart4.Init.OverSampling = UART_OVERSAMPLING_16;
1357 huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
1358 huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
1359 huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
1360 if (HAL_UART_Init(&huart4) != HAL_OK)
1361 {
1362 Error_Handler();
1363 }
1364 if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
1365 {
1366 Error_Handler();
1367 }
1368 if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
1369 {
1370 Error_Handler();
1371 }
1372 if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
1373 {
1374 Error_Handler();
1375 }
1376 /* USER CODE BEGIN UART4_Init 2 */
1377
1378 /* USER CODE END UART4_Init 2 */
1379
1380}
1381
1387static void MX_USART1_UART_Init(void)
1388{
1389
1390 /* USER CODE BEGIN USART1_Init 0 */
1391
1392 /* USER CODE END USART1_Init 0 */
1393
1394 /* USER CODE BEGIN USART1_Init 1 */
1395
1396 /* USER CODE END USART1_Init 1 */
1397 huart1.Instance = USART1;
1398 huart1.Init.BaudRate = 1843200;
1399 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1400 huart1.Init.StopBits = UART_STOPBITS_1;
1401 huart1.Init.Parity = UART_PARITY_NONE;
1402 huart1.Init.Mode = UART_MODE_TX_RX;
1403 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1404 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1405 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
1406 huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
1407 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
1408 if (HAL_UART_Init(&huart1) != HAL_OK)
1409 {
1410 Error_Handler();
1411 }
1412 if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
1413 {
1414 Error_Handler();
1415 }
1416 if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
1417 {
1418 Error_Handler();
1419 }
1420 if (HAL_UARTEx_EnableFifoMode(&huart1) != HAL_OK)
1421 {
1422 Error_Handler();
1423 }
1424 /* USER CODE BEGIN USART1_Init 2 */
1425
1426 /* USER CODE END USART1_Init 2 */
1427
1428}
1429
1435static void MX_USB_OTG_FS_PCD_Init(void)
1436{
1437
1438 /* USER CODE BEGIN USB_OTG_FS_Init 0 */
1439
1440 /* USER CODE END USB_OTG_FS_Init 0 */
1441
1442 /* USER CODE BEGIN USB_OTG_FS_Init 1 */
1443
1444 /* USER CODE END USB_OTG_FS_Init 1 */
1445 hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
1446 hpcd_USB_OTG_FS.Init.dev_endpoints = 9;
1447 hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
1448 hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
1449 hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
1450 hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
1451 hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
1452 hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
1453 hpcd_USB_OTG_FS.Init.battery_charging_enable = DISABLE;
1454 hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
1455 hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
1456 if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
1457 {
1458 Error_Handler();
1459 }
1460 /* USER CODE BEGIN USB_OTG_FS_Init 2 */
1461
1462 /* USER CODE END USB_OTG_FS_Init 2 */
1463
1464}
1465
1469static void MX_DMA_Init(void)
1470{
1471
1472 /* DMA controller clock enable */
1473 __HAL_RCC_DMA1_CLK_ENABLE();
1474
1475 /* DMA interrupt init */
1476 /* DMA1_Stream0_IRQn interrupt configuration */
1477 HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 5, 0);
1478 HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
1479 /* DMA1_Stream1_IRQn interrupt configuration */
1480 HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0);
1481 HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
1482
1483}
1484
1488static void MX_MDMA_Init(void)
1489{
1490
1491 /* MDMA controller clock enable */
1492 __HAL_RCC_MDMA_CLK_ENABLE();
1493 /* Local variables */
1494
1495 /* MDMA interrupt initialization */
1496 /* MDMA_IRQn interrupt configuration */
1497 HAL_NVIC_SetPriority(MDMA_IRQn, 5, 0);
1498 HAL_NVIC_EnableIRQ(MDMA_IRQn);
1499
1500}
1501
1507static void MX_GPIO_Init(void)
1508{
1509 GPIO_InitTypeDef GPIO_InitStruct = {0};
1510 /* USER CODE BEGIN MX_GPIO_Init_1 */
1511
1512 /* USER CODE END MX_GPIO_Init_1 */
1513
1514 /* GPIO Ports Clock Enable */
1515 __HAL_RCC_GPIOE_CLK_ENABLE();
1516 __HAL_RCC_GPIOH_CLK_ENABLE();
1517 __HAL_RCC_GPIOC_CLK_ENABLE();
1518 __HAL_RCC_GPIOA_CLK_ENABLE();
1519 __HAL_RCC_GPIOB_CLK_ENABLE();
1520 __HAL_RCC_GPIOD_CLK_ENABLE();
1521
1522 /*Configure GPIO pin Output Level */
1523 HAL_GPIO_WritePin(GPIOE, GPIO_1_Pin|GPIO_LED_FLASH_Pin|GPIO_LED2_Pin|GPIO_LED3_Pin, GPIO_PIN_RESET);
1524
1525 /*Configure GPIO pin Output Level */
1526 HAL_GPIO_WritePin(GPIOA, GPIO_2_Pin|GPIO_3_AIRBRAKES_AUX_Pin|GPIO4_CAMERA_Pin|GIO_SPI1_CS_Pin
1527 |GPIO_LED_USB_Pin, GPIO_PIN_RESET);
1528
1529 /*Configure GPIO pin Output Level */
1530 HAL_GPIO_WritePin(GPIOD, BARO_CS_Pin|IMU_CS_Pin|MAG_CS_Pin|GPIO_LED1_Pin, GPIO_PIN_RESET);
1531
1532 /*Configure GPIO pin Output Level */
1533 HAL_GPIO_WritePin(GPIOC, GPIO_Pyro_EN1_Pin|GPIO_Pyro_EN2_Pin|GPIO_DaVinci_Marc_SYNC_Pin, GPIO_PIN_RESET);
1534
1535 /*Configure GPIO pins : GPIO_1_Pin GPIO_LED_FLASH_Pin GPIO_LED2_Pin GPIO_LED3_Pin */
1536 GPIO_InitStruct.Pin = GPIO_1_Pin|GPIO_LED_FLASH_Pin|GPIO_LED2_Pin|GPIO_LED3_Pin;
1537 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1538 GPIO_InitStruct.Pull = GPIO_NOPULL;
1539 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1540 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
1541
1542 /*Configure GPIO pins : GPIO_2_Pin GPIO_3_AIRBRAKES_AUX_Pin GPIO4_CAMERA_Pin GIO_SPI1_CS_Pin
1543 GPIO_LED_USB_Pin */
1544 GPIO_InitStruct.Pin = GPIO_2_Pin|GPIO_3_AIRBRAKES_AUX_Pin|GPIO4_CAMERA_Pin|GIO_SPI1_CS_Pin
1545 |GPIO_LED_USB_Pin;
1546 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1547 GPIO_InitStruct.Pull = GPIO_NOPULL;
1548 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1549 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
1550
1551 /*Configure GPIO pins : BARO_CS_Pin IMU_CS_Pin MAG_CS_Pin GPIO_LED1_Pin */
1552 GPIO_InitStruct.Pin = BARO_CS_Pin|IMU_CS_Pin|MAG_CS_Pin|GPIO_LED1_Pin;
1553 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1554 GPIO_InitStruct.Pull = GPIO_NOPULL;
1555 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1556 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
1557
1558 /*Configure GPIO pins : GPIO_Pyro_EN1_Pin GPIO_Pyro_EN2_Pin GPIO_DaVinci_Marc_SYNC_Pin */
1559 GPIO_InitStruct.Pin = GPIO_Pyro_EN1_Pin|GPIO_Pyro_EN2_Pin|GPIO_DaVinci_Marc_SYNC_Pin;
1560 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
1561 GPIO_InitStruct.Pull = GPIO_NOPULL;
1562 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1563 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
1564
1565 /*AnalogSwitch Config */
1566 HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PA0, SYSCFG_SWITCH_PA0_CLOSE);
1567
1568 /*AnalogSwitch Config */
1569 HAL_SYSCFG_AnalogSwitchConfig(SYSCFG_SWITCH_PA1, SYSCFG_SWITCH_PA1_CLOSE);
1570
1571 /* USER CODE BEGIN MX_GPIO_Init_2 */
1572
1573 /* USER CODE END MX_GPIO_Init_2 */
1574}
1575
1576/* USER CODE BEGIN 4 */
1577
1578/* USER CODE END 4 */
1579
1580/* USER CODE BEGIN Header_StartSensor_Task */
1587/* USER CODE END Header_StartSensor_Task */
1588void StartSensor_Task(void *argument)
1589{
1590 /* USER CODE BEGIN 5 */
1591 //xSensorsTaskHandle = xTaskGetCurrentTaskHandle();
1592 //static uint32_t prescaler = 0;
1593 uint32_t num_esecuzioni = 0;
1594 Data_Package_no_Linear_IMU the_rest = {0};
1595 osDelay(50);
1596 HAL_TIM_Base_Start_IT(&htim6);
1597
1598 /* Infinite loop */
1599 for(;;)
1600 {
1601 //-----------------------------------------------------------------------------------every 0.25 ms
1602 osThreadFlagsWait(SENSOR_FLAG, osFlagsWaitAny, osWaitForever);
1603
1604
1606
1610
1611
1612 //Lettura IMU
1613 num_esecuzioni +=1;
1614 num_esecuzioni %= (uint32_t)40;
1615 if(flag_flash){
1618 }
1619
1620 if (num_esecuzioni == 0){
1621
1623
1625
1629
1630 the_rest.dps_x = angular_rate_mdps_1[0];
1631 the_rest.dps_y = angular_rate_mdps_1[1];
1632 the_rest.dps_z = angular_rate_mdps_1[2];
1635
1636
1637 if(first_measure ){
1638 Pressure_1 = the_rest.pressure;
1639 Temperature_1 = the_rest.temperature;
1640 first_measure = false;
1641 }
1643 z[0] = (double)altitude;
1644 the_rest.altitude = altitude;
1645 the_rest.velocity=velocity;
1646 z[1] = (double)gps_vel;
1647
1648 switch (flight_state.flight_state){
1649 case INVALID:
1650 the_rest.phase = 0;
1651 break;
1652 case CALIBRATING:
1653 the_rest.phase = 1;
1654 break;
1655 case LIFTOFF:
1656 the_rest.phase = 2;
1657 break;
1658 case BURNING:
1659 the_rest.phase = 3;
1660 break;
1661 case ABCSDEPLOYED:
1662 the_rest.phase = 4;
1663 break;
1664 case DROGUE:
1665 the_rest.phase = 5;
1666 break;
1667 case MAIN:
1668 the_rest.phase = 6;
1669 break;
1670 case TOUCHDOWN:
1671 the_rest.phase = 7;
1672 break;
1673 }
1674 if(flag_flash){
1677 //-------------------------------------------------------- We enter this portion of code every 10 ms
1678 if (num_of_saved_rest_packages == 8) {
1682 } else if (num_of_saved_rest_packages == 4) {
1684 }
1685 }
1687 omega[0] = -angular_rate_mdps_1[2]*M_PI/180000;
1688 omega[1] = angular_rate_mdps_1[1]*M_PI/180000;
1689 omega[2] = angular_rate_mdps_1[0]*M_PI/180000;
1690
1691 //++prescaler;
1692 //if (prescaler == 100) // 1 second
1693 // {
1694 // prescaler = 0;
1695 // //toggle_led();
1696 // LED_TOGGLE(GPIO_LED1_GPIO_Port,GPIO_LED1_Pin);
1697 //}
1698
1699 osThreadFlagsSet(Kalman_mkfHandle, KALMAN_FLAG);
1700 //-----------------------------------------------------------------------------------------------------------------------
1701 //lis2mdl_magnetic_raw_get(&lis2mdl_dev_ctx, raw_mag_data);
1702
1703 //the_rest.mag_x = lis2mdl_from_lsb_to_nanotesla(raw_mag_data[0]);
1704 //the_rest.mag_y = lis2mdl_from_lsb_to_nanotesla(raw_mag_data[1]);
1705 //the_rest.mag_z = lis2mdl_from_lsb_to_nanotesla(raw_mag_data[1]);
1706 //-----------------------------------------------------------------------------------------------------------------------
1707 }
1708
1709 }
1710 /* USER CODE END 5 */
1711}
1712
1713/* USER CODE BEGIN Header_StartFSM */
1720/* USER CODE END Header_StartFSM */
1721void StartFSM(void *argument)
1722{
1723 /* USER CODE BEGIN StartFSM */
1724 osDelay(50);
1725 HAL_TIM_Base_Start_IT(&htim13);
1726 /* Infinite loop */
1727 for(;;)
1728 {
1729 osThreadFlagsWait(FSM_FLAG, osFlagsWaitAny, osWaitForever);
1730
1732 acc1.accX = acceleration_mg_1[0];
1733 acc1.accY = acceleration_mg_1[1];
1734 acc1.accZ = acceleration_mg_1[2];
1735
1736 estimation_output_t MotionData;
1737 MotionData.acceleration = sqrt(
1741 MotionData.velocity = velocity;
1742 MotionData.height = altitude;
1743
1744 /* Check Flight Phases */
1745 check_flight_phase(&flight_state,MotionData, acc1);
1746 }
1747 /* USER CODE END StartFSM */
1748}
1749
1750/* USER CODE BEGIN Header_StartKalman_mkf */
1757/* USER CODE END Header_StartKalman_mkf */
1758void StartKalman_mkf(void *argument)
1759{
1760 /* USER CODE BEGIN StartKalman_mkf */
1761 static uint32_t prescaler = 0;
1762
1763 /* Infinite loop */
1764 for(;;) {
1765 osThreadFlagsWait(KALMAN_FLAG, osFlagsWaitAny, osWaitForever);
1766
1767 if(flag_attitude) {
1769 alpha = M_PI/2 - alpha;
1770 //mekf(q,beta,P,omega, b_B, 0.0, q_new, beta_new, P_new); //mekf tinkered because of the magnetometers question, Height_AGL was replaced with permanent 0
1771 memcpy(q,q_new,sizeof(q_new));
1772 }
1773
1774 //memcpy(beta,beta_new,sizeof(beta_new));
1775 //memcpy(P,P_new,sizeof(P_new));
1776//--------------------------------------------------------------------------------------------- TODO : to b e reintroduced with the actual mekf
1777 // z_component = 1 - 2*( q[0]*q[0] + q[1]*q[1] );
1778
1779 // if(z_component < - 1){
1780 // z_component = -1.0;
1781 // }
1782 // else if(z_component > 1){
1783 // z_component = 1.0;
1784 //}
1785
1786 //alpha = acos(z_component);
1787//----------------------------------------------------------------------------------------------------
1788 if(flag_kf) {
1790 gnss_flag = false;
1791 altitude = x_est[0];
1792 velocity = x_est[1];
1793 } else {
1794 velocity = gps_vel;
1795 }
1796
1798 ++prescaler;
1799
1800 if (prescaler == 25) { // 1 second
1801 prescaler = 0;
1802 //toggle_led();
1803 LED_TOGGLE(GPIO_LED1_GPIO_Port,GPIO_LED1_Pin);
1804 }
1805
1806
1808 memcpy(cpy_buffer,data_buffer,2112);
1809 } else if(num_of_saved_rest_packages_locked == 8) {
1810 memcpy(cpy_buffer,data_buffer+2112,2112);
1811 }
1812
1815
1816 if (flash_address >= (67108864 - 211200)) {
1818 flag_flash = false;
1819 } else {
1820 QFlash_Write(flash_address,(uint8_t*) cpy_buffer,sizeof(cpy_buffer));
1823 }
1824 }
1825 }
1826 /* USER CODE END StartKalman_mkf */
1827}
1828
1829/* USER CODE BEGIN Header_StartMPC_Task */
1836/* USER CODE END Header_StartMPC_Task */
1837void StartMPC_Task(void *argument)
1838{
1839 /* USER CODE BEGIN StartMPC_Task */
1840 static uint32_t prescaler = 0;
1841 osDelay(50);
1842 HAL_TIM_Base_Start_IT(&htim7);
1843
1844 /* Infinite loop */
1845 for(;;)
1846 {
1847 osThreadFlagsWait(MPC_FLAG, osFlagsWaitAny, osWaitForever);
1848 HAL_ADC_Start(&hadc3);
1849 HAL_ADC_PollForConversion(&hadc3, HAL_MAX_DELAY);
1850 adcVal =(HAL_ADC_GetValue(&hadc3));
1851 HAL_ADC_Stop(&hadc3);
1852 Vin=((adcVal/3180.0f)*3.09f);
1853 Vr=(Vin*((2700.0f+4700.0f)/2700.0f));
1855
1862 switch (flight_state.flight_state){
1863 case INVALID:
1864 message.phase = 0;
1865 break;
1866 case CALIBRATING:
1867 message.phase = 1;
1868 break;
1869 case LIFTOFF:
1870 message.phase = 2;
1871 break;
1872 case BURNING:
1873 message.phase = 3;
1874 break;
1875 case ABCSDEPLOYED:
1876 message.phase = 4;
1877 break;
1878 case DROGUE:
1879 message.phase = 5;
1880 break;
1881 case MAIN:
1882 message.phase = 6;
1883 break;
1884 case TOUCHDOWN:
1885 message.phase = 7;
1886 break;
1887 }
1888 //------------------------------------------------------------------------------------------------- TODO given that magnetometers will not fly we will replace their data with other stuff
1889 message.mag_x = (float_t)alpha;
1890
1891 if(altitude> max_alt){
1894 }
1895 if(velocity> max_vel){
1898
1899 }
1907
1908 double deg = optimalAngle( sim_time_step,
1913 cd_table);
1914 //------------------------------------------------------------------------------------------------- TODO given that magnetometers will not fly we will replace their data with other stuff
1915
1916 message.deg = (float_t)deg;
1917
1918 }else if(flight_state.flight_state>=DROGUE){
1919 message.deg = 60.0;
1920 }
1921 ++prescaler;
1922 if (prescaler == 2) // 1 second
1923 {
1924 prescaler = 0;
1925 // //toggle_led();
1926 LED_TOGGLE(GPIO_LED3_GPIO_Port,GPIO_LED3_Pin);
1927 }
1928 memcpy(array,(uint8_t*)&message,sizeof(message));
1929 HAL_UART_Transmit_DMA(&huart1, array, sizeof(array));
1930
1931
1932 }
1933 /* USER CODE END StartMPC_Task */
1934}
1935
1936/* USER CODE BEGIN Header_StartReceiveVel_Task */
1942/* USER CODE END Header_StartReceiveVel_Task */
1943void StartReceiveVel_Task(void *argument)
1944{
1945 /* USER CODE BEGIN StartReceiveVel_Task */
1946 /* Infinite loop */
1947 if (HAL_UART_Receive_DMA(&huart1, vel, 4) != HAL_OK) {
1948 Error_Handler();
1949 }
1950
1951 for(;;)
1952 {
1953 uint32_t flags = osThreadFlagsWait(RECEIVED_VEL_FLAG , osFlagsWaitAny, osWaitForever);
1954
1955 if (flags & RECEIVED_VEL_FLAG) {
1956 memcpy(&gps_vel,(uint8_t*)vel,sizeof(vel));
1957 HAL_UART_Receive_DMA(&huart1, vel, 4);
1958
1959 gnss_flag = gps_vel > 0;
1960
1961 if(gnss_flag) {
1962 LED_TOGGLE(GPIO_LED_USB_GPIO_Port, GPIO_LED_USB_Pin);
1963 }
1964 }
1965 }
1966 /* USER CODE END StartReceiveVel_Task */
1967}
1968
1969 /* MPU Configuration */
1970
1971void MPU_Config(void)
1972{
1973 MPU_Region_InitTypeDef MPU_InitStruct = {0};
1974
1975 /* Disables the MPU */
1976 HAL_MPU_Disable();
1977
1980 MPU_InitStruct.Enable = MPU_REGION_ENABLE;
1981 MPU_InitStruct.Number = MPU_REGION_NUMBER0;
1982 MPU_InitStruct.BaseAddress = 0x0;
1983 MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
1984 MPU_InitStruct.SubRegionDisable = 0x87;
1985 MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
1986 MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
1987 MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
1988 MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
1989 MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
1990 MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
1991
1992 HAL_MPU_ConfigRegion(&MPU_InitStruct);
1993 /* Enables the MPU */
1994 HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
1995
1996}
1997
2006void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
2007{
2008 /* USER CODE BEGIN Callback 0 */
2009
2010 /* USER CODE END Callback 0 */
2011 if (htim->Instance == TIM4)
2012 {
2013 HAL_IncTick();
2014 }
2015 /* USER CODE BEGIN Callback 1 */
2016 if (htim->Instance == TIM7) { //500 ms
2017 if (HAL_UART_GetState(&huart1) == HAL_UART_STATE_READY || HAL_UART_GetState(&huart1) == HAL_UART_STATE_BUSY_RX) // Ready or only busy receiving
2018 {
2019
2020 osThreadFlagsSet(MPC_TaskHandle, MPC_FLAG);
2021 }
2022 }
2023
2024 if (htim->Instance == TIM6) { // <<< Check for the 4kHz (0.25ms) timer
2025
2026 osThreadFlagsSet(Sensor_TaskHandle, SENSOR_FLAG);
2027
2028
2029 }
2030
2031 if(htim->Instance == TIM13){ // 10ms timer for the FSM
2032 osThreadFlagsSet(FSMHandle, FSM_FLAG);
2033 }
2034
2035 /* USER CODE END Callback 1 */
2036}
2037
2043{
2044 /* USER CODE BEGIN Error_Handler_Debug */
2045 /* User can add his own implementation to report the HAL error return state */
2046 __disable_irq();
2047 while (1)
2048 {
2049 }
2050 /* USER CODE END Error_Handler_Debug */
2051}
2052#ifdef USE_FULL_ASSERT
2060void assert_failed(uint8_t *file, uint32_t line)
2061{
2062 /* USER CODE BEGIN 6 */
2063 /* User can add his own implementation to report the file name and line number,
2064 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
2065 /* USER CODE END 6 */
2066}
2067#endif /* USE_FULL_ASSERT */
void attitude_estimation(const double quat[4], double ts, double omega_x, double omega_y, double omega_z, double *alpha, double quat_new[4])
Propagates the rocket's attitude quaternion and calculates the angle from vertical.
A temporary, gyroscope-based attitude estimator.
int8_t bmp3_get_sensor_data(uint8_t sensor_comp, struct bmp3_data *comp_data, struct bmp3_dev *dev)
This API reads the pressure, temperature or both data from the sensor, compensates the data and store...
Definition bmp3.c:1428
#define NULL
Definition bmp3_defs.h:88
#define BMP3_PRESS_TEMP
Definition bmp3_defs.h:313
Provides a driver for playing musical notes on a PWM-driven buzzer.
void check_flight_phase(flight_fsm_t *phase, estimation_output_t MotionData, linear_acceleration_t acc_data)
Main FSM router function that delegates to the current state's handler.
#define NOTE_A5
Note A, 5th octave.
Definition buzzer.h:59
#define TEMPO_BASE_MS
The base duration for a note, in milliseconds.
Definition buzzer.h:61
#define NOTE_D6
Note D, 6th octave.
Definition buzzer.h:56
#define NOTE_B5
Note B, 5th octave.
Definition buzzer.h:58
#define NOTE_Db6
Note D-flat, 6th octave.
Definition buzzer.h:57
#define NOTE_Gb5
Note G-flat, 5th octave.
Definition buzzer.h:55
void musica_maestro(buzzer_t *bz, const note_t *partition, uint16_t melody_length)
Plays a melody by iterating through an array of notes.
Definition buzzer.c:38
void buzzer_init(buzzer_t *bz, TIM_HandleTypeDef *htim, uint32_t channel)
Initializes the buzzer object and its associated timer hardware.
Definition buzzer.c:23
flight_phase_t
Enumeration of all possible flight phases (states) in the FSM.
@ CALIBRATING
On the launchpad, calibrating sensors.
@ MAIN
Main parachute has been deployed.
@ LIFTOFF
Rocket has cleared the launch rail.
@ ABCSDEPLOYED
Airbrakes are deployed for apogee control.
@ DROGUE
Drogue parachute has been deployed.
@ BURNING
Engine is burning; under powered ascent.
@ INVALID
An undefined or error state.
@ TOUCHDOWN
Rocket has landed.
bool flag_kf
RTOS event flag to trigger the Kalman Filter task.
Definition main.c:301
bool flag_MPC
RTOS event flag to trigger the MPC task.
Definition main.c:303
TIM_HandleTypeDef htim15
HAL Timer handle for the buzzer PWM.
Definition main.c:69
bool flag_flash
RTOS event flag to trigger the data logging task.
Definition main.c:307
uint8_t drogue
Status flag for the drogue parachute pyro channel.
Definition main.c:229
SPI_HandleTypeDef hspi2
HAL SPI handle for Sensor Bus 1 (e.g., IMU, Baro).
Definition main.c:62
bool flag_attitude
RTOS event flag to trigger the attitude estimation task.
Definition main.c:302
QSPI_HandleTypeDef hqspi
HAL QSPI handle for the external flash memory.
Definition main.c:58
SPI_HandleTypeDef hspi3
HAL SPI handle for Sensor Bus 2 (e.g., secondary sensors).
Definition main.c:63
uint8_t mainp
Status flag for the main parachute pyro channel.
Definition main.c:230
int32_t lsm6dso32_angular_rate_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Angular rate sensor. The value is expressed as a 16-bit word in two’s complement.[get].
int32_t lsm6dso32_acceleration_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Linear acceleration output register. The value is expressed as a 16-bit word in two’s complement....
float_t lsm6dso32_from_fs16_to_mg(int16_t lsb)
float_t lsm6dso32_from_fs2000_to_mdps(int16_t lsb)
int8_t calibrateIMU(stmdev_ctx_t *imu, uint16_t iterationNum, OFFSET_TYPE type)
Calibrates the IMU by calculating sensor offsets.
Definition utilities.c:366
int8_t init_imup(stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
Initializes the primary IMU (LSM6DSO32).
Definition utilities.c:193
int8_t init_imuB(stmdev_ctx_t *imu, lsm6dso32_fs_xl_t acc_full_scale, lsm6dso32_fs_g_t gyro_full_scale, lsm6dso32_odr_xl_t acc_output_data_rate, lsm6dso32_odr_g_t gyro_output_data_rate)
Initializes the backup IMU (LSM6DSO32).
Definition utilities.c:665
@ HWOFFSET
Use the hardware's internal offset registers.
Definition utilities.h:61
void StartKalman_mkf(void *argument)
Function implementing the Kalman_mkf thread.
Definition main.c:1758
void StartSensor_Task(void *argument)
Function implementing the Sensor_Task thread.
Definition main.c:1588
void StartMPC_Task(void *argument)
Function implementing the MPC_Task thread.
Definition main.c:1837
void StartFSM(void *argument)
Function implementing the FSM thread.
Definition main.c:1721
HAL_StatusTypeDef QFlash_Init()
HAL_StatusTypeDef QFlash_ChipErase()
HAL_StatusTypeDef QFlash_Write(uint32_t addr, uint8_t *data, uint32_t dataSize)
HAL_StatusTypeDef QFlash_Read(uint32_t address, uint8_t *buffer, uint32_t dataSize)
int8_t init_bmp390_B(struct bmp3_dev *bmp390)
Initializes the backup barometer (BMP390).
Definition utilities.c:723
int8_t init_bmp390_p(struct bmp3_dev *bmp390)
Initializes the primary barometer (BMP390).
Definition utilities.c:252
void kalmanFilter(double x_est[2], double P[4], const double z[2], double alpha, double a_m, double Ts, const double Q[4], const double R[4], bool gnss_signal)
Executes one prediction and correction step of the Kalman filter.
@ LSM6DSO32_XL_ODR_6667Hz_HIGH_PERF
@ LSM6DSO32_2000dps
@ LSM6DSO32_GY_ODR_208Hz_HIGH_PERF
@ LSM6DSO32_16g
osThreadId_t xReceived_VelID
Definition main.c:275
static void MX_USB_OTG_FS_PCD_Init(void)
USB_OTG_FS Initialization Function.
Definition main.c:1435
float_t Temperature_1
Definition main.c:227
bool gnss_flag
Definition main.c:300
flight_phase_t flight_phase
Definition main.c:115
struct bmp3_dev bmp390_1
Definition main.c:122
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
Definition main.c:379
TIM_HandleTypeDef htim13
Definition main.c:68
TIM_HandleTypeDef htim6
Definition main.c:66
osThreadId_t Sensor_TaskHandle
Definition main.c:79
void Error_Handler(void)
This function is executed in case of error occurrence.
Definition main.c:2042
struct bmp3_dev bmp390_2
Definition main.c:122
static float_t acceleration_mg_1[3]
Definition main.c:132
bool first_measure
Definition main.c:233
const osThreadAttr_t FSM_attributes
Definition main.c:87
TaskHandle_t xMPCTaskHandle
Definition main.c:269
double b_B[]
Definition main.c:241
double current_delta
Definition main.c:257
osThreadId_t xKalman_TaskID
Definition main.c:278
static void MX_TIM7_Init(void)
TIM7 Initialization Function.
Definition main.c:1204
double alpha
Definition main.c:249
ADC_HandleTypeDef hadc1
Definition main.c:52
static void MX_QUADSPI_Init(void)
QUADSPI Initialization Function.
Definition main.c:938
TaskHandle_t xReceived_VelHandle
Definition main.c:268
static void MX_SPI1_Init(void)
SPI1 Initialization Function.
Definition main.c:973
float initial_flag_value
Definition main.c:316
const double mach_states[]
Definition main.c:261
flight_fsm_t flight_state
Definition main.c:117
TIM_HandleTypeDef htim2
Definition main.c:65
UART_HandleTypeDef huart1
Definition main.c:72
stmdev_ctx_t lis2mdl_dev_ctx_2
Definition main.c:136
void PeriphCommonClock_Config(void)
Peripherals Common Clock Configuration.
Definition main.c:669
DMA_HandleTypeDef hdma_usart1_rx
Definition main.c:73
#define MPC_FLAG
Definition main.c:284
uint32_t flash_address
Definition main.c:308
float_t altitude
Definition main.c:224
stmdev_ctx_t lis2mdl_dev_ctx
Definition main.c:135
#define SENSOR_FLAG
Definition main.c:283
struct bmp3_data barometer_data_2
Definition main.c:127
uint32_t num_of_lin_acc_saved_flash
Definition main.c:314
float Vr
Definition main.c:322
uint32_t num_of_saved_rest_packages_flash
Definition main.c:315
TaskHandle_t xKalman_TaskHandle
Definition main.c:271
PCD_HandleTypeDef hpcd_USB_OTG_FS
Definition main.c:76
uint32_t num_of_lin_acc_saved
Definition main.c:311
static double P[] __attribute__((aligned(4)))
Data_Package_For_Marconi message
Definition main.c:228
double a_m
Definition main.c:250
static int16_t data_raw_acceleration_1[3]
Definition main.c:130
static void MX_ADC2_Init(void)
ADC2 Initialization Function.
Definition main.c:765
double beta[]
Definition main.c:238
osThreadId_t xSensorsTaskID
Definition main.c:277
double tilt_angle
Definition main.c:260
MDMA_HandleTypeDef hmdma_quadspi_fifo_th
Definition main.c:59
DMA_HandleTypeDef hdma_usart1_tx
Definition main.c:74
float_t Pressure_1
Definition main.c:226
double q_new[]
Definition main.c:243
static void MX_DMA_Init(void)
Definition main.c:1469
static void MX_USART1_UART_Init(void)
USART1 Initialization Function.
Definition main.c:1387
const osThreadAttr_t Kalman_mkf_attributes
Definition main.c:94
static void MX_MDMA_Init(void)
Definition main.c:1488
const osThreadAttr_t ReceiveVel_Task_attributes
Definition main.c:108
static void MX_FDCAN1_Init(void)
FDCAN1 Initialization Function.
Definition main.c:885
uint8_t data_buffer[4224]
Definition main.c:309
double sim_time_step
Definition main.c:256
double omega[]
Definition main.c:240
note_t Partition[]
Definition main.c:365
void SystemClock_Config(void)
System Clock Configuration.
Definition main.c:611
#define UART_RX_ERROR_FLAG
Definition main.c:288
TaskHandle_t xSensorsTaskHandle
Definition main.c:270
FDCAN_HandleTypeDef hfdcan1
Definition main.c:56
double z_component
Definition main.c:264
buzzer_t * bz
Definition main.c:121
int main(void)
The application entry point.
Definition main.c:399
osThreadId_t ReceiveVel_TaskHandle
Definition main.c:107
const double R[]
Definition main.c:253
int16_t raw_mag_data[3]
Definition main.c:137
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
Definition main.c:2006
double beta_new[]
Definition main.c:244
osThreadId_t MPC_TaskHandle
Definition main.c:100
float Vin
Definition main.c:321
uint8_t cpy_buffer[2112]
Definition main.c:310
static void MPU_Config(void)
Definition main.c:1971
double tolerance
Definition main.c:259
ADC_HandleTypeDef hadc3
Definition main.c:54
SPI_HandleTypeDef hspi1
Definition main.c:61
double time_step
Definition main.c:255
#define KALMAN_FLAG
Definition main.c:286
static void MX_ADC1_Init(void)
ADC1 Initialization Function.
Definition main.c:696
stmdev_ctx_t imu_1
Definition main.c:124
osThreadId_t xMPCTaskID
Definition main.c:276
float_t velocity
Definition main.c:225
osThreadId_t Kalman_mkfHandle
Definition main.c:93
double q[]
Definition main.c:237
uint32_t adcVal
Definition main.c:323
uint8_t vel[4]
Definition main.c:292
osThreadId_t FSMHandle
Definition main.c:86
float gps_vel
Definition main.c:293
#define RECEIVED_VEL_FLAG
Definition main.c:285
TIM_HandleTypeDef htim7
Definition main.c:67
double target_apogee
Definition main.c:258
const osThreadAttr_t MPC_Task_attributes
Definition main.c:101
struct bmp3_data barometer_data_1
Definition main.c:126
static float_t angular_rate_mdps_1[3]
Definition main.c:133
const double deployment_states[]
Definition main.c:262
static void MX_TIM15_Init(void)
TIM15 Initialization Function.
Definition main.c:1273
ADC_HandleTypeDef hadc2
Definition main.c:53
uint8_t array[63]
Definition main.c:296
double z[]
Definition main.c:248
static void MX_SPI3_Init(void)
SPI3 Initialization Function.
Definition main.c:1069
const double Q[]
Definition main.c:252
static void MX_UART4_Init(void)
UART4 Initialization Function.
Definition main.c:1339
float max_vel
Definition main.c:232
void StartReceiveVel_Task(void *argument)
Function implementing the ReceiveVel_Task thread.
Definition main.c:1943
static void MX_SPI2_Init(void)
SPI2 Initialization Function.
Definition main.c:1021
#define FSM_FLAG
Definition main.c:287
static void MX_ADC3_Init(void)
ADC3 Initialization Function.
Definition main.c:825
UART_HandleTypeDef huart4
Definition main.c:71
uint32_t num_of_saved_rest_packages
Definition main.c:312
uint32_t num_of_saved_rest_packages_locked
Definition main.c:313
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
Definition main.c:370
static int16_t data_raw_angular_rate_1[3]
Definition main.c:129
static void MX_GPIO_Init(void)
GPIO Initialization Function.
Definition main.c:1507
double P_2[]
Definition main.c:247
double x_est[]
Definition main.c:254
static void MX_TIM13_Init(void)
TIM13 Initialization Function.
Definition main.c:1242
static double cd_table[]
Definition main.c:263
double Ts
Definition main.c:251
stmdev_ctx_t imu_2
Definition main.c:124
float max_alt
Definition main.c:231
static void MX_TIM6_Init(void)
TIM6 Initialization Function.
Definition main.c:1166
const osThreadAttr_t Sensor_Task_attributes
Definition main.c:80
static void MX_TIM2_Init(void)
TIM2 Initialization Function.
Definition main.c:1117
: Header for main.c file. This file contains the common defines of the application.
Multiplicative Extended Kalman Filter (MEKF) for attitude and gyroscope bias estimation.
double optimalAngle(double sim_time_step, double altitude, double temperature, double velocity, double pressure, double current_delta, double tilt_angle, double target_apogee, double tolerance, const double mach_states[5], const double deployment_states[6], const double cd_table[30])
Calculates the optimal constant airbrake angle to reach a target apogee.
Model Predictive Controller (MPC) to determine the optimal airbrake angle.
DWT-based microsecond profiler for ARM Cortex-M microcontrollers.
void initDWT(void)
Initializes the DWT (Data Watchpoint and Trace) cycle counter.
Definition profiler.h:70
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim)
Data packet formatted for transmission to the Marconi ground station.
Definition main.c:194
float_t acc_x
Acceleration along the X-axis in g's.
Definition main.c:195
float_t acc_y
Acceleration along the Y-axis in g's.
Definition main.c:196
float_t Battery_Voltage
Current battery voltage in Volts.
Definition main.c:214
float_t mag_z
Magnetic field strength on the Z-axis in mG.
Definition main.c:205
uint8_t parachute_2
Status of the main parachute (e.g., 0=Armed, 1=Deployed).
Definition main.c:218
float_t mag_y
Magnetic field strength on the Y-axis in mG.
Definition main.c:204
float_t altitude
Calculated altitude above sea level in meters (m).
Definition main.c:209
float_t temperature
Ambient temperature in degrees Celsius (°C).
Definition main.c:207
float_t acc_z
Acceleration along the Z-axis in g's.
Definition main.c:197
float_t dps_y
Angular rate around the Y-axis in dps.
Definition main.c:200
float_t pressure
Atmospheric pressure in Pascals (Pa).
Definition main.c:208
uint8_t parachute_1
Status of the drogue parachute (e.g., 0=Armed, 1=Deployed).
Definition main.c:217
uint8_t phase
Current flight phase identifier (e.g., 0=Calibration, 1=Liftoff).
Definition main.c:212
float_t mag_x
Magnetic field strength on the X-axis in mG (milligauss).
Definition main.c:203
float_t deg
Current airbrakes opening degrees.
Definition main.c:215
float_t velocity
Calculated module of velocity in meters per second (m/s).
Definition main.c:211
float_t dps_z
Angular rate around the Z-axis in dps.
Definition main.c:201
float_t dps_x
Angular rate around the X-axis in degrees per second (dps).
Definition main.c:199
A comprehensive sensor data packet, excluding linear acceleration.
Definition main.c:166
float_t altitude
Calculated altitude above sea level in meters (m).
Definition main.c:178
float_t dps_x
Angular rate around the X-axis in degrees per second (dps).
Definition main.c:167
float_t mag_z
Magnetic field strength on the Z-axis in mG.
Definition main.c:173
float_t pressure
Atmospheric pressure in Pascals (Pa).
Definition main.c:176
float_t dps_y
Angular rate around the Y-axis in dps.
Definition main.c:168
float_t deg
Current airbrakes opening degrees.
Definition main.c:181
float_t mag_x
Magnetic field strength on the X-axis in mG (milligauss).
Definition main.c:171
float_t dps_z
Angular rate around the Z-axis in dps.
Definition main.c:169
float_t temperature
Ambient temperature in degrees Celsius (°C).
Definition main.c:175
float_t phase
Current flight phase (as a floating point representation for memory alignment).
Definition main.c:180
float_t velocity
Calculated vertical velocity in meters per second (m/s).
Definition main.c:179
float_t mag_y
Magnetic field strength on the Y-axis in mG.
Definition main.c:172
Represents a 3-axis linear acceleration data packet.
Definition main.c:149
float_t acc_y
Acceleration along the Y-axis in g's.
Definition main.c:151
float_t acc_x
Acceleration along the X-axis in g's.
Definition main.c:150
float_t acc_z
Acceleration along the Z-axis in g's.
Definition main.c:152
bmp3 sensor structure which comprises of temperature and pressure data.
Definition bmp3_defs.h:842
double pressure
Definition bmp3_defs.h:847
double temperature
Definition bmp3_defs.h:844
bmp3 device structure
Definition bmp3_defs.h:895
Represents the buzzer device handle.
Definition buzzer.h:39
Holds the primary outputs of the state estimation filter (e.g., Kalman filter).
float_t velocity
Vertical velocity in meters per second (m/s).
float_t height
Vertical altitude above ground level in meters (m).
float_t acceleration
Vertical acceleration in meters per second squared (m/s^2).
Main data structure for the Flight State Machine.
flight_phase_t flight_state
The current state of the FSM.
Represents a 3-axis linear acceleration vector from an IMU.
float_t accZ
Acceleration along the Z-axis in m/s^2.
float_t accX
Acceleration along the X-axis in m/s^2.
float_t accY
Acceleration along the Y-axis in m/s^2.
Represents a single musical note with a frequency and duration.
Definition buzzer.h:31
float_t readAltitude(float_t seaLevelPa, float_t seaLevelT, float_t currentPa)
Calculates altitude based on the barometric formula.
Definition utilities.c:780
Driver for W25Qxxx series Quad-SPI NOR Flash memory.
@ HAL_OK