123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503 |
- /* USER CODE BEGIN Header */
- /**
- ******************************************************************************
- * @file : main.c
- * @brief : 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.
- *
- ******************************************************************************
- */
- /* USER CODE END Header */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "cmsis_os.h"
- /* Private includes ----------------------------------------------------------*/
- /* USER CODE BEGIN Includes */
- #include "string.h"
- #include <stdio.h>
- #include "uart_tasks.h"
- #include "mock_tasks.h"
- #include "node-red-config.h"
- #include "adc_buffers.h"
- #include "meas_tasks.h"
- #include "peripherial.h"
- #include "measurements.h"
- #include "position_task.h"
- /* USER CODE END Includes */
- /* Private typedef -----------------------------------------------------------*/
- typedef StaticTimer_t osStaticTimerDef_t;
- /* USER CODE BEGIN PTD */
- /* USER CODE END PTD */
- /* Private define ------------------------------------------------------------*/
- /* USER CODE BEGIN PD */
- /* USER CODE END PD */
- /* Private macro -------------------------------------------------------------*/
- /* USER CODE BEGIN PM */
- /* USER CODE END PM */
- /* Private variables ---------------------------------------------------------*/
- ADC_HandleTypeDef hadc1;
- ADC_HandleTypeDef hadc2;
- ADC_HandleTypeDef hadc3;
- DMA_HandleTypeDef hdma_adc1;
- DMA_HandleTypeDef hdma_adc2;
- DMA_HandleTypeDef hdma_adc3;
- COMP_HandleTypeDef hcomp1;
- CRC_HandleTypeDef hcrc;
- DAC_HandleTypeDef hdac1;
- IWDG_HandleTypeDef hiwdg1;
- RNG_HandleTypeDef hrng;
- TIM_HandleTypeDef htim1;
- TIM_HandleTypeDef htim3;
- TIM_HandleTypeDef htim8;
- UART_HandleTypeDef huart8;
- UART_HandleTypeDef huart1;
- /* Definitions for defaultTask */
- osThreadId_t defaultTaskHandle;
- const osThreadAttr_t defaultTask_attributes = {
- .name = "defaultTask",
- .stack_size = 512 * 4,
- .priority = (osPriority_t) osPriorityNormal,
- };
- /* Definitions for debugLedTimer */
- osTimerId_t debugLedTimerHandle;
- osStaticTimerDef_t debugLedTimerControlBlock;
- const osTimerAttr_t debugLedTimer_attributes = {
- .name = "debugLedTimer",
- .cb_mem = &debugLedTimerControlBlock,
- .cb_size = sizeof(debugLedTimerControlBlock),
- };
- /* Definitions for fanTimer */
- osTimerId_t fanTimerHandle;
- osStaticTimerDef_t fanTimerControlBlock;
- const osTimerAttr_t fanTimer_attributes = {
- .name = "fanTimer",
- .cb_mem = &fanTimerControlBlock,
- .cb_size = sizeof(fanTimerControlBlock),
- };
- /* Definitions for motorXTimer */
- osTimerId_t motorXTimerHandle;
- osStaticTimerDef_t motorXTimerControlBlock;
- const osTimerAttr_t motorXTimer_attributes = {
- .name = "motorXTimer",
- .cb_mem = &motorXTimerControlBlock,
- .cb_size = sizeof(motorXTimerControlBlock),
- };
- /* Definitions for motorYTimer */
- osTimerId_t motorYTimerHandle;
- osStaticTimerDef_t motorYTimerControlBlock;
- const osTimerAttr_t motorYTimer_attributes = {
- .name = "motorYTimer",
- .cb_mem = &motorYTimerControlBlock,
- .cb_size = sizeof(motorYTimerControlBlock),
- };
- /* USER CODE BEGIN PV */
- TIM_OC_InitTypeDef fanTimerConfigOC = { 0 };
- TIM_OC_InitTypeDef motorXYTimerConfigOC = { 0 };
- extern RESMeasurements resMeasurements;
- extern SesnorsInfo sensorsInfo;
- volatile int32_t encoderXChannelA = 0;
- volatile int32_t encoderXChannelB = 0;
- volatile int32_t encoderYChannelA = 0;
- volatile int32_t encoderYChannelB = 0;
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- void PeriphCommonClock_Config(void);
- static void MPU_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_DMA_Init(void);
- static void MX_RNG_Init(void);
- static void MX_USART1_UART_Init(void);
- static void MX_ADC1_Init(void);
- static void MX_UART8_Init(void);
- static void MX_CRC_Init(void);
- static void MX_ADC2_Init(void);
- static void MX_ADC3_Init(void);
- static void MX_TIM1_Init(void);
- static void MX_TIM3_Init(void);
- static void MX_DAC1_Init(void);
- static void MX_COMP1_Init(void);
- static void MX_TIM8_Init(void);
- static void MX_IWDG1_Init(void);
- void StartDefaultTask(void *argument);
- void debugLedTimerCallback(void *argument);
- void fanTimerCallback(void *argument);
- void motorXTimerCallback(void *argument);
- void motorYTimerCallback(void *argument);
- /* USER CODE BEGIN PFP */
- /* USER CODE END PFP */
- /* Private user code ---------------------------------------------------------*/
- /* USER CODE BEGIN 0 */
- int __io_putchar(int ch)
- {
- #if UART_TASK_LOGS
- // HAL_UART_Transmit(&huart8, (uint8_t *)&ch, 1, 0xFFFF); // Use UART8 as debug interface
- ITM_SendChar(ch); // Use SWV as debug interface
- #endif
- return ch;
- }
- void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
- {
- if((GPIO_Pin == GPIO_PIN_14) || (GPIO_Pin == GPIO_PIN_15))
- {
- uint32_t pinStates = ((HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_15) << 1) | HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_14)) & 0x3;
- osMessageQueuePut(encoderXTaskArg.dataQueue, &pinStates, 0, 0);
- }
- else if ((GPIO_Pin == GPIO_PIN_10) || (GPIO_Pin == GPIO_PIN_11))
- {
- uint32_t pinStates = ((HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_11) << 1) | HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_10)) & 0x3;
- osMessageQueuePut(encoderYTaskArg.dataQueue, &pinStates, 0, 0);
- }
- }
- /* USER CODE END 0 */
- /**
- * @brief The application entry point.
- * @retval int
- */
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- /* USER CODE END 1 */
- /* MPU Configuration--------------------------------------------------------*/
- MPU_Config();
- /* Enable the CPU Cache */
- /* Enable I-Cache---------------------------------------------------------*/
- SCB_EnableICache();
- /* Enable D-Cache---------------------------------------------------------*/
- SCB_EnableDCache();
- /* MCU Configuration--------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* Configure the peripherals common clocks */
- PeriphCommonClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_DMA_Init();
- MX_RNG_Init();
- MX_USART1_UART_Init();
- MX_ADC1_Init();
- MX_UART8_Init();
- MX_CRC_Init();
- MX_ADC2_Init();
- MX_ADC3_Init();
- MX_TIM1_Init();
- MX_TIM3_Init();
- MX_DAC1_Init();
- MX_COMP1_Init();
- MX_TIM8_Init();
- #ifdef WATCHDOG_ENABLED
- MX_IWDG1_Init();
- #endif
- /* USER CODE BEGIN 2 */
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- /* USER CODE END 2 */
- /* Init scheduler */
- osKernelInitialize();
- /* USER CODE BEGIN RTOS_MUTEX */
- /* add mutexes, ... */
- /* USER CODE END RTOS_MUTEX */
- /* USER CODE BEGIN RTOS_SEMAPHORES */
- /* add semaphores, ... */
- /* USER CODE END RTOS_SEMAPHORES */
- /* Create the timer(s) */
- /* creation of debugLedTimer */
- debugLedTimerHandle = osTimerNew(debugLedTimerCallback, osTimerOnce, NULL, &debugLedTimer_attributes);
- /* creation of fanTimer */
- fanTimerHandle = osTimerNew(fanTimerCallback, osTimerOnce, NULL, &fanTimer_attributes);
- /* creation of motorXTimer */
- motorXTimerHandle = osTimerNew(motorXTimerCallback, osTimerPeriodic, NULL, &motorXTimer_attributes);
- /* creation of motorYTimer */
- motorYTimerHandle = osTimerNew(motorYTimerCallback, osTimerPeriodic, NULL, &motorYTimer_attributes);
- /* USER CODE BEGIN RTOS_TIMERS */
- /* start timers, add new ones, ... */
- /* USER CODE END RTOS_TIMERS */
- /* USER CODE BEGIN RTOS_QUEUES */
- /* add queues, ... */
- /* USER CODE END RTOS_QUEUES */
- /* Create the thread(s) */
- /* creation of defaultTask */
- defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
- /* USER CODE BEGIN RTOS_THREADS */
- /* add threads, ... */
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- UartTasksInit();
- #ifdef USER_MOCKS
- MockMeasurmetsTaskInit();
- #else
- MeasTasksInit();
- #endif
- PositionControlTaskInit();
- /* USER CODE END RTOS_THREADS */
- /* USER CODE BEGIN RTOS_EVENTS */
- /* add events, ... */
- /* USER CODE END RTOS_EVENTS */
- /* Start scheduler */
- osKernelStart();
- /* We should never get here as control is now taken by the scheduler */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- }
- /* USER CODE END 3 */
- }
- /**
- * @brief System Clock Configuration
- * @retval None
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- /** Supply configuration update enable
- */
- HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
- /** Configure the main internal regulator output voltage
- */
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
- while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
- /** Initializes the RCC Oscillators according to the specified parameters
- * in the RCC_OscInitTypeDef structure.
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI
- |RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.LSIState = RCC_LSI_ON;
- RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 5;
- RCC_OscInitStruct.PLL.PLLN = 160;
- RCC_OscInitStruct.PLL.PLLP = 2;
- RCC_OscInitStruct.PLL.PLLQ = 2;
- RCC_OscInitStruct.PLL.PLLR = 2;
- RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_2;
- RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
- RCC_OscInitStruct.PLL.PLLFRACN = 0;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Initializes the CPU, AHB and APB buses clocks
- */
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
- |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
- RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
- RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
- {
- Error_Handler();
- }
- }
- /**
- * @brief Peripherals Common Clock Configuration
- * @retval None
- */
- void PeriphCommonClock_Config(void)
- {
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
- /** Initializes the peripherals clock
- */
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC;
- PeriphClkInitStruct.PLL2.PLL2M = 5;
- PeriphClkInitStruct.PLL2.PLL2N = 90;
- PeriphClkInitStruct.PLL2.PLL2P = 25;
- PeriphClkInitStruct.PLL2.PLL2Q = 3;
- PeriphClkInitStruct.PLL2.PLL2R = 2;
- PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_2;
- PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE;
- PeriphClkInitStruct.PLL2.PLL2FRACN = 0;
- PeriphClkInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_PLL2;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- }
- /**
- * @brief ADC1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ADC1_Init(void)
- {
- /* USER CODE BEGIN ADC1_Init 0 */
- /* USER CODE END ADC1_Init 0 */
- ADC_MultiModeTypeDef multimode = {0};
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC1_Init 1 */
- /* USER CODE END ADC1_Init 1 */
- /** Common config
- */
- hadc1.Instance = ADC1;
- hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc1.Init.Resolution = ADC_RESOLUTION_16B;
- hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
- hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
- hadc1.Init.LowPowerAutoWait = DISABLE;
- hadc1.Init.ContinuousConvMode = ENABLE;
- hadc1.Init.NbrOfConversion = 7;
- hadc1.Init.DiscontinuousConvMode = DISABLE;
- hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T8_TRGO;
- hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
- hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
- hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
- hadc1.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the ADC multi-mode
- */
- multimode.Mode = ADC_DUALMODE_REGSIMULT;
- multimode.DualModeData = ADC_DUALMODEDATAFORMAT_32_10_BITS;
- multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
- if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_8;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- sConfig.OffsetSignedSaturation = DISABLE;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_9;
- sConfig.Rank = ADC_REGULAR_RANK_2;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_7;
- sConfig.Rank = ADC_REGULAR_RANK_3;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_16;
- sConfig.Rank = ADC_REGULAR_RANK_4;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_17;
- sConfig.Rank = ADC_REGULAR_RANK_5;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_14;
- sConfig.Rank = ADC_REGULAR_RANK_6;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_15;
- sConfig.Rank = ADC_REGULAR_RANK_7;
- if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC1_Init 2 */
- if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE END ADC1_Init 2 */
- }
- /**
- * @brief ADC2 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ADC2_Init(void)
- {
- /* USER CODE BEGIN ADC2_Init 0 */
- /* USER CODE END ADC2_Init 0 */
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC2_Init 1 */
- /* USER CODE END ADC2_Init 1 */
- /** Common config
- */
- hadc2.Instance = ADC2;
- hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc2.Init.Resolution = ADC_RESOLUTION_16B;
- hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
- hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
- hadc2.Init.LowPowerAutoWait = DISABLE;
- hadc2.Init.ContinuousConvMode = ENABLE;
- hadc2.Init.NbrOfConversion = 3;
- hadc2.Init.DiscontinuousConvMode = DISABLE;
- hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
- hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
- hadc2.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc2) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_3;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- sConfig.OffsetSignedSaturation = DISABLE;
- if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_4;
- sConfig.Rank = ADC_REGULAR_RANK_2;
- if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_5;
- sConfig.Rank = ADC_REGULAR_RANK_3;
- if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC2_Init 2 */
- if (HAL_ADCEx_Calibration_Start(&hadc2, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE END ADC2_Init 2 */
- }
- /**
- * @brief ADC3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_ADC3_Init(void)
- {
- /* USER CODE BEGIN ADC3_Init 0 */
- /* USER CODE END ADC3_Init 0 */
- ADC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN ADC3_Init 1 */
- /* USER CODE END ADC3_Init 1 */
- /** Common config
- */
- hadc3.Instance = ADC3;
- hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
- hadc3.Init.Resolution = ADC_RESOLUTION_16B;
- hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;
- hadc3.Init.EOCSelection = ADC_EOC_SEQ_CONV;
- hadc3.Init.LowPowerAutoWait = DISABLE;
- hadc3.Init.ContinuousConvMode = ENABLE;
- hadc3.Init.NbrOfConversion = 5;
- hadc3.Init.DiscontinuousConvMode = DISABLE;
- hadc3.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T8_TRGO;
- hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
- hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_ONESHOT;
- hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
- hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
- hadc3.Init.OversamplingMode = DISABLE;
- if (HAL_ADC_Init(&hadc3) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_0;
- sConfig.Rank = ADC_REGULAR_RANK_1;
- sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
- sConfig.SingleDiff = ADC_SINGLE_ENDED;
- sConfig.OffsetNumber = ADC_OFFSET_NONE;
- sConfig.Offset = 0;
- sConfig.OffsetSignedSaturation = DISABLE;
- if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_1;
- sConfig.Rank = ADC_REGULAR_RANK_2;
- if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_10;
- sConfig.Rank = ADC_REGULAR_RANK_3;
- if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_11;
- sConfig.Rank = ADC_REGULAR_RANK_4;
- if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure Regular Channel
- */
- sConfig.Channel = ADC_CHANNEL_VREFINT;
- sConfig.Rank = ADC_REGULAR_RANK_5;
- if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN ADC3_Init 2 */
- if (HAL_ADCEx_Calibration_Start(&hadc3, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE END ADC3_Init 2 */
- }
- /**
- * @brief COMP1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_COMP1_Init(void)
- {
- /* USER CODE BEGIN COMP1_Init 0 */
- /* USER CODE END COMP1_Init 0 */
- /* USER CODE BEGIN COMP1_Init 1 */
- /* USER CODE END COMP1_Init 1 */
- hcomp1.Instance = COMP1;
- hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_3_4VREFINT;
- hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO2;
- hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
- hcomp1.Init.Hysteresis = COMP_HYSTERESIS_NONE;
- hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
- hcomp1.Init.Mode = COMP_POWERMODE_HIGHSPEED;
- hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
- hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_NONE;
- if (HAL_COMP_Init(&hcomp1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN COMP1_Init 2 */
- /* USER CODE END COMP1_Init 2 */
- }
- /**
- * @brief CRC Initialization Function
- * @param None
- * @retval None
- */
- static void MX_CRC_Init(void)
- {
- /* USER CODE BEGIN CRC_Init 0 */
- /* USER CODE END CRC_Init 0 */
- /* USER CODE BEGIN CRC_Init 1 */
- /* USER CODE END CRC_Init 1 */
- hcrc.Instance = CRC;
- hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_DISABLE;
- hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
- hcrc.Init.GeneratingPolynomial = 4129;
- hcrc.Init.CRCLength = CRC_POLYLENGTH_16B;
- hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
- hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
- hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
- if (HAL_CRC_Init(&hcrc) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN CRC_Init 2 */
- /* USER CODE END CRC_Init 2 */
- }
- /**
- * @brief DAC1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_DAC1_Init(void)
- {
- /* USER CODE BEGIN DAC1_Init 0 */
- /* USER CODE END DAC1_Init 0 */
- DAC_ChannelConfTypeDef sConfig = {0};
- /* USER CODE BEGIN DAC1_Init 1 */
- /* USER CODE END DAC1_Init 1 */
- /** DAC Initialization
- */
- hdac1.Instance = DAC1;
- if (HAL_DAC_Init(&hdac1) != HAL_OK)
- {
- Error_Handler();
- }
- /** DAC channel OUT1 config
- */
- sConfig.DAC_SampleAndHold = DAC_SAMPLEANDHOLD_DISABLE;
- sConfig.DAC_Trigger = DAC_TRIGGER_NONE;
- sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;
- sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_DISABLE;
- sConfig.DAC_UserTrimming = DAC_TRIMMING_FACTORY;
- if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1) != HAL_OK)
- {
- Error_Handler();
- }
- /** DAC channel OUT2 config
- */
- if (HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN DAC1_Init 2 */
- /* USER CODE END DAC1_Init 2 */
- }
- /**
- * @brief IWDG1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_IWDG1_Init(void)
- {
- /* USER CODE BEGIN IWDG1_Init 0 */
- /* USER CODE END IWDG1_Init 0 */
- /* USER CODE BEGIN IWDG1_Init 1 */
- /* USER CODE END IWDG1_Init 1 */
- hiwdg1.Instance = IWDG1;
- hiwdg1.Init.Prescaler = IWDG_PRESCALER_64;
- hiwdg1.Init.Window = 249;
- hiwdg1.Init.Reload = 249;
- if (HAL_IWDG_Init(&hiwdg1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN IWDG1_Init 2 */
- /* USER CODE END IWDG1_Init 2 */
- }
- /**
- * @brief RNG Initialization Function
- * @param None
- * @retval None
- */
- static void MX_RNG_Init(void)
- {
- /* USER CODE BEGIN RNG_Init 0 */
- /* USER CODE END RNG_Init 0 */
- /* USER CODE BEGIN RNG_Init 1 */
- /* USER CODE END RNG_Init 1 */
- hrng.Instance = RNG;
- hrng.Init.ClockErrorDetection = RNG_CED_ENABLE;
- if (HAL_RNG_Init(&hrng) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN RNG_Init 2 */
- /* USER CODE END RNG_Init 2 */
- }
- /**
- * @brief TIM1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM1_Init(void)
- {
- /* USER CODE BEGIN TIM1_Init 0 */
- /* USER CODE END TIM1_Init 0 */
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- TIM_OC_InitTypeDef sConfigOC = {0};
- TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
- /* USER CODE BEGIN TIM1_Init 1 */
- /* USER CODE END TIM1_Init 1 */
- htim1.Instance = TIM1;
- htim1.Init.Prescaler = 199;
- htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim1.Init.Period = 999;
- htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim1.Init.RepetitionCounter = 0;
- htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
- if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sConfigOC.OCMode = TIM_OCMODE_PWM1;
- sConfigOC.Pulse = 99;
- sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
- sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
- sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
- sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
- sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
- if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
- {
- Error_Handler();
- }
- sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
- sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
- sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
- sBreakDeadTimeConfig.DeadTime = 0;
- sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
- sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
- sBreakDeadTimeConfig.BreakFilter = 0;
- sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
- sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
- sBreakDeadTimeConfig.Break2Filter = 0;
- sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
- if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM1_Init 2 */
- memcpy(&fanTimerConfigOC, &sConfigOC, sizeof(TIM_OC_InitTypeDef));
- /* USER CODE END TIM1_Init 2 */
- HAL_TIM_MspPostInit(&htim1);
- }
- /**
- * @brief TIM3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM3_Init(void)
- {
- /* USER CODE BEGIN TIM3_Init 0 */
- /* USER CODE END TIM3_Init 0 */
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- TIM_OC_InitTypeDef sConfigOC = {0};
- /* USER CODE BEGIN TIM3_Init 1 */
- /* USER CODE END TIM3_Init 1 */
- htim3.Instance = TIM3;
- htim3.Init.Prescaler = 199;
- htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim3.Init.Period = 999;
- htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
- if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sConfigOC.OCMode = TIM_OCMODE_COMBINED_PWM1;
- sConfigOC.Pulse = 500;
- sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
- sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
- if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
- {
- Error_Handler();
- }
- __HAL_TIM_DISABLE_OCxPRELOAD(&htim3, TIM_CHANNEL_1);
- sConfigOC.OCMode = TIM_OCMODE_PWM1;
- if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
- {
- Error_Handler();
- }
- __HAL_TIM_DISABLE_OCxPRELOAD(&htim3, TIM_CHANNEL_2);
- if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
- {
- Error_Handler();
- }
- __HAL_TIM_DISABLE_OCxPRELOAD(&htim3, TIM_CHANNEL_3);
- if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
- {
- Error_Handler();
- }
- __HAL_TIM_DISABLE_OCxPRELOAD(&htim3, TIM_CHANNEL_4);
- /* USER CODE BEGIN TIM3_Init 2 */
- memcpy(&motorXYTimerConfigOC, &sConfigOC, sizeof(TIM_OC_InitTypeDef));
- /* USER CODE END TIM3_Init 2 */
- HAL_TIM_MspPostInit(&htim3);
- }
- /**
- * @brief TIM8 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM8_Init(void)
- {
- /* USER CODE BEGIN TIM8_Init 0 */
- /* USER CODE END TIM8_Init 0 */
- TIM_ClockConfigTypeDef sClockSourceConfig = {0};
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- /* USER CODE BEGIN TIM8_Init 1 */
- /* USER CODE END TIM8_Init 1 */
- htim8.Instance = TIM8;
- htim8.Init.Prescaler = 0;
- htim8.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim8.Init.Period = 1999;
- htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim8.Init.RepetitionCounter = 0;
- htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
- if (HAL_TIM_Base_Init(&htim8) != HAL_OK)
- {
- Error_Handler();
- }
- sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
- if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
- sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM8_Init 2 */
- /* USER CODE END TIM8_Init 2 */
- }
- /**
- * @brief UART8 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_UART8_Init(void)
- {
- /* USER CODE BEGIN UART8_Init 0 */
- /* USER CODE END UART8_Init 0 */
- /* USER CODE BEGIN UART8_Init 1 */
- /* USER CODE END UART8_Init 1 */
- huart8.Instance = UART8;
- huart8.Init.BaudRate = 115200;
- huart8.Init.WordLength = UART_WORDLENGTH_8B;
- huart8.Init.StopBits = UART_STOPBITS_1;
- huart8.Init.Parity = UART_PARITY_NONE;
- huart8.Init.Mode = UART_MODE_TX_RX;
- huart8.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart8.Init.OverSampling = UART_OVERSAMPLING_16;
- huart8.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart8.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart8.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
- if (HAL_UART_Init(&huart8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart8, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart8, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart8) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN UART8_Init 2 */
- /* USER CODE END UART8_Init 2 */
- }
- /**
- * @brief USART1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART1_UART_Init(void)
- {
- /* USER CODE BEGIN USART1_Init 0 */
- /* USER CODE END USART1_Init 0 */
- /* USER CODE BEGIN USART1_Init 1 */
- /* USER CODE END USART1_Init 1 */
- huart1.Instance = USART1;
- huart1.Init.BaudRate = 115200;
- huart1.Init.WordLength = UART_WORDLENGTH_8B;
- huart1.Init.StopBits = UART_STOPBITS_1;
- huart1.Init.Parity = UART_PARITY_NONE;
- huart1.Init.Mode = UART_MODE_TX_RX;
- huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
- huart1.Init.OverSampling = UART_OVERSAMPLING_16;
- huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
- huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
- huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_TXINVERT_INIT;
- huart1.AdvancedInit.TxPinLevelInvert = UART_ADVFEATURE_TXINV_ENABLE;
- if (HAL_UART_Init(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART1_Init 2 */
- /* USER CODE END USART1_Init 2 */
- }
- /**
- * Enable DMA controller clock
- */
- static void MX_DMA_Init(void)
- {
- /* DMA controller clock enable */
- __HAL_RCC_DMA1_CLK_ENABLE();
- /* DMA interrupt init */
- /* DMA1_Stream0_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
- /* DMA1_Stream1_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
- /* DMA1_Stream2_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA1_Stream2_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(DMA1_Stream2_IRQn);
- }
- /**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct = {0};
- /* USER CODE BEGIN MX_GPIO_Init_1 */
- /* USER CODE END MX_GPIO_Init_1 */
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOE, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
- |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET);
- /*Configure GPIO pin Output Level */
- HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
- /*Configure GPIO pins : PE7 PE8 PE9 PE10
- PE13 PE14 PE15 */
- GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10
- |GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
- /*Configure GPIO pins : PB10 PB11 */
- GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- /*Configure GPIO pins : PD8 PD9 PD10 PD11
- PD12 PD13 PD3 */
- GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
- |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_3;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- /*Configure GPIO pins : PD14 PD15 */
- GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
- GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- /*Configure GPIO pins : PD4 PD5 PD6 PD7 */
- GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Pull = GPIO_NOPULL;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- /* EXTI interrupt init*/
- HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
- HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
- /* USER CODE BEGIN MX_GPIO_Init_2 */
- /* USER CODE END MX_GPIO_Init_2 */
- }
- /* USER CODE BEGIN 4 */
- void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
- {
- if(hadc->Instance == ADC1)
- {
- DbgLEDToggle(DBG_LED4);
- SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)adc1Data.adcDataBuffer) & ~(uint32_t)0x1F), __SCB_DCACHE_LINE_SIZE);
- if(adc1MeasDataQueue != NULL)
- {
- osMessageQueuePut(adc1MeasDataQueue, &adc1Data, 0, 0);
- }
- if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint32_t)) != HAL_OK)
- {
- Error_Handler();
- }
- }
- if(hadc->Instance == ADC3)
- {
- SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)adc3Data.adcDataBuffer) & ~(uint32_t)0x1F), __SCB_DCACHE_LINE_SIZE);
- if(adc3MeasDataQueue != NULL)
- {
- osMessageQueuePut(adc3MeasDataQueue, &adc3Data, 0, 0);
- }
- if(HAL_ADC_Start_DMA(&hadc3, (uint32_t *)adc3Data.adcDataBuffer, ADC3LastData*sizeof(uint16_t)) != HAL_OK)
- {
- Error_Handler();
- }
- }
- osTimerStop (debugLedTimerHandle);
- }
- /* USER CODE END 4 */
- /* USER CODE BEGIN Header_StartDefaultTask */
- /**
- * @brief Function implementing the defaultTask thread.
- * @param argument: Not used
- * @retval None
- */
- /* USER CODE END Header_StartDefaultTask */
- void StartDefaultTask(void *argument)
- {
- /* USER CODE BEGIN 5 */
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- SelectCurrentSensorGain(CurrentSensorL1, csGain3);
- SelectCurrentSensorGain(CurrentSensorL2, csGain3);
- SelectCurrentSensorGain(CurrentSensorL3, csGain3);
- EnableCurrentSensors();
- osDelay(pdMS_TO_TICKS(100));
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- if(HAL_TIM_Base_Start(&htim8) != HAL_OK)
- {
- Error_Handler();
- }
- if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)adc1Data.adcDataBuffer, ADC1LastData*sizeof(uint32_t)) != HAL_OK)
- {
- Error_Handler();
- }
- if(HAL_ADC_Start_DMA(&hadc3, (uint32_t *)adc3Data.adcDataBuffer, ADC3LastData*sizeof(uint16_t)) != HAL_OK)
- {
- Error_Handler();
- }
- HAL_COMP_Start(&hcomp1);
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- /* Infinite loop */
- for(;;)
- {
- osDelay(pdMS_TO_TICKS(100));
- #ifdef WATCHDOG_ENABLED
- HAL_IWDG_Refresh(&hiwdg1);
- #endif
- if(HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_1) == HAL_TIM_CHANNEL_STATE_READY &&
- HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_2) == HAL_TIM_CHANNEL_STATE_READY)
- {
- if(osMutexAcquire(sensorsInfoMutex, osWaitForever) == osOK)
- {
- sensorsInfo.motorXStatus = 0;
- osMutexRelease(sensorsInfoMutex);
- }
- }
- if(HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_3) == HAL_TIM_CHANNEL_STATE_READY &&
- HAL_TIM_GetChannelState(&htim3, TIM_CHANNEL_4) == HAL_TIM_CHANNEL_STATE_READY)
- {
- if(osMutexAcquire(sensorsInfoMutex, osWaitForever) == osOK)
- {
- sensorsInfo.motorYStatus = 0;
- osMutexRelease(sensorsInfoMutex);
- }
- }
- }
- /* USER CODE END 5 */
- }
- /* debugLedTimerCallback function */
- void debugLedTimerCallback(void *argument)
- {
- /* USER CODE BEGIN debugLedTimerCallback */
- DbgLEDOff (DBG_LED1);
- /* USER CODE END debugLedTimerCallback */
- }
- /* fanTimerCallback function */
- void fanTimerCallback(void *argument)
- {
- /* USER CODE BEGIN fanTimerCallback */
- HAL_TIM_PWM_Stop(&htim1, TIM_CHANNEL_2);
- /* USER CODE END fanTimerCallback */
- }
- /* motorXTimerCallback function */
- void motorXTimerCallback(void *argument)
- {
- /* USER CODE BEGIN motorXTimerCallback */
- MotorAction(&htim3, &motorXYTimerConfigOC, TIM_CHANNEL_1, TIM_CHANNEL_2, HiZ, 0);
- HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
- HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_2);
- /* USER CODE END motorXTimerCallback */
- }
- /* motorYTimerCallback function */
- void motorYTimerCallback(void *argument)
- {
- /* USER CODE BEGIN motorYTimerCallback */
- MotorAction(&htim3, &motorXYTimerConfigOC, TIM_CHANNEL_3, TIM_CHANNEL_4, HiZ, 0);
- HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3);
- HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_4);
- /* USER CODE END motorYTimerCallback */
- }
- /* MPU Configuration */
- void MPU_Config(void)
- {
- MPU_Region_InitTypeDef MPU_InitStruct = {0};
- /* Disables the MPU */
- HAL_MPU_Disable();
- /** Initializes and configures the Region and the memory to be protected
- */
- MPU_InitStruct.Enable = MPU_REGION_ENABLE;
- MPU_InitStruct.Number = MPU_REGION_NUMBER0;
- MPU_InitStruct.BaseAddress = 0x0;
- MPU_InitStruct.Size = MPU_REGION_SIZE_4GB;
- MPU_InitStruct.SubRegionDisable = 0x87;
- MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
- MPU_InitStruct.AccessPermission = MPU_REGION_NO_ACCESS;
- MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
- MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
- MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
- MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
- HAL_MPU_ConfigRegion(&MPU_InitStruct);
- /** Initializes and configures the Region and the memory to be protected
- */
- MPU_InitStruct.Number = MPU_REGION_NUMBER1;
- MPU_InitStruct.BaseAddress = 0x24020000;
- MPU_InitStruct.Size = MPU_REGION_SIZE_128KB;
- MPU_InitStruct.SubRegionDisable = 0x0;
- MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
- MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
- MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
- HAL_MPU_ConfigRegion(&MPU_InitStruct);
- /** Initializes and configures the Region and the memory to be protected
- */
- MPU_InitStruct.Number = MPU_REGION_NUMBER2;
- MPU_InitStruct.BaseAddress = 0x24040000;
- MPU_InitStruct.Size = MPU_REGION_SIZE_512B;
- MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
- MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
- MPU_InitStruct.IsBufferable = MPU_ACCESS_BUFFERABLE;
- HAL_MPU_ConfigRegion(&MPU_InitStruct);
- /* Enables the MPU */
- HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
- }
- /**
- * @brief Period elapsed callback in non blocking mode
- * @note This function is called when TIM6 interrupt took place, inside
- * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
- * a global variable "uwTick" used as application time base.
- * @param htim : TIM handle
- * @retval None
- */
- void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
- {
- /* USER CODE BEGIN Callback 0 */
- /* USER CODE END Callback 0 */
- if (htim->Instance == TIM6) {
- HAL_IncTick();
- }
- /* USER CODE BEGIN Callback 1 */
- else if (htim->Instance == TIM4)
- {
- encoderXChannelA = 0;
- encoderXChannelB = 0;
- }
- else if (htim->Instance == TIM2)
- {
- encoderYChannelA = 0;
- encoderYChannelB = 0;
- }
- /* USER CODE END Callback 1 */
- }
- /**
- * @brief This function is executed in case of error occurrence.
- * @retval None
- */
- void Error_Handler(void)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- __disable_irq();
- NVIC_SystemReset();
- while (1)
- {
- }
- /* USER CODE END Error_Handler_Debug */
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t *file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif /* USE_FULL_ASSERT */
|