Updated for the next revision of the motor board

Committer:
elijahsj
Date:
Wed Aug 26 02:43:57 2020 +0000
Revision:
3:2f46953e7c8b
Parent:
2:30503be9a375
Child:
5:d2dffc88e94d
finished shield code;

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