Mikis Wöhrmann
/
Nucleo_PWM_TEST
Just a test...
main.cpp@0:6b1a8c783fef, 2018-07-23 (annotated)
- Committer:
- Airdevelopments
- Date:
- Mon Jul 23 23:09:43 2018 +0000
- Revision:
- 0:6b1a8c783fef
Just a test, no real use...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Airdevelopments | 0:6b1a8c783fef | 1 | |
Airdevelopments | 0:6b1a8c783fef | 2 | /** |
Airdevelopments | 0:6b1a8c783fef | 3 | ****************************************************************************** |
Airdevelopments | 0:6b1a8c783fef | 4 | * @file : main.c |
Airdevelopments | 0:6b1a8c783fef | 5 | * @brief : Main program body |
Airdevelopments | 0:6b1a8c783fef | 6 | ****************************************************************************** |
Airdevelopments | 0:6b1a8c783fef | 7 | ** This notice applies to any and all portions of this file |
Airdevelopments | 0:6b1a8c783fef | 8 | * that are not between comment pairs USER CODE BEGIN and |
Airdevelopments | 0:6b1a8c783fef | 9 | * USER CODE END. Other portions of this file, whether |
Airdevelopments | 0:6b1a8c783fef | 10 | * inserted by the user or by software development tools |
Airdevelopments | 0:6b1a8c783fef | 11 | * are owned by their respective copyright owners. |
Airdevelopments | 0:6b1a8c783fef | 12 | * |
Airdevelopments | 0:6b1a8c783fef | 13 | * COPYRIGHT(c) 2018 STMicroelectronics |
Airdevelopments | 0:6b1a8c783fef | 14 | * |
Airdevelopments | 0:6b1a8c783fef | 15 | * Redistribution and use in source and binary forms, with or without modification, |
Airdevelopments | 0:6b1a8c783fef | 16 | * are permitted provided that the following conditions are met: |
Airdevelopments | 0:6b1a8c783fef | 17 | * 1. Redistributions of source code must retain the above copyright notice, |
Airdevelopments | 0:6b1a8c783fef | 18 | * this list of conditions and the following disclaimer. |
Airdevelopments | 0:6b1a8c783fef | 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Airdevelopments | 0:6b1a8c783fef | 20 | * this list of conditions and the following disclaimer in the documentation |
Airdevelopments | 0:6b1a8c783fef | 21 | * and/or other materials provided with the distribution. |
Airdevelopments | 0:6b1a8c783fef | 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Airdevelopments | 0:6b1a8c783fef | 23 | * may be used to endorse or promote products derived from this software |
Airdevelopments | 0:6b1a8c783fef | 24 | * without specific prior written permission. |
Airdevelopments | 0:6b1a8c783fef | 25 | * |
Airdevelopments | 0:6b1a8c783fef | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Airdevelopments | 0:6b1a8c783fef | 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Airdevelopments | 0:6b1a8c783fef | 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Airdevelopments | 0:6b1a8c783fef | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Airdevelopments | 0:6b1a8c783fef | 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Airdevelopments | 0:6b1a8c783fef | 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Airdevelopments | 0:6b1a8c783fef | 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Airdevelopments | 0:6b1a8c783fef | 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Airdevelopments | 0:6b1a8c783fef | 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Airdevelopments | 0:6b1a8c783fef | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Airdevelopments | 0:6b1a8c783fef | 36 | * |
Airdevelopments | 0:6b1a8c783fef | 37 | ****************************************************************************** |
Airdevelopments | 0:6b1a8c783fef | 38 | */ |
Airdevelopments | 0:6b1a8c783fef | 39 | /* Includes ------------------------------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 40 | #include "mbed.h" |
Airdevelopments | 0:6b1a8c783fef | 41 | #include "stm32f4xx_hal.h" |
Airdevelopments | 0:6b1a8c783fef | 42 | |
Airdevelopments | 0:6b1a8c783fef | 43 | /* USER CODE BEGIN Includes */ |
Airdevelopments | 0:6b1a8c783fef | 44 | |
Airdevelopments | 0:6b1a8c783fef | 45 | /* USER CODE END Includes */ |
Airdevelopments | 0:6b1a8c783fef | 46 | |
Airdevelopments | 0:6b1a8c783fef | 47 | /* Private variables ---------------------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 48 | TIM_HandleTypeDef htim3; |
Airdevelopments | 0:6b1a8c783fef | 49 | |
Airdevelopments | 0:6b1a8c783fef | 50 | UART_HandleTypeDef huart2; |
Airdevelopments | 0:6b1a8c783fef | 51 | |
Airdevelopments | 0:6b1a8c783fef | 52 | /* USER CODE BEGIN PV */ |
Airdevelopments | 0:6b1a8c783fef | 53 | /* Private variables ---------------------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 54 | |
Airdevelopments | 0:6b1a8c783fef | 55 | /* USER CODE END PV */ |
Airdevelopments | 0:6b1a8c783fef | 56 | |
Airdevelopments | 0:6b1a8c783fef | 57 | /* Private function prototypes -----------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 58 | void SystemClock_Config(void); |
Airdevelopments | 0:6b1a8c783fef | 59 | static void MX_GPIO_Init(void); |
Airdevelopments | 0:6b1a8c783fef | 60 | static void MX_USART2_UART_Init(void); |
Airdevelopments | 0:6b1a8c783fef | 61 | static void MX_TIM3_Init(void); |
Airdevelopments | 0:6b1a8c783fef | 62 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); |
Airdevelopments | 0:6b1a8c783fef | 63 | |
Airdevelopments | 0:6b1a8c783fef | 64 | |
Airdevelopments | 0:6b1a8c783fef | 65 | /* USER CODE BEGIN PFP */ |
Airdevelopments | 0:6b1a8c783fef | 66 | /* Private function prototypes -----------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 67 | |
Airdevelopments | 0:6b1a8c783fef | 68 | /* USER CODE END PFP */ |
Airdevelopments | 0:6b1a8c783fef | 69 | |
Airdevelopments | 0:6b1a8c783fef | 70 | /* USER CODE BEGIN 0 */ |
Airdevelopments | 0:6b1a8c783fef | 71 | |
Airdevelopments | 0:6b1a8c783fef | 72 | /* USER CODE END 0 */ |
Airdevelopments | 0:6b1a8c783fef | 73 | |
Airdevelopments | 0:6b1a8c783fef | 74 | /** |
Airdevelopments | 0:6b1a8c783fef | 75 | * @brief The application entry point. |
Airdevelopments | 0:6b1a8c783fef | 76 | * |
Airdevelopments | 0:6b1a8c783fef | 77 | * @retval None |
Airdevelopments | 0:6b1a8c783fef | 78 | */ |
Airdevelopments | 0:6b1a8c783fef | 79 | int main(void) |
Airdevelopments | 0:6b1a8c783fef | 80 | { |
Airdevelopments | 0:6b1a8c783fef | 81 | /* USER CODE BEGIN 1 */ |
Airdevelopments | 0:6b1a8c783fef | 82 | |
Airdevelopments | 0:6b1a8c783fef | 83 | /* USER CODE END 1 */ |
Airdevelopments | 0:6b1a8c783fef | 84 | |
Airdevelopments | 0:6b1a8c783fef | 85 | /* MCU Configuration----------------------------------------------------------*/ |
Airdevelopments | 0:6b1a8c783fef | 86 | |
Airdevelopments | 0:6b1a8c783fef | 87 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
Airdevelopments | 0:6b1a8c783fef | 88 | HAL_Init(); |
Airdevelopments | 0:6b1a8c783fef | 89 | |
Airdevelopments | 0:6b1a8c783fef | 90 | /* USER CODE BEGIN Init */ |
Airdevelopments | 0:6b1a8c783fef | 91 | |
Airdevelopments | 0:6b1a8c783fef | 92 | /* USER CODE END Init */ |
Airdevelopments | 0:6b1a8c783fef | 93 | |
Airdevelopments | 0:6b1a8c783fef | 94 | /* Configure the system clock */ |
Airdevelopments | 0:6b1a8c783fef | 95 | SystemClock_Config(); |
Airdevelopments | 0:6b1a8c783fef | 96 | |
Airdevelopments | 0:6b1a8c783fef | 97 | /* USER CODE BEGIN SysInit */ |
Airdevelopments | 0:6b1a8c783fef | 98 | |
Airdevelopments | 0:6b1a8c783fef | 99 | /* USER CODE END SysInit */ |
Airdevelopments | 0:6b1a8c783fef | 100 | |
Airdevelopments | 0:6b1a8c783fef | 101 | /* Initialize all configured peripherals */ |
Airdevelopments | 0:6b1a8c783fef | 102 | MX_GPIO_Init(); |
Airdevelopments | 0:6b1a8c783fef | 103 | MX_USART2_UART_Init(); |
Airdevelopments | 0:6b1a8c783fef | 104 | MX_TIM3_Init(); |
Airdevelopments | 0:6b1a8c783fef | 105 | /* USER CODE BEGIN 2 */ |
Airdevelopments | 0:6b1a8c783fef | 106 | |
Airdevelopments | 0:6b1a8c783fef | 107 | /* USER CODE END 2 */ |
Airdevelopments | 0:6b1a8c783fef | 108 | |
Airdevelopments | 0:6b1a8c783fef | 109 | /* Infinite loop */ |
Airdevelopments | 0:6b1a8c783fef | 110 | /* USER CODE BEGIN WHILE */ |
Airdevelopments | 0:6b1a8c783fef | 111 | while (1) |
Airdevelopments | 0:6b1a8c783fef | 112 | { |
Airdevelopments | 0:6b1a8c783fef | 113 | |
Airdevelopments | 0:6b1a8c783fef | 114 | /* USER CODE END WHILE */ |
Airdevelopments | 0:6b1a8c783fef | 115 | |
Airdevelopments | 0:6b1a8c783fef | 116 | /* USER CODE BEGIN 3 */ |
Airdevelopments | 0:6b1a8c783fef | 117 | |
Airdevelopments | 0:6b1a8c783fef | 118 | } |
Airdevelopments | 0:6b1a8c783fef | 119 | /* USER CODE END 3 */ |
Airdevelopments | 0:6b1a8c783fef | 120 | |
Airdevelopments | 0:6b1a8c783fef | 121 | } |
Airdevelopments | 0:6b1a8c783fef | 122 | |
Airdevelopments | 0:6b1a8c783fef | 123 | /** |
Airdevelopments | 0:6b1a8c783fef | 124 | * @brief System Clock Configuration |
Airdevelopments | 0:6b1a8c783fef | 125 | * @retval None |
Airdevelopments | 0:6b1a8c783fef | 126 | */ |
Airdevelopments | 0:6b1a8c783fef | 127 | void SystemClock_Config(void) |
Airdevelopments | 0:6b1a8c783fef | 128 | { |
Airdevelopments | 0:6b1a8c783fef | 129 | |
Airdevelopments | 0:6b1a8c783fef | 130 | RCC_OscInitTypeDef RCC_OscInitStruct; |
Airdevelopments | 0:6b1a8c783fef | 131 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
Airdevelopments | 0:6b1a8c783fef | 132 | |
Airdevelopments | 0:6b1a8c783fef | 133 | /**Configure the main internal regulator output voltage |
Airdevelopments | 0:6b1a8c783fef | 134 | */ |
Airdevelopments | 0:6b1a8c783fef | 135 | __HAL_RCC_PWR_CLK_ENABLE(); |
Airdevelopments | 0:6b1a8c783fef | 136 | |
Airdevelopments | 0:6b1a8c783fef | 137 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
Airdevelopments | 0:6b1a8c783fef | 138 | |
Airdevelopments | 0:6b1a8c783fef | 139 | /**Initializes the CPU, AHB and APB busses clocks |
Airdevelopments | 0:6b1a8c783fef | 140 | */ |
Airdevelopments | 0:6b1a8c783fef | 141 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
Airdevelopments | 0:6b1a8c783fef | 142 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
Airdevelopments | 0:6b1a8c783fef | 143 | RCC_OscInitStruct.HSICalibrationValue = 16; |
Airdevelopments | 0:6b1a8c783fef | 144 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
Airdevelopments | 0:6b1a8c783fef | 145 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
Airdevelopments | 0:6b1a8c783fef | 146 | RCC_OscInitStruct.PLL.PLLM = 16; |
Airdevelopments | 0:6b1a8c783fef | 147 | RCC_OscInitStruct.PLL.PLLN = 336; |
Airdevelopments | 0:6b1a8c783fef | 148 | RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; |
Airdevelopments | 0:6b1a8c783fef | 149 | RCC_OscInitStruct.PLL.PLLQ = 7; |
Airdevelopments | 0:6b1a8c783fef | 150 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 151 | { |
Airdevelopments | 0:6b1a8c783fef | 152 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 153 | } |
Airdevelopments | 0:6b1a8c783fef | 154 | |
Airdevelopments | 0:6b1a8c783fef | 155 | /**Initializes the CPU, AHB and APB busses clocks |
Airdevelopments | 0:6b1a8c783fef | 156 | */ |
Airdevelopments | 0:6b1a8c783fef | 157 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
Airdevelopments | 0:6b1a8c783fef | 158 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
Airdevelopments | 0:6b1a8c783fef | 159 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
Airdevelopments | 0:6b1a8c783fef | 160 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
Airdevelopments | 0:6b1a8c783fef | 161 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
Airdevelopments | 0:6b1a8c783fef | 162 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
Airdevelopments | 0:6b1a8c783fef | 163 | |
Airdevelopments | 0:6b1a8c783fef | 164 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 165 | { |
Airdevelopments | 0:6b1a8c783fef | 166 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 167 | } |
Airdevelopments | 0:6b1a8c783fef | 168 | |
Airdevelopments | 0:6b1a8c783fef | 169 | /**Configure the Systick interrupt time |
Airdevelopments | 0:6b1a8c783fef | 170 | */ |
Airdevelopments | 0:6b1a8c783fef | 171 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
Airdevelopments | 0:6b1a8c783fef | 172 | |
Airdevelopments | 0:6b1a8c783fef | 173 | /**Configure the Systick |
Airdevelopments | 0:6b1a8c783fef | 174 | */ |
Airdevelopments | 0:6b1a8c783fef | 175 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
Airdevelopments | 0:6b1a8c783fef | 176 | |
Airdevelopments | 0:6b1a8c783fef | 177 | /* SysTick_IRQn interrupt configuration */ |
Airdevelopments | 0:6b1a8c783fef | 178 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
Airdevelopments | 0:6b1a8c783fef | 179 | } |
Airdevelopments | 0:6b1a8c783fef | 180 | |
Airdevelopments | 0:6b1a8c783fef | 181 | /* TIM3 init function */ |
Airdevelopments | 0:6b1a8c783fef | 182 | static void MX_TIM3_Init(void) |
Airdevelopments | 0:6b1a8c783fef | 183 | { |
Airdevelopments | 0:6b1a8c783fef | 184 | |
Airdevelopments | 0:6b1a8c783fef | 185 | TIM_ClockConfigTypeDef sClockSourceConfig; |
Airdevelopments | 0:6b1a8c783fef | 186 | TIM_MasterConfigTypeDef sMasterConfig; |
Airdevelopments | 0:6b1a8c783fef | 187 | TIM_OC_InitTypeDef sConfigOC; |
Airdevelopments | 0:6b1a8c783fef | 188 | |
Airdevelopments | 0:6b1a8c783fef | 189 | htim3.Instance = TIM3; |
Airdevelopments | 0:6b1a8c783fef | 190 | htim3.Init.Prescaler = 0; |
Airdevelopments | 0:6b1a8c783fef | 191 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
Airdevelopments | 0:6b1a8c783fef | 192 | htim3.Init.Period = 0; |
Airdevelopments | 0:6b1a8c783fef | 193 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
Airdevelopments | 0:6b1a8c783fef | 194 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 195 | { |
Airdevelopments | 0:6b1a8c783fef | 196 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 197 | } |
Airdevelopments | 0:6b1a8c783fef | 198 | |
Airdevelopments | 0:6b1a8c783fef | 199 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
Airdevelopments | 0:6b1a8c783fef | 200 | if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 201 | { |
Airdevelopments | 0:6b1a8c783fef | 202 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 203 | } |
Airdevelopments | 0:6b1a8c783fef | 204 | |
Airdevelopments | 0:6b1a8c783fef | 205 | if (HAL_TIM_PWM_Init(&htim3) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 206 | { |
Airdevelopments | 0:6b1a8c783fef | 207 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 208 | } |
Airdevelopments | 0:6b1a8c783fef | 209 | |
Airdevelopments | 0:6b1a8c783fef | 210 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
Airdevelopments | 0:6b1a8c783fef | 211 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
Airdevelopments | 0:6b1a8c783fef | 212 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 213 | { |
Airdevelopments | 0:6b1a8c783fef | 214 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 215 | } |
Airdevelopments | 0:6b1a8c783fef | 216 | |
Airdevelopments | 0:6b1a8c783fef | 217 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
Airdevelopments | 0:6b1a8c783fef | 218 | sConfigOC.Pulse = 0; |
Airdevelopments | 0:6b1a8c783fef | 219 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
Airdevelopments | 0:6b1a8c783fef | 220 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
Airdevelopments | 0:6b1a8c783fef | 221 | if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 222 | { |
Airdevelopments | 0:6b1a8c783fef | 223 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 224 | } |
Airdevelopments | 0:6b1a8c783fef | 225 | |
Airdevelopments | 0:6b1a8c783fef | 226 | HAL_TIM_MspPostInit(&htim3); |
Airdevelopments | 0:6b1a8c783fef | 227 | |
Airdevelopments | 0:6b1a8c783fef | 228 | } |
Airdevelopments | 0:6b1a8c783fef | 229 | |
Airdevelopments | 0:6b1a8c783fef | 230 | /* USART2 init function */ |
Airdevelopments | 0:6b1a8c783fef | 231 | static void MX_USART2_UART_Init(void) |
Airdevelopments | 0:6b1a8c783fef | 232 | { |
Airdevelopments | 0:6b1a8c783fef | 233 | |
Airdevelopments | 0:6b1a8c783fef | 234 | huart2.Instance = USART2; |
Airdevelopments | 0:6b1a8c783fef | 235 | huart2.Init.BaudRate = 115200; |
Airdevelopments | 0:6b1a8c783fef | 236 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
Airdevelopments | 0:6b1a8c783fef | 237 | huart2.Init.StopBits = UART_STOPBITS_1; |
Airdevelopments | 0:6b1a8c783fef | 238 | huart2.Init.Parity = UART_PARITY_NONE; |
Airdevelopments | 0:6b1a8c783fef | 239 | huart2.Init.Mode = UART_MODE_TX_RX; |
Airdevelopments | 0:6b1a8c783fef | 240 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
Airdevelopments | 0:6b1a8c783fef | 241 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
Airdevelopments | 0:6b1a8c783fef | 242 | if (HAL_UART_Init(&huart2) != HAL_OK) |
Airdevelopments | 0:6b1a8c783fef | 243 | { |
Airdevelopments | 0:6b1a8c783fef | 244 | _Error_Handler(__FILE__, __LINE__); |
Airdevelopments | 0:6b1a8c783fef | 245 | } |
Airdevelopments | 0:6b1a8c783fef | 246 | |
Airdevelopments | 0:6b1a8c783fef | 247 | } |
Airdevelopments | 0:6b1a8c783fef | 248 | |
Airdevelopments | 0:6b1a8c783fef | 249 | /** Configure pins as |
Airdevelopments | 0:6b1a8c783fef | 250 | * Analog |
Airdevelopments | 0:6b1a8c783fef | 251 | * Input |
Airdevelopments | 0:6b1a8c783fef | 252 | * Output |
Airdevelopments | 0:6b1a8c783fef | 253 | * EVENT_OUT |
Airdevelopments | 0:6b1a8c783fef | 254 | * EXTI |
Airdevelopments | 0:6b1a8c783fef | 255 | */ |
Airdevelopments | 0:6b1a8c783fef | 256 | static void MX_GPIO_Init(void) |
Airdevelopments | 0:6b1a8c783fef | 257 | { |
Airdevelopments | 0:6b1a8c783fef | 258 | |
Airdevelopments | 0:6b1a8c783fef | 259 | GPIO_InitTypeDef GPIO_InitStruct; |
Airdevelopments | 0:6b1a8c783fef | 260 | |
Airdevelopments | 0:6b1a8c783fef | 261 | /* GPIO Ports Clock Enable */ |
Airdevelopments | 0:6b1a8c783fef | 262 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
Airdevelopments | 0:6b1a8c783fef | 263 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
Airdevelopments | 0:6b1a8c783fef | 264 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
Airdevelopments | 0:6b1a8c783fef | 265 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
Airdevelopments | 0:6b1a8c783fef | 266 | |
Airdevelopments | 0:6b1a8c783fef | 267 | /*Configure GPIO pin Output Level */ |
Airdevelopments | 0:6b1a8c783fef | 268 | HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); |
Airdevelopments | 0:6b1a8c783fef | 269 | |
Airdevelopments | 0:6b1a8c783fef | 270 | /*Configure GPIO pin : B1_Pin */ |
Airdevelopments | 0:6b1a8c783fef | 271 | GPIO_InitStruct.Pin = B1_Pin; |
Airdevelopments | 0:6b1a8c783fef | 272 | GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; |
Airdevelopments | 0:6b1a8c783fef | 273 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Airdevelopments | 0:6b1a8c783fef | 274 | HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct); |
Airdevelopments | 0:6b1a8c783fef | 275 | |
Airdevelopments | 0:6b1a8c783fef | 276 | /*Configure GPIO pin : LD2_Pin */ |
Airdevelopments | 0:6b1a8c783fef | 277 | GPIO_InitStruct.Pin = LD2_Pin; |
Airdevelopments | 0:6b1a8c783fef | 278 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
Airdevelopments | 0:6b1a8c783fef | 279 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
Airdevelopments | 0:6b1a8c783fef | 280 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
Airdevelopments | 0:6b1a8c783fef | 281 | HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct); |
Airdevelopments | 0:6b1a8c783fef | 282 | |
Airdevelopments | 0:6b1a8c783fef | 283 | } |
Airdevelopments | 0:6b1a8c783fef | 284 | |
Airdevelopments | 0:6b1a8c783fef | 285 | /* USER CODE BEGIN 4 */ |
Airdevelopments | 0:6b1a8c783fef | 286 | |
Airdevelopments | 0:6b1a8c783fef | 287 | /* USER CODE END 4 */ |
Airdevelopments | 0:6b1a8c783fef | 288 | |
Airdevelopments | 0:6b1a8c783fef | 289 | /** |
Airdevelopments | 0:6b1a8c783fef | 290 | * @brief This function is executed in case of error occurrence. |
Airdevelopments | 0:6b1a8c783fef | 291 | * @param file: The file name as string. |
Airdevelopments | 0:6b1a8c783fef | 292 | * @param line: The line in file as a number. |
Airdevelopments | 0:6b1a8c783fef | 293 | * @retval None |
Airdevelopments | 0:6b1a8c783fef | 294 | */ |
Airdevelopments | 0:6b1a8c783fef | 295 | void _Error_Handler(char *file, int line) |
Airdevelopments | 0:6b1a8c783fef | 296 | { |
Airdevelopments | 0:6b1a8c783fef | 297 | /* USER CODE BEGIN Error_Handler_Debug */ |
Airdevelopments | 0:6b1a8c783fef | 298 | /* User can add his own implementation to report the HAL error return state */ |
Airdevelopments | 0:6b1a8c783fef | 299 | while(1) |
Airdevelopments | 0:6b1a8c783fef | 300 | { |
Airdevelopments | 0:6b1a8c783fef | 301 | } |
Airdevelopments | 0:6b1a8c783fef | 302 | /* USER CODE END Error_Handler_Debug */ |
Airdevelopments | 0:6b1a8c783fef | 303 | } |
Airdevelopments | 0:6b1a8c783fef | 304 | |
Airdevelopments | 0:6b1a8c783fef | 305 | #ifdef USE_FULL_ASSERT |
Airdevelopments | 0:6b1a8c783fef | 306 | /** |
Airdevelopments | 0:6b1a8c783fef | 307 | * @brief Reports the name of the source file and the source line number |
Airdevelopments | 0:6b1a8c783fef | 308 | * where the assert_param error has occurred. |
Airdevelopments | 0:6b1a8c783fef | 309 | * @param file: pointer to the source file name |
Airdevelopments | 0:6b1a8c783fef | 310 | * @param line: assert_param error line source number |
Airdevelopments | 0:6b1a8c783fef | 311 | * @retval None |
Airdevelopments | 0:6b1a8c783fef | 312 | */ |
Airdevelopments | 0:6b1a8c783fef | 313 | void assert_failed(uint8_t* file, uint32_t line) |
Airdevelopments | 0:6b1a8c783fef | 314 | { |
Airdevelopments | 0:6b1a8c783fef | 315 | /* USER CODE BEGIN 6 */ |
Airdevelopments | 0:6b1a8c783fef | 316 | /* User can add his own implementation to report the file name and line number, |
Airdevelopments | 0:6b1a8c783fef | 317 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
Airdevelopments | 0:6b1a8c783fef | 318 | /* USER CODE END 6 */ |
Airdevelopments | 0:6b1a8c783fef | 319 | } |
Airdevelopments | 0:6b1a8c783fef | 320 | #endif /* USE_FULL_ASSERT */ |
Airdevelopments | 0:6b1a8c783fef | 321 | |
Airdevelopments | 0:6b1a8c783fef | 322 | /** |
Airdevelopments | 0:6b1a8c783fef | 323 | * @} |
Airdevelopments | 0:6b1a8c783fef | 324 | */ |
Airdevelopments | 0:6b1a8c783fef | 325 | |
Airdevelopments | 0:6b1a8c783fef | 326 | /** |
Airdevelopments | 0:6b1a8c783fef | 327 | * @} |
Airdevelopments | 0:6b1a8c783fef | 328 | */ |
Airdevelopments | 0:6b1a8c783fef | 329 | |
Airdevelopments | 0:6b1a8c783fef | 330 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
Airdevelopments | 0:6b1a8c783fef | 331 |