Updated for the next revision of the motor board

Committer:
elijahsj
Date:
Wed Aug 26 00:24:51 2020 +0000
Revision:
2:30503be9a375
Parent:
1:4c3c2b7337a6
Child:
3:2f46953e7c8b
Cleanup;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elijahsj 1:4c3c2b7337a6 1 #include "mbed.h"
elijahsj 1:4c3c2b7337a6 2 #include "HardwareSetup.h"
elijahsj 1:4c3c2b7337a6 3 #include "stm32h7xx_hal.h"
elijahsj 1:4c3c2b7337a6 4
elijahsj 1:4c3c2b7337a6 5 TIM_HandleTypeDef htim12;
elijahsj 1:4c3c2b7337a6 6 TIM_HandleTypeDef htim15;
elijahsj 1:4c3c2b7337a6 7 TIM_HandleTypeDef htim13;
elijahsj 1:4c3c2b7337a6 8 TIM_HandleTypeDef htim14;
elijahsj 1:4c3c2b7337a6 9 TIM_HandleTypeDef htim16;
elijahsj 1:4c3c2b7337a6 10 TIM_HandleTypeDef htim17;
elijahsj 1:4c3c2b7337a6 11
elijahsj 1:4c3c2b7337a6 12 void SystemClock_Config(void);
elijahsj 1:4c3c2b7337a6 13 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim);
elijahsj 1:4c3c2b7337a6 14 static void MX_TIM12_Init(void);
elijahsj 2:30503be9a375 15 static void MX_TIM13_Init(void);
elijahsj 2:30503be9a375 16 static void MX_TIM14_Init(void);
elijahsj 2:30503be9a375 17 static void MX_TIM15_Init(void);
elijahsj 2:30503be9a375 18 static void MX_TIM16_Init(void);
elijahsj 2:30503be9a375 19 static void MX_TIM17_Init(void);
elijahsj 1:4c3c2b7337a6 20
elijahsj 1:4c3c2b7337a6 21 void initHardware(){
elijahsj 1:4c3c2b7337a6 22 /* Initialise the HAL Layer */
elijahsj 1:4c3c2b7337a6 23 HAL_Init();
elijahsj 1:4c3c2b7337a6 24
elijahsj 1:4c3c2b7337a6 25 /* Configure the system clock */
elijahsj 1:4c3c2b7337a6 26 SystemClock_Config();
elijahsj 1:4c3c2b7337a6 27
elijahsj 1:4c3c2b7337a6 28 /* Initialize all configured peripherals */
elijahsj 1:4c3c2b7337a6 29 MX_TIM12_Init();
elijahsj 2:30503be9a375 30 MX_TIM13_Init();
elijahsj 2:30503be9a375 31 MX_TIM14_Init();
elijahsj 2:30503be9a375 32 MX_TIM15_Init();
elijahsj 2:30503be9a375 33 MX_TIM16_Init();
elijahsj 2:30503be9a375 34 MX_TIM17_Init();
elijahsj 2:30503be9a375 35 //HAL_TIM_Base_Start(&htim15);
elijahsj 2:30503be9a375 36
elijahsj 1:4c3c2b7337a6 37 HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_1); // start pwm generation
elijahsj 1:4c3c2b7337a6 38 HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_2); // start pwm generation
elijahsj 2:30503be9a375 39 HAL_TIM_PWM_Start(&htim13, TIM_CHANNEL_1); // start pwm generation
elijahsj 2:30503be9a375 40 HAL_TIM_PWM_Start(&htim14, TIM_CHANNEL_1); // start pwm generation
elijahsj 2:30503be9a375 41 HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_1); // start pwm generation
elijahsj 2:30503be9a375 42 HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2); // start pwm generation
elijahsj 2:30503be9a375 43 HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1); // start pwm generation
elijahsj 2:30503be9a375 44 HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1); // start pwm generation
elijahsj 2:30503be9a375 45
elijahsj 2:30503be9a375 46
elijahsj 1:4c3c2b7337a6 47 }
elijahsj 1:4c3c2b7337a6 48
elijahsj 1:4c3c2b7337a6 49 static void MX_TIM12_Init(void)
elijahsj 1:4c3c2b7337a6 50 {
elijahsj 1:4c3c2b7337a6 51 __HAL_RCC_TIM12_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 52 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 1:4c3c2b7337a6 53 htim12.Instance = TIM12;
elijahsj 1:4c3c2b7337a6 54 htim12.Init.Prescaler = 0;
elijahsj 1:4c3c2b7337a6 55 htim12.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 1:4c3c2b7337a6 56 htim12.Init.Period = PWM_PERIOD;
elijahsj 1:4c3c2b7337a6 57 htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 1:4c3c2b7337a6 58 htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 1:4c3c2b7337a6 59 if (HAL_TIM_PWM_Init(&htim12) != HAL_OK)
elijahsj 1:4c3c2b7337a6 60 {
elijahsj 1:4c3c2b7337a6 61 //Error_Handler();
elijahsj 1:4c3c2b7337a6 62 }
elijahsj 1:4c3c2b7337a6 63 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 1:4c3c2b7337a6 64 sConfigOC.Pulse = 0;
elijahsj 1:4c3c2b7337a6 65 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 1:4c3c2b7337a6 66 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 1:4c3c2b7337a6 67 if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 1:4c3c2b7337a6 68 {
elijahsj 1:4c3c2b7337a6 69 //Error_Handler();
elijahsj 1:4c3c2b7337a6 70 }
elijahsj 1:4c3c2b7337a6 71 if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
elijahsj 1:4c3c2b7337a6 72 {
elijahsj 1:4c3c2b7337a6 73 //Error_Handler();
elijahsj 1:4c3c2b7337a6 74 }
elijahsj 2:30503be9a375 75 HAL_TIM_MspPostInit(&htim12);
elijahsj 2:30503be9a375 76 }
elijahsj 2:30503be9a375 77
elijahsj 2:30503be9a375 78 static void MX_TIM13_Init(void)
elijahsj 2:30503be9a375 79 {
elijahsj 2:30503be9a375 80 __HAL_RCC_TIM13_CLK_ENABLE();
elijahsj 2:30503be9a375 81 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 2:30503be9a375 82 htim13.Instance = TIM13;
elijahsj 2:30503be9a375 83 htim13.Init.Prescaler = 0;
elijahsj 2:30503be9a375 84 htim13.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 2:30503be9a375 85 htim13.Init.Period = PWM_PERIOD;
elijahsj 2:30503be9a375 86 htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 2:30503be9a375 87 htim13.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 2:30503be9a375 88 if (HAL_TIM_Base_Init(&htim13) != HAL_OK)
elijahsj 2:30503be9a375 89 {
elijahsj 2:30503be9a375 90 //Error_Handler();
elijahsj 2:30503be9a375 91 }
elijahsj 2:30503be9a375 92 if (HAL_TIM_PWM_Init(&htim13) != HAL_OK)
elijahsj 2:30503be9a375 93 {
elijahsj 2:30503be9a375 94 //Error_Handler();
elijahsj 2:30503be9a375 95 }
elijahsj 2:30503be9a375 96 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 2:30503be9a375 97 sConfigOC.Pulse = 0;
elijahsj 2:30503be9a375 98 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 2:30503be9a375 99 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 2:30503be9a375 100 if (HAL_TIM_PWM_ConfigChannel(&htim13, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 2:30503be9a375 101 {
elijahsj 2:30503be9a375 102 //Error_Handler();
elijahsj 2:30503be9a375 103 }
elijahsj 2:30503be9a375 104 HAL_TIM_MspPostInit(&htim13);
elijahsj 2:30503be9a375 105 }
elijahsj 2:30503be9a375 106
elijahsj 2:30503be9a375 107 static void MX_TIM14_Init(void)
elijahsj 2:30503be9a375 108 {
elijahsj 2:30503be9a375 109 __HAL_RCC_TIM14_CLK_ENABLE();
elijahsj 2:30503be9a375 110 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 2:30503be9a375 111 htim14.Instance = TIM14;
elijahsj 2:30503be9a375 112 htim14.Init.Prescaler = 0;
elijahsj 2:30503be9a375 113 htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 2:30503be9a375 114 htim14.Init.Period = PWM_PERIOD;
elijahsj 2:30503be9a375 115 htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 2:30503be9a375 116 htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 2:30503be9a375 117 if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
elijahsj 2:30503be9a375 118 {
elijahsj 2:30503be9a375 119 //Error_Handler();
elijahsj 2:30503be9a375 120 }
elijahsj 2:30503be9a375 121 if (HAL_TIM_PWM_Init(&htim14) != HAL_OK)
elijahsj 2:30503be9a375 122 {
elijahsj 2:30503be9a375 123 //Error_Handler();
elijahsj 2:30503be9a375 124 }
elijahsj 2:30503be9a375 125 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 2:30503be9a375 126 sConfigOC.Pulse = 0;
elijahsj 2:30503be9a375 127 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 2:30503be9a375 128 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 2:30503be9a375 129 if (HAL_TIM_PWM_ConfigChannel(&htim14, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 2:30503be9a375 130 {
elijahsj 2:30503be9a375 131 //Error_Handler();
elijahsj 2:30503be9a375 132 }
elijahsj 2:30503be9a375 133 HAL_TIM_MspPostInit(&htim14);
elijahsj 2:30503be9a375 134 }
elijahsj 1:4c3c2b7337a6 135
elijahsj 2:30503be9a375 136 static void MX_TIM15_Init(void)
elijahsj 2:30503be9a375 137 {
elijahsj 2:30503be9a375 138 __HAL_RCC_TIM15_CLK_ENABLE();
elijahsj 2:30503be9a375 139 TIM_MasterConfigTypeDef sMasterConfig = {0};
elijahsj 2:30503be9a375 140 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 2:30503be9a375 141 TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
elijahsj 2:30503be9a375 142 htim15.Instance = TIM15;
elijahsj 2:30503be9a375 143 htim15.Init.Prescaler = 0;
elijahsj 2:30503be9a375 144 htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 2:30503be9a375 145 htim15.Init.Period = PWM_PERIOD;
elijahsj 2:30503be9a375 146 htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 2:30503be9a375 147 htim15.Init.RepetitionCounter = 0;
elijahsj 2:30503be9a375 148 htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 2:30503be9a375 149 if (HAL_TIM_PWM_Init(&htim15) != HAL_OK)
elijahsj 2:30503be9a375 150 {
elijahsj 2:30503be9a375 151 //Error_Handler();
elijahsj 2:30503be9a375 152 }
elijahsj 2:30503be9a375 153 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
elijahsj 2:30503be9a375 154 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
elijahsj 2:30503be9a375 155 if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
elijahsj 2:30503be9a375 156 {
elijahsj 2:30503be9a375 157 //Error_Handler();
elijahsj 2:30503be9a375 158 }
elijahsj 2:30503be9a375 159 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 2:30503be9a375 160 sConfigOC.Pulse = 0;
elijahsj 2:30503be9a375 161 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 2:30503be9a375 162 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
elijahsj 2:30503be9a375 163 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 2:30503be9a375 164 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
elijahsj 2:30503be9a375 165 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
elijahsj 2:30503be9a375 166 if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 2:30503be9a375 167 {
elijahsj 2:30503be9a375 168 //Error_Handler();
elijahsj 2:30503be9a375 169 }
elijahsj 2:30503be9a375 170 if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
elijahsj 2:30503be9a375 171 {
elijahsj 2:30503be9a375 172 //Error_Handler();
elijahsj 2:30503be9a375 173 }
elijahsj 2:30503be9a375 174 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
elijahsj 2:30503be9a375 175 sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
elijahsj 2:30503be9a375 176 sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
elijahsj 2:30503be9a375 177 sBreakDeadTimeConfig.DeadTime = 0;
elijahsj 2:30503be9a375 178 sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
elijahsj 2:30503be9a375 179 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
elijahsj 2:30503be9a375 180 sBreakDeadTimeConfig.BreakFilter = 0;
elijahsj 2:30503be9a375 181 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
elijahsj 2:30503be9a375 182 if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK)
elijahsj 2:30503be9a375 183 {
elijahsj 2:30503be9a375 184 //Error_Handler();
elijahsj 2:30503be9a375 185 }
elijahsj 2:30503be9a375 186 HAL_TIM_MspPostInit(&htim15);
elijahsj 2:30503be9a375 187
elijahsj 2:30503be9a375 188 }
elijahsj 2:30503be9a375 189
elijahsj 2:30503be9a375 190 static void MX_TIM16_Init(void)
elijahsj 2:30503be9a375 191 {
elijahsj 2:30503be9a375 192 __HAL_RCC_TIM16_CLK_ENABLE();
elijahsj 2:30503be9a375 193 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 2:30503be9a375 194 TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
elijahsj 2:30503be9a375 195 htim16.Instance = TIM16;
elijahsj 2:30503be9a375 196 htim16.Init.Prescaler = 0;
elijahsj 2:30503be9a375 197 htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 2:30503be9a375 198 htim16.Init.Period = PWM_PERIOD;
elijahsj 2:30503be9a375 199 htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 2:30503be9a375 200 htim16.Init.RepetitionCounter = 0;
elijahsj 2:30503be9a375 201 htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 2:30503be9a375 202 if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
elijahsj 2:30503be9a375 203 {
elijahsj 2:30503be9a375 204 //Error_Handler();
elijahsj 2:30503be9a375 205 }
elijahsj 2:30503be9a375 206 if (HAL_TIM_PWM_Init(&htim16) != HAL_OK)
elijahsj 2:30503be9a375 207 {
elijahsj 2:30503be9a375 208 //Error_Handler();
elijahsj 2:30503be9a375 209 }
elijahsj 2:30503be9a375 210 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 2:30503be9a375 211 sConfigOC.Pulse = 0;
elijahsj 2:30503be9a375 212 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 2:30503be9a375 213 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
elijahsj 2:30503be9a375 214 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 2:30503be9a375 215 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
elijahsj 2:30503be9a375 216 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
elijahsj 2:30503be9a375 217 if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 2:30503be9a375 218 {
elijahsj 2:30503be9a375 219 //Error_Handler();
elijahsj 2:30503be9a375 220 }
elijahsj 2:30503be9a375 221 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
elijahsj 2:30503be9a375 222 sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
elijahsj 2:30503be9a375 223 sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
elijahsj 2:30503be9a375 224 sBreakDeadTimeConfig.DeadTime = 0;
elijahsj 2:30503be9a375 225 sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
elijahsj 2:30503be9a375 226 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
elijahsj 2:30503be9a375 227 sBreakDeadTimeConfig.BreakFilter = 0;
elijahsj 2:30503be9a375 228 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
elijahsj 2:30503be9a375 229 if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK)
elijahsj 2:30503be9a375 230 {
elijahsj 2:30503be9a375 231 //Error_Handler();
elijahsj 2:30503be9a375 232 }
elijahsj 2:30503be9a375 233 HAL_TIM_MspPostInit(&htim16);
elijahsj 2:30503be9a375 234
elijahsj 2:30503be9a375 235 }
elijahsj 2:30503be9a375 236
elijahsj 2:30503be9a375 237 static void MX_TIM17_Init(void)
elijahsj 2:30503be9a375 238 {
elijahsj 2:30503be9a375 239 __HAL_RCC_TIM17_CLK_ENABLE();
elijahsj 2:30503be9a375 240 TIM_OC_InitTypeDef sConfigOC = {0};
elijahsj 2:30503be9a375 241 TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
elijahsj 2:30503be9a375 242 htim17.Instance = TIM17;
elijahsj 2:30503be9a375 243 htim17.Init.Prescaler = 0;
elijahsj 2:30503be9a375 244 htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
elijahsj 2:30503be9a375 245 htim17.Init.Period = PWM_PERIOD;
elijahsj 2:30503be9a375 246 htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
elijahsj 2:30503be9a375 247 htim17.Init.RepetitionCounter = 0;
elijahsj 2:30503be9a375 248 htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
elijahsj 2:30503be9a375 249 if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
elijahsj 2:30503be9a375 250 {
elijahsj 2:30503be9a375 251 //Error_Handler();
elijahsj 2:30503be9a375 252 }
elijahsj 2:30503be9a375 253 if (HAL_TIM_PWM_Init(&htim17) != HAL_OK)
elijahsj 2:30503be9a375 254 {
elijahsj 2:30503be9a375 255 //Error_Handler();
elijahsj 2:30503be9a375 256 }
elijahsj 2:30503be9a375 257 sConfigOC.OCMode = TIM_OCMODE_PWM1;
elijahsj 2:30503be9a375 258 sConfigOC.Pulse = 0;
elijahsj 2:30503be9a375 259 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
elijahsj 2:30503be9a375 260 sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
elijahsj 2:30503be9a375 261 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
elijahsj 2:30503be9a375 262 sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
elijahsj 2:30503be9a375 263 sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
elijahsj 2:30503be9a375 264 if (HAL_TIM_PWM_ConfigChannel(&htim17, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
elijahsj 2:30503be9a375 265 {
elijahsj 2:30503be9a375 266 //Error_Handler();
elijahsj 2:30503be9a375 267 }
elijahsj 2:30503be9a375 268 sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
elijahsj 2:30503be9a375 269 sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
elijahsj 2:30503be9a375 270 sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
elijahsj 2:30503be9a375 271 sBreakDeadTimeConfig.DeadTime = 0;
elijahsj 2:30503be9a375 272 sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
elijahsj 2:30503be9a375 273 sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
elijahsj 2:30503be9a375 274 sBreakDeadTimeConfig.BreakFilter = 0;
elijahsj 2:30503be9a375 275 sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
elijahsj 2:30503be9a375 276 if (HAL_TIMEx_ConfigBreakDeadTime(&htim17, &sBreakDeadTimeConfig) != HAL_OK)
elijahsj 2:30503be9a375 277 {
elijahsj 2:30503be9a375 278 //Error_Handler();
elijahsj 2:30503be9a375 279 }
elijahsj 2:30503be9a375 280 HAL_TIM_MspPostInit(&htim17);
elijahsj 2:30503be9a375 281
elijahsj 1:4c3c2b7337a6 282 }
elijahsj 1:4c3c2b7337a6 283
elijahsj 1:4c3c2b7337a6 284 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
elijahsj 1:4c3c2b7337a6 285 {
elijahsj 2:30503be9a375 286 /* GPIO Ports Clock Enable */
elijahsj 1:4c3c2b7337a6 287 __HAL_RCC_GPIOE_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 288 __HAL_RCC_GPIOC_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 289 __HAL_RCC_GPIOF_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 290 __HAL_RCC_GPIOH_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 291 __HAL_RCC_GPIOA_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 292 __HAL_RCC_GPIOB_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 293 __HAL_RCC_GPIOD_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 294 __HAL_RCC_GPIOG_CLK_ENABLE();
elijahsj 1:4c3c2b7337a6 295
elijahsj 1:4c3c2b7337a6 296 GPIO_InitTypeDef GPIO_InitStruct = {0};
elijahsj 1:4c3c2b7337a6 297 if(htim->Instance==TIM12)
elijahsj 1:4c3c2b7337a6 298 {
elijahsj 1:4c3c2b7337a6 299
elijahsj 1:4c3c2b7337a6 300 /**TIM12 GPIO Configuration
elijahsj 1:4c3c2b7337a6 301 PB14 ------> TIM12_CH1
elijahsj 1:4c3c2b7337a6 302 PB15 ------> TIM12_CH2
elijahsj 1:4c3c2b7337a6 303 */
elijahsj 1:4c3c2b7337a6 304 GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
elijahsj 1:4c3c2b7337a6 305 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 306 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 307 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 308 GPIO_InitStruct.Alternate = GPIO_AF2_TIM12;
elijahsj 1:4c3c2b7337a6 309 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 310 }
elijahsj 1:4c3c2b7337a6 311 else if(htim->Instance==TIM13)
elijahsj 1:4c3c2b7337a6 312 {
elijahsj 1:4c3c2b7337a6 313 /**TIM13 GPIO Configuration
elijahsj 1:4c3c2b7337a6 314 PA6 ------> TIM13_CH1
elijahsj 1:4c3c2b7337a6 315 */
elijahsj 1:4c3c2b7337a6 316 GPIO_InitStruct.Pin = GPIO_PIN_6;
elijahsj 1:4c3c2b7337a6 317 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 318 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 319 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 320 GPIO_InitStruct.Alternate = GPIO_AF9_TIM13;
elijahsj 1:4c3c2b7337a6 321 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 322 }
elijahsj 1:4c3c2b7337a6 323 else if(htim->Instance==TIM14)
elijahsj 1:4c3c2b7337a6 324 {
elijahsj 1:4c3c2b7337a6 325 /**TIM14 GPIO Configuration
elijahsj 1:4c3c2b7337a6 326 PF9 ------> TIM14_CH1
elijahsj 1:4c3c2b7337a6 327 */
elijahsj 1:4c3c2b7337a6 328 GPIO_InitStruct.Pin = GPIO_PIN_9;
elijahsj 1:4c3c2b7337a6 329 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 330 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 331 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 332 GPIO_InitStruct.Alternate = GPIO_AF9_TIM14;
elijahsj 1:4c3c2b7337a6 333 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 334 }
elijahsj 1:4c3c2b7337a6 335 else if(htim->Instance==TIM15)
elijahsj 1:4c3c2b7337a6 336 {
elijahsj 1:4c3c2b7337a6 337 /**TIM15 GPIO Configuration
elijahsj 1:4c3c2b7337a6 338 PE5 ------> TIM15_CH1
elijahsj 1:4c3c2b7337a6 339 PE6 ------> TIM15_CH2
elijahsj 1:4c3c2b7337a6 340 */
elijahsj 1:4c3c2b7337a6 341 GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
elijahsj 1:4c3c2b7337a6 342 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 343 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 344 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 345 GPIO_InitStruct.Alternate = GPIO_AF4_TIM15;
elijahsj 1:4c3c2b7337a6 346 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 347 }
elijahsj 1:4c3c2b7337a6 348 else if(htim->Instance==TIM16)
elijahsj 1:4c3c2b7337a6 349 {
elijahsj 1:4c3c2b7337a6 350 /**TIM16 GPIO Configuration
elijahsj 1:4c3c2b7337a6 351 PF6 ------> TIM16_CH1
elijahsj 1:4c3c2b7337a6 352 */
elijahsj 1:4c3c2b7337a6 353 GPIO_InitStruct.Pin = GPIO_PIN_6;
elijahsj 1:4c3c2b7337a6 354 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 355 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 356 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 357 GPIO_InitStruct.Alternate = GPIO_AF1_TIM16;
elijahsj 1:4c3c2b7337a6 358 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 359 }
elijahsj 1:4c3c2b7337a6 360 else if(htim->Instance==TIM17)
elijahsj 1:4c3c2b7337a6 361 {
elijahsj 1:4c3c2b7337a6 362 /**TIM17 GPIO Configuration
elijahsj 1:4c3c2b7337a6 363 PF7 ------> TIM17_CH1
elijahsj 1:4c3c2b7337a6 364 */
elijahsj 1:4c3c2b7337a6 365 GPIO_InitStruct.Pin = GPIO_PIN_7;
elijahsj 1:4c3c2b7337a6 366 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
elijahsj 1:4c3c2b7337a6 367 GPIO_InitStruct.Pull = GPIO_NOPULL;
elijahsj 1:4c3c2b7337a6 368 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
elijahsj 1:4c3c2b7337a6 369 GPIO_InitStruct.Alternate = GPIO_AF1_TIM17;
elijahsj 1:4c3c2b7337a6 370 HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
elijahsj 1:4c3c2b7337a6 371 }
elijahsj 1:4c3c2b7337a6 372
elijahsj 1:4c3c2b7337a6 373 }
elijahsj 1:4c3c2b7337a6 374
elijahsj 1:4c3c2b7337a6 375 void SystemClock_Config(void)
elijahsj 1:4c3c2b7337a6 376 {
elijahsj 1:4c3c2b7337a6 377 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
elijahsj 1:4c3c2b7337a6 378 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
elijahsj 1:4c3c2b7337a6 379 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
elijahsj 1:4c3c2b7337a6 380
elijahsj 1:4c3c2b7337a6 381 /** Supply configuration update enable
elijahsj 1:4c3c2b7337a6 382 */
elijahsj 1:4c3c2b7337a6 383 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
elijahsj 1:4c3c2b7337a6 384 /** Configure the main internal regulator output voltage
elijahsj 1:4c3c2b7337a6 385 */
elijahsj 1:4c3c2b7337a6 386 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
elijahsj 1:4c3c2b7337a6 387
elijahsj 1:4c3c2b7337a6 388 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
elijahsj 1:4c3c2b7337a6 389 /** Macro to configure the PLL clock source
elijahsj 1:4c3c2b7337a6 390 */
elijahsj 1:4c3c2b7337a6 391 __HAL_RCC_PLL_PLLSOURCE_CONFIG(RCC_PLLSOURCE_HSI);
elijahsj 1:4c3c2b7337a6 392 /** Initializes the CPU, AHB and APB busses clocks
elijahsj 1:4c3c2b7337a6 393 */
elijahsj 1:4c3c2b7337a6 394 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
elijahsj 1:4c3c2b7337a6 395 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
elijahsj 1:4c3c2b7337a6 396 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
elijahsj 1:4c3c2b7337a6 397 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
elijahsj 1:4c3c2b7337a6 398 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
elijahsj 1:4c3c2b7337a6 399 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
elijahsj 1:4c3c2b7337a6 400 {
elijahsj 1:4c3c2b7337a6 401 //Error_Handler();
elijahsj 1:4c3c2b7337a6 402 }
elijahsj 1:4c3c2b7337a6 403 /** Initializes the CPU, AHB and APB busses clocks
elijahsj 1:4c3c2b7337a6 404 */
elijahsj 1:4c3c2b7337a6 405 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
elijahsj 1:4c3c2b7337a6 406 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
elijahsj 1:4c3c2b7337a6 407 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
elijahsj 1:4c3c2b7337a6 408 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
elijahsj 1:4c3c2b7337a6 409 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
elijahsj 1:4c3c2b7337a6 410 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
elijahsj 1:4c3c2b7337a6 411 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
elijahsj 1:4c3c2b7337a6 412 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
elijahsj 1:4c3c2b7337a6 413 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
elijahsj 1:4c3c2b7337a6 414 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
elijahsj 1:4c3c2b7337a6 415
elijahsj 1:4c3c2b7337a6 416 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
elijahsj 1:4c3c2b7337a6 417 {
elijahsj 1:4c3c2b7337a6 418 //Error_Handler();
elijahsj 1:4c3c2b7337a6 419 }
elijahsj 1:4c3c2b7337a6 420
elijahsj 1:4c3c2b7337a6 421 }
elijahsj 1:4c3c2b7337a6 422
elijahsj 1:4c3c2b7337a6 423
elijahsj 1:4c3c2b7337a6 424
elijahsj 1:4c3c2b7337a6 425