Updated for the next revision of the motor board
HardwareSetup.cpp@6:417655779dc5, 2020-08-26 (annotated)
- Committer:
- elijahsj
- Date:
- Wed Aug 26 19:35:02 2020 +0000
- Revision:
- 6:417655779dc5
- Parent:
- 5:d2dffc88e94d
- Child:
- 7:e3a2ade56b79
Working but ADCs need DMA to run high speed loops
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:417655779dc5 | 11 | ADC_HandleTypeDef hadc1; |
elijahsj | 6:417655779dc5 | 12 | ADC_HandleTypeDef hadc2; |
elijahsj | 1:4c3c2b7337a6 | 13 | |
elijahsj | 3:2f46953e7c8b | 14 | int PWM_PERIOD; |
elijahsj | 1:4c3c2b7337a6 | 15 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim); |
elijahsj | 1:4c3c2b7337a6 | 16 | static void MX_TIM12_Init(void); |
elijahsj | 2:30503be9a375 | 17 | static void MX_TIM13_Init(void); |
elijahsj | 2:30503be9a375 | 18 | static void MX_TIM14_Init(void); |
elijahsj | 2:30503be9a375 | 19 | static void MX_TIM15_Init(void); |
elijahsj | 2:30503be9a375 | 20 | static void MX_TIM16_Init(void); |
elijahsj | 2:30503be9a375 | 21 | static void MX_TIM17_Init(void); |
elijahsj | 6:417655779dc5 | 22 | static void MX_ADC1_Init(void); |
elijahsj | 6:417655779dc5 | 23 | static void MX_ADC2_Init(void); |
elijahsj | 6:417655779dc5 | 24 | |
elijahsj | 6:417655779dc5 | 25 | uint16_t Current_A; |
elijahsj | 6:417655779dc5 | 26 | uint16_t Current_B; |
elijahsj | 6:417655779dc5 | 27 | uint16_t Current_C; |
elijahsj | 6:417655779dc5 | 28 | uint16_t Current_D; |
elijahsj | 6:417655779dc5 | 29 | |
elijahsj | 6:417655779dc5 | 30 | AnalogIn currentA(PF_12); //Enable ADC pin |
elijahsj | 6:417655779dc5 | 31 | AnalogIn currentB(PF_11); //Enable ADC pin |
elijahsj | 6:417655779dc5 | 32 | AnalogIn currentC(PF_13); //Enable ADC pin |
elijahsj | 6:417655779dc5 | 33 | AnalogIn currentD(PA_4); //Enable ADC pin |
elijahsj | 1:4c3c2b7337a6 | 34 | |
elijahsj | 3:2f46953e7c8b | 35 | void initHardware(int periodTicks){ |
elijahsj | 3:2f46953e7c8b | 36 | PWM_PERIOD = periodTicks; |
elijahsj | 1:4c3c2b7337a6 | 37 | /* Initialise the HAL Layer */ |
elijahsj | 1:4c3c2b7337a6 | 38 | HAL_Init(); |
elijahsj | 1:4c3c2b7337a6 | 39 | |
elijahsj | 1:4c3c2b7337a6 | 40 | /* Initialize all configured peripherals */ |
elijahsj | 1:4c3c2b7337a6 | 41 | MX_TIM12_Init(); |
elijahsj | 2:30503be9a375 | 42 | MX_TIM13_Init(); |
elijahsj | 2:30503be9a375 | 43 | MX_TIM14_Init(); |
elijahsj | 2:30503be9a375 | 44 | MX_TIM15_Init(); |
elijahsj | 2:30503be9a375 | 45 | MX_TIM16_Init(); |
elijahsj | 2:30503be9a375 | 46 | MX_TIM17_Init(); |
elijahsj | 6:417655779dc5 | 47 | MX_ADC1_Init(); |
elijahsj | 6:417655779dc5 | 48 | MX_ADC2_Init(); |
elijahsj | 2:30503be9a375 | 49 | //HAL_TIM_Base_Start(&htim15); |
elijahsj | 2:30503be9a375 | 50 | |
elijahsj | 1:4c3c2b7337a6 | 51 | HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 1:4c3c2b7337a6 | 52 | HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_2); // start pwm generation |
elijahsj | 2:30503be9a375 | 53 | HAL_TIM_PWM_Start(&htim13, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 2:30503be9a375 | 54 | HAL_TIM_PWM_Start(&htim14, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 2:30503be9a375 | 55 | HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 2:30503be9a375 | 56 | HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2); // start pwm generation |
elijahsj | 2:30503be9a375 | 57 | HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 2:30503be9a375 | 58 | HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1); // start pwm generation |
elijahsj | 2:30503be9a375 | 59 | |
elijahsj | 1:4c3c2b7337a6 | 60 | } |
elijahsj | 1:4c3c2b7337a6 | 61 | |
elijahsj | 6:417655779dc5 | 62 | |
elijahsj | 6:417655779dc5 | 63 | |
elijahsj | 6:417655779dc5 | 64 | uint16_t readADC1(int channel){ |
elijahsj | 6:417655779dc5 | 65 | |
elijahsj | 6:417655779dc5 | 66 | HAL_ADC_Start(&hadc1); |
elijahsj | 6:417655779dc5 | 67 | HAL_ADC_PollForConversion(&hadc1,20); |
elijahsj | 6:417655779dc5 | 68 | Current_A = HAL_ADC_GetValue(&hadc1); |
elijahsj | 6:417655779dc5 | 69 | HAL_ADC_PollForConversion(&hadc1,20); |
elijahsj | 6:417655779dc5 | 70 | Current_B = HAL_ADC_GetValue(&hadc1); |
elijahsj | 6:417655779dc5 | 71 | HAL_ADC_Stop (&hadc1); |
elijahsj | 6:417655779dc5 | 72 | if (channel){ |
elijahsj | 6:417655779dc5 | 73 | |
elijahsj | 6:417655779dc5 | 74 | return Current_A; |
elijahsj | 6:417655779dc5 | 75 | } |
elijahsj | 6:417655779dc5 | 76 | else |
elijahsj | 6:417655779dc5 | 77 | return Current_B; |
elijahsj | 6:417655779dc5 | 78 | } |
elijahsj | 6:417655779dc5 | 79 | |
elijahsj | 6:417655779dc5 | 80 | uint16_t readADC2(int channel){ |
elijahsj | 6:417655779dc5 | 81 | |
elijahsj | 6:417655779dc5 | 82 | HAL_ADC_Start(&hadc2); |
elijahsj | 6:417655779dc5 | 83 | HAL_ADC_PollForConversion(&hadc2,20); |
elijahsj | 6:417655779dc5 | 84 | Current_C = HAL_ADC_GetValue(&hadc2); |
elijahsj | 6:417655779dc5 | 85 | HAL_ADC_PollForConversion(&hadc2,20); |
elijahsj | 6:417655779dc5 | 86 | Current_D = HAL_ADC_GetValue(&hadc2); |
elijahsj | 6:417655779dc5 | 87 | HAL_ADC_Stop (&hadc2); |
elijahsj | 6:417655779dc5 | 88 | if (channel){ |
elijahsj | 6:417655779dc5 | 89 | |
elijahsj | 6:417655779dc5 | 90 | return Current_C; |
elijahsj | 6:417655779dc5 | 91 | } |
elijahsj | 6:417655779dc5 | 92 | else |
elijahsj | 6:417655779dc5 | 93 | return Current_D; |
elijahsj | 6:417655779dc5 | 94 | } |
elijahsj | 6:417655779dc5 | 95 | |
elijahsj | 6:417655779dc5 | 96 | |
elijahsj | 6:417655779dc5 | 97 | static void MX_ADC1_Init(void) |
elijahsj | 6:417655779dc5 | 98 | { |
elijahsj | 6:417655779dc5 | 99 | ADC_MultiModeTypeDef multimode = {0}; |
elijahsj | 6:417655779dc5 | 100 | ADC_ChannelConfTypeDef sConfig = {0}; |
elijahsj | 6:417655779dc5 | 101 | /** Common config |
elijahsj | 6:417655779dc5 | 102 | */ |
elijahsj | 6:417655779dc5 | 103 | hadc1.Instance = ADC1; |
elijahsj | 6:417655779dc5 | 104 | hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
elijahsj | 6:417655779dc5 | 105 | hadc1.Init.Resolution = ADC_RESOLUTION_16B; |
elijahsj | 6:417655779dc5 | 106 | hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; |
elijahsj | 6:417655779dc5 | 107 | hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; |
elijahsj | 6:417655779dc5 | 108 | hadc1.Init.LowPowerAutoWait = DISABLE; |
elijahsj | 6:417655779dc5 | 109 | hadc1.Init.ContinuousConvMode = ENABLE; |
elijahsj | 6:417655779dc5 | 110 | hadc1.Init.NbrOfConversion = 2; |
elijahsj | 6:417655779dc5 | 111 | hadc1.Init.DiscontinuousConvMode = DISABLE; |
elijahsj | 6:417655779dc5 | 112 | hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
elijahsj | 6:417655779dc5 | 113 | hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; |
elijahsj | 6:417655779dc5 | 114 | hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; |
elijahsj | 6:417655779dc5 | 115 | hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED; |
elijahsj | 6:417655779dc5 | 116 | hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; |
elijahsj | 6:417655779dc5 | 117 | hadc1.Init.OversamplingMode = DISABLE; |
elijahsj | 6:417655779dc5 | 118 | if (HAL_ADC_Init(&hadc1) != HAL_OK) |
elijahsj | 6:417655779dc5 | 119 | { |
elijahsj | 6:417655779dc5 | 120 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 121 | } |
elijahsj | 6:417655779dc5 | 122 | /** Configure the ADC multi-mode |
elijahsj | 6:417655779dc5 | 123 | */ |
elijahsj | 6:417655779dc5 | 124 | multimode.Mode = ADC_MODE_INDEPENDENT; |
elijahsj | 6:417655779dc5 | 125 | if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) |
elijahsj | 6:417655779dc5 | 126 | { |
elijahsj | 6:417655779dc5 | 127 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 128 | } |
elijahsj | 6:417655779dc5 | 129 | /** Configure Regular Channel |
elijahsj | 6:417655779dc5 | 130 | */ |
elijahsj | 6:417655779dc5 | 131 | sConfig.Channel = ADC_CHANNEL_2; |
elijahsj | 6:417655779dc5 | 132 | sConfig.Rank = ADC_REGULAR_RANK_1; |
elijahsj | 6:417655779dc5 | 133 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
elijahsj | 6:417655779dc5 | 134 | sConfig.SingleDiff = ADC_SINGLE_ENDED; |
elijahsj | 6:417655779dc5 | 135 | sConfig.OffsetNumber = ADC_OFFSET_NONE; |
elijahsj | 6:417655779dc5 | 136 | sConfig.Offset = 0; |
elijahsj | 6:417655779dc5 | 137 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
elijahsj | 6:417655779dc5 | 138 | { |
elijahsj | 6:417655779dc5 | 139 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 140 | } |
elijahsj | 6:417655779dc5 | 141 | |
elijahsj | 6:417655779dc5 | 142 | sConfig.Channel = ADC_CHANNEL_6; |
elijahsj | 6:417655779dc5 | 143 | sConfig.Rank = ADC_REGULAR_RANK_2; |
elijahsj | 6:417655779dc5 | 144 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
elijahsj | 6:417655779dc5 | 145 | sConfig.SingleDiff = ADC_SINGLE_ENDED; |
elijahsj | 6:417655779dc5 | 146 | sConfig.OffsetNumber = ADC_OFFSET_NONE; |
elijahsj | 6:417655779dc5 | 147 | sConfig.Offset = 0; |
elijahsj | 6:417655779dc5 | 148 | if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) |
elijahsj | 6:417655779dc5 | 149 | { |
elijahsj | 6:417655779dc5 | 150 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 151 | } |
elijahsj | 6:417655779dc5 | 152 | } |
elijahsj | 6:417655779dc5 | 153 | |
elijahsj | 6:417655779dc5 | 154 | /** |
elijahsj | 6:417655779dc5 | 155 | * @brief ADC2 Initialization Function |
elijahsj | 6:417655779dc5 | 156 | * @param None |
elijahsj | 6:417655779dc5 | 157 | * @retval None |
elijahsj | 6:417655779dc5 | 158 | */ |
elijahsj | 6:417655779dc5 | 159 | static void MX_ADC2_Init(void) |
elijahsj | 6:417655779dc5 | 160 | { |
elijahsj | 6:417655779dc5 | 161 | ADC_MultiModeTypeDef multimode = {0}; |
elijahsj | 6:417655779dc5 | 162 | ADC_ChannelConfTypeDef sConfig = {0}; |
elijahsj | 6:417655779dc5 | 163 | /** Common config |
elijahsj | 6:417655779dc5 | 164 | */ |
elijahsj | 6:417655779dc5 | 165 | hadc2.Instance = ADC2; |
elijahsj | 6:417655779dc5 | 166 | hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
elijahsj | 6:417655779dc5 | 167 | hadc2.Init.Resolution = ADC_RESOLUTION_16B; |
elijahsj | 6:417655779dc5 | 168 | hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE; |
elijahsj | 6:417655779dc5 | 169 | hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV; |
elijahsj | 6:417655779dc5 | 170 | hadc2.Init.LowPowerAutoWait = DISABLE; |
elijahsj | 6:417655779dc5 | 171 | hadc2.Init.ContinuousConvMode = ENABLE; |
elijahsj | 6:417655779dc5 | 172 | hadc2.Init.NbrOfConversion = 2; |
elijahsj | 6:417655779dc5 | 173 | hadc2.Init.DiscontinuousConvMode = DISABLE; |
elijahsj | 6:417655779dc5 | 174 | hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
elijahsj | 6:417655779dc5 | 175 | hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; |
elijahsj | 6:417655779dc5 | 176 | hadc2.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR; |
elijahsj | 6:417655779dc5 | 177 | hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED; |
elijahsj | 6:417655779dc5 | 178 | hadc2.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE; |
elijahsj | 6:417655779dc5 | 179 | hadc2.Init.OversamplingMode = DISABLE; |
elijahsj | 6:417655779dc5 | 180 | if (HAL_ADC_Init(&hadc2) != HAL_OK) |
elijahsj | 6:417655779dc5 | 181 | { |
elijahsj | 6:417655779dc5 | 182 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 183 | } |
elijahsj | 6:417655779dc5 | 184 | /** Configure the ADC multi-mode |
elijahsj | 6:417655779dc5 | 185 | */ |
elijahsj | 6:417655779dc5 | 186 | multimode.Mode = ADC_MODE_INDEPENDENT; |
elijahsj | 6:417655779dc5 | 187 | if (HAL_ADCEx_MultiModeConfigChannel(&hadc2, &multimode) != HAL_OK) |
elijahsj | 6:417655779dc5 | 188 | { |
elijahsj | 6:417655779dc5 | 189 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 190 | } |
elijahsj | 6:417655779dc5 | 191 | /** Configure Regular Channel |
elijahsj | 6:417655779dc5 | 192 | */ |
elijahsj | 6:417655779dc5 | 193 | sConfig.Channel = ADC_CHANNEL_2; |
elijahsj | 6:417655779dc5 | 194 | sConfig.Rank = ADC_REGULAR_RANK_1; |
elijahsj | 6:417655779dc5 | 195 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
elijahsj | 6:417655779dc5 | 196 | sConfig.SingleDiff = ADC_SINGLE_ENDED; |
elijahsj | 6:417655779dc5 | 197 | sConfig.OffsetNumber = ADC_OFFSET_NONE; |
elijahsj | 6:417655779dc5 | 198 | sConfig.Offset = 0; |
elijahsj | 6:417655779dc5 | 199 | if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) |
elijahsj | 6:417655779dc5 | 200 | { |
elijahsj | 6:417655779dc5 | 201 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 202 | } |
elijahsj | 6:417655779dc5 | 203 | |
elijahsj | 6:417655779dc5 | 204 | sConfig.Channel = ADC_CHANNEL_18; |
elijahsj | 6:417655779dc5 | 205 | sConfig.Rank = ADC_REGULAR_RANK_2; |
elijahsj | 6:417655779dc5 | 206 | sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; |
elijahsj | 6:417655779dc5 | 207 | sConfig.SingleDiff = ADC_SINGLE_ENDED; |
elijahsj | 6:417655779dc5 | 208 | sConfig.OffsetNumber = ADC_OFFSET_NONE; |
elijahsj | 6:417655779dc5 | 209 | sConfig.Offset = 0; |
elijahsj | 6:417655779dc5 | 210 | if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK) |
elijahsj | 6:417655779dc5 | 211 | { |
elijahsj | 6:417655779dc5 | 212 | //Error_Handler(); |
elijahsj | 6:417655779dc5 | 213 | } |
elijahsj | 6:417655779dc5 | 214 | |
elijahsj | 6:417655779dc5 | 215 | } |
elijahsj | 6:417655779dc5 | 216 | |
elijahsj | 6:417655779dc5 | 217 | |
elijahsj | 1:4c3c2b7337a6 | 218 | static void MX_TIM12_Init(void) |
elijahsj | 1:4c3c2b7337a6 | 219 | { |
elijahsj | 1:4c3c2b7337a6 | 220 | __HAL_RCC_TIM12_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 221 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 1:4c3c2b7337a6 | 222 | htim12.Instance = TIM12; |
elijahsj | 1:4c3c2b7337a6 | 223 | htim12.Init.Prescaler = 0; |
elijahsj | 1:4c3c2b7337a6 | 224 | htim12.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 1:4c3c2b7337a6 | 225 | htim12.Init.Period = PWM_PERIOD; |
elijahsj | 1:4c3c2b7337a6 | 226 | htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 1:4c3c2b7337a6 | 227 | htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 1:4c3c2b7337a6 | 228 | if (HAL_TIM_PWM_Init(&htim12) != HAL_OK) |
elijahsj | 1:4c3c2b7337a6 | 229 | { |
elijahsj | 1:4c3c2b7337a6 | 230 | //Error_Handler(); |
elijahsj | 1:4c3c2b7337a6 | 231 | } |
elijahsj | 1:4c3c2b7337a6 | 232 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 1:4c3c2b7337a6 | 233 | sConfigOC.Pulse = 0; |
elijahsj | 1:4c3c2b7337a6 | 234 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 1:4c3c2b7337a6 | 235 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 1:4c3c2b7337a6 | 236 | if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 1:4c3c2b7337a6 | 237 | { |
elijahsj | 1:4c3c2b7337a6 | 238 | //Error_Handler(); |
elijahsj | 1:4c3c2b7337a6 | 239 | } |
elijahsj | 1:4c3c2b7337a6 | 240 | if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) |
elijahsj | 1:4c3c2b7337a6 | 241 | { |
elijahsj | 1:4c3c2b7337a6 | 242 | //Error_Handler(); |
elijahsj | 1:4c3c2b7337a6 | 243 | } |
elijahsj | 2:30503be9a375 | 244 | HAL_TIM_MspPostInit(&htim12); |
elijahsj | 2:30503be9a375 | 245 | } |
elijahsj | 2:30503be9a375 | 246 | |
elijahsj | 2:30503be9a375 | 247 | static void MX_TIM13_Init(void) |
elijahsj | 2:30503be9a375 | 248 | { |
elijahsj | 2:30503be9a375 | 249 | __HAL_RCC_TIM13_CLK_ENABLE(); |
elijahsj | 2:30503be9a375 | 250 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 2:30503be9a375 | 251 | htim13.Instance = TIM13; |
elijahsj | 2:30503be9a375 | 252 | htim13.Init.Prescaler = 0; |
elijahsj | 2:30503be9a375 | 253 | htim13.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 2:30503be9a375 | 254 | htim13.Init.Period = PWM_PERIOD; |
elijahsj | 2:30503be9a375 | 255 | htim13.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 2:30503be9a375 | 256 | htim13.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 2:30503be9a375 | 257 | if (HAL_TIM_Base_Init(&htim13) != HAL_OK) |
elijahsj | 2:30503be9a375 | 258 | { |
elijahsj | 2:30503be9a375 | 259 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 260 | } |
elijahsj | 2:30503be9a375 | 261 | if (HAL_TIM_PWM_Init(&htim13) != HAL_OK) |
elijahsj | 2:30503be9a375 | 262 | { |
elijahsj | 2:30503be9a375 | 263 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 264 | } |
elijahsj | 2:30503be9a375 | 265 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 2:30503be9a375 | 266 | sConfigOC.Pulse = 0; |
elijahsj | 2:30503be9a375 | 267 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 268 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 2:30503be9a375 | 269 | if (HAL_TIM_PWM_ConfigChannel(&htim13, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 2:30503be9a375 | 270 | { |
elijahsj | 2:30503be9a375 | 271 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 272 | } |
elijahsj | 2:30503be9a375 | 273 | HAL_TIM_MspPostInit(&htim13); |
elijahsj | 2:30503be9a375 | 274 | } |
elijahsj | 2:30503be9a375 | 275 | |
elijahsj | 2:30503be9a375 | 276 | static void MX_TIM14_Init(void) |
elijahsj | 2:30503be9a375 | 277 | { |
elijahsj | 2:30503be9a375 | 278 | __HAL_RCC_TIM14_CLK_ENABLE(); |
elijahsj | 2:30503be9a375 | 279 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 2:30503be9a375 | 280 | htim14.Instance = TIM14; |
elijahsj | 2:30503be9a375 | 281 | htim14.Init.Prescaler = 0; |
elijahsj | 2:30503be9a375 | 282 | htim14.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 2:30503be9a375 | 283 | htim14.Init.Period = PWM_PERIOD; |
elijahsj | 2:30503be9a375 | 284 | htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 2:30503be9a375 | 285 | htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 2:30503be9a375 | 286 | if (HAL_TIM_Base_Init(&htim14) != HAL_OK) |
elijahsj | 2:30503be9a375 | 287 | { |
elijahsj | 2:30503be9a375 | 288 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 289 | } |
elijahsj | 2:30503be9a375 | 290 | if (HAL_TIM_PWM_Init(&htim14) != HAL_OK) |
elijahsj | 2:30503be9a375 | 291 | { |
elijahsj | 2:30503be9a375 | 292 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 293 | } |
elijahsj | 2:30503be9a375 | 294 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 2:30503be9a375 | 295 | sConfigOC.Pulse = 0; |
elijahsj | 2:30503be9a375 | 296 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 297 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 2:30503be9a375 | 298 | if (HAL_TIM_PWM_ConfigChannel(&htim14, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 2:30503be9a375 | 299 | { |
elijahsj | 2:30503be9a375 | 300 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 301 | } |
elijahsj | 2:30503be9a375 | 302 | HAL_TIM_MspPostInit(&htim14); |
elijahsj | 2:30503be9a375 | 303 | } |
elijahsj | 1:4c3c2b7337a6 | 304 | |
elijahsj | 2:30503be9a375 | 305 | static void MX_TIM15_Init(void) |
elijahsj | 2:30503be9a375 | 306 | { |
elijahsj | 2:30503be9a375 | 307 | __HAL_RCC_TIM15_CLK_ENABLE(); |
elijahsj | 2:30503be9a375 | 308 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
elijahsj | 2:30503be9a375 | 309 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 2:30503be9a375 | 310 | TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; |
elijahsj | 2:30503be9a375 | 311 | htim15.Instance = TIM15; |
elijahsj | 2:30503be9a375 | 312 | htim15.Init.Prescaler = 0; |
elijahsj | 2:30503be9a375 | 313 | htim15.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 2:30503be9a375 | 314 | htim15.Init.Period = PWM_PERIOD; |
elijahsj | 2:30503be9a375 | 315 | htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 2:30503be9a375 | 316 | htim15.Init.RepetitionCounter = 0; |
elijahsj | 2:30503be9a375 | 317 | htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 2:30503be9a375 | 318 | if (HAL_TIM_PWM_Init(&htim15) != HAL_OK) |
elijahsj | 2:30503be9a375 | 319 | { |
elijahsj | 2:30503be9a375 | 320 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 321 | } |
elijahsj | 2:30503be9a375 | 322 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
elijahsj | 2:30503be9a375 | 323 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
elijahsj | 2:30503be9a375 | 324 | if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK) |
elijahsj | 2:30503be9a375 | 325 | { |
elijahsj | 2:30503be9a375 | 326 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 327 | } |
elijahsj | 2:30503be9a375 | 328 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 2:30503be9a375 | 329 | sConfigOC.Pulse = 0; |
elijahsj | 2:30503be9a375 | 330 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 331 | sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 332 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 2:30503be9a375 | 333 | sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 334 | sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 335 | if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 2:30503be9a375 | 336 | { |
elijahsj | 2:30503be9a375 | 337 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 338 | } |
elijahsj | 2:30503be9a375 | 339 | if (HAL_TIM_PWM_ConfigChannel(&htim15, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) |
elijahsj | 2:30503be9a375 | 340 | { |
elijahsj | 2:30503be9a375 | 341 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 342 | } |
elijahsj | 2:30503be9a375 | 343 | sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; |
elijahsj | 2:30503be9a375 | 344 | sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; |
elijahsj | 2:30503be9a375 | 345 | sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; |
elijahsj | 2:30503be9a375 | 346 | sBreakDeadTimeConfig.DeadTime = 0; |
elijahsj | 2:30503be9a375 | 347 | sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; |
elijahsj | 2:30503be9a375 | 348 | sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 349 | sBreakDeadTimeConfig.BreakFilter = 0; |
elijahsj | 2:30503be9a375 | 350 | sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; |
elijahsj | 2:30503be9a375 | 351 | if (HAL_TIMEx_ConfigBreakDeadTime(&htim15, &sBreakDeadTimeConfig) != HAL_OK) |
elijahsj | 2:30503be9a375 | 352 | { |
elijahsj | 2:30503be9a375 | 353 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 354 | } |
elijahsj | 2:30503be9a375 | 355 | HAL_TIM_MspPostInit(&htim15); |
elijahsj | 2:30503be9a375 | 356 | |
elijahsj | 2:30503be9a375 | 357 | } |
elijahsj | 2:30503be9a375 | 358 | |
elijahsj | 2:30503be9a375 | 359 | static void MX_TIM16_Init(void) |
elijahsj | 2:30503be9a375 | 360 | { |
elijahsj | 2:30503be9a375 | 361 | __HAL_RCC_TIM16_CLK_ENABLE(); |
elijahsj | 2:30503be9a375 | 362 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 2:30503be9a375 | 363 | TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; |
elijahsj | 2:30503be9a375 | 364 | htim16.Instance = TIM16; |
elijahsj | 2:30503be9a375 | 365 | htim16.Init.Prescaler = 0; |
elijahsj | 2:30503be9a375 | 366 | htim16.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 2:30503be9a375 | 367 | htim16.Init.Period = PWM_PERIOD; |
elijahsj | 2:30503be9a375 | 368 | htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 2:30503be9a375 | 369 | htim16.Init.RepetitionCounter = 0; |
elijahsj | 2:30503be9a375 | 370 | htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 2:30503be9a375 | 371 | if (HAL_TIM_Base_Init(&htim16) != HAL_OK) |
elijahsj | 2:30503be9a375 | 372 | { |
elijahsj | 2:30503be9a375 | 373 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 374 | } |
elijahsj | 2:30503be9a375 | 375 | if (HAL_TIM_PWM_Init(&htim16) != HAL_OK) |
elijahsj | 2:30503be9a375 | 376 | { |
elijahsj | 2:30503be9a375 | 377 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 378 | } |
elijahsj | 2:30503be9a375 | 379 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 2:30503be9a375 | 380 | sConfigOC.Pulse = 0; |
elijahsj | 2:30503be9a375 | 381 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 382 | sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 383 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 2:30503be9a375 | 384 | sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 385 | sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 386 | if (HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 2:30503be9a375 | 387 | { |
elijahsj | 2:30503be9a375 | 388 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 389 | } |
elijahsj | 2:30503be9a375 | 390 | sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; |
elijahsj | 2:30503be9a375 | 391 | sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; |
elijahsj | 2:30503be9a375 | 392 | sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; |
elijahsj | 2:30503be9a375 | 393 | sBreakDeadTimeConfig.DeadTime = 0; |
elijahsj | 2:30503be9a375 | 394 | sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; |
elijahsj | 2:30503be9a375 | 395 | sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 396 | sBreakDeadTimeConfig.BreakFilter = 0; |
elijahsj | 2:30503be9a375 | 397 | sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; |
elijahsj | 2:30503be9a375 | 398 | if (HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK) |
elijahsj | 2:30503be9a375 | 399 | { |
elijahsj | 2:30503be9a375 | 400 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 401 | } |
elijahsj | 2:30503be9a375 | 402 | HAL_TIM_MspPostInit(&htim16); |
elijahsj | 2:30503be9a375 | 403 | |
elijahsj | 2:30503be9a375 | 404 | } |
elijahsj | 2:30503be9a375 | 405 | |
elijahsj | 2:30503be9a375 | 406 | static void MX_TIM17_Init(void) |
elijahsj | 2:30503be9a375 | 407 | { |
elijahsj | 2:30503be9a375 | 408 | __HAL_RCC_TIM17_CLK_ENABLE(); |
elijahsj | 2:30503be9a375 | 409 | TIM_OC_InitTypeDef sConfigOC = {0}; |
elijahsj | 2:30503be9a375 | 410 | TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; |
elijahsj | 2:30503be9a375 | 411 | htim17.Instance = TIM17; |
elijahsj | 2:30503be9a375 | 412 | htim17.Init.Prescaler = 0; |
elijahsj | 2:30503be9a375 | 413 | htim17.Init.CounterMode = TIM_COUNTERMODE_UP; |
elijahsj | 2:30503be9a375 | 414 | htim17.Init.Period = PWM_PERIOD; |
elijahsj | 2:30503be9a375 | 415 | htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
elijahsj | 2:30503be9a375 | 416 | htim17.Init.RepetitionCounter = 0; |
elijahsj | 2:30503be9a375 | 417 | htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
elijahsj | 2:30503be9a375 | 418 | if (HAL_TIM_Base_Init(&htim17) != HAL_OK) |
elijahsj | 2:30503be9a375 | 419 | { |
elijahsj | 2:30503be9a375 | 420 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 421 | } |
elijahsj | 2:30503be9a375 | 422 | if (HAL_TIM_PWM_Init(&htim17) != HAL_OK) |
elijahsj | 2:30503be9a375 | 423 | { |
elijahsj | 2:30503be9a375 | 424 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 425 | } |
elijahsj | 2:30503be9a375 | 426 | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
elijahsj | 2:30503be9a375 | 427 | sConfigOC.Pulse = 0; |
elijahsj | 2:30503be9a375 | 428 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 429 | sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 430 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
elijahsj | 2:30503be9a375 | 431 | sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 432 | sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; |
elijahsj | 2:30503be9a375 | 433 | if (HAL_TIM_PWM_ConfigChannel(&htim17, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
elijahsj | 2:30503be9a375 | 434 | { |
elijahsj | 2:30503be9a375 | 435 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 436 | } |
elijahsj | 2:30503be9a375 | 437 | sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; |
elijahsj | 2:30503be9a375 | 438 | sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; |
elijahsj | 2:30503be9a375 | 439 | sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; |
elijahsj | 2:30503be9a375 | 440 | sBreakDeadTimeConfig.DeadTime = 0; |
elijahsj | 2:30503be9a375 | 441 | sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; |
elijahsj | 2:30503be9a375 | 442 | sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; |
elijahsj | 2:30503be9a375 | 443 | sBreakDeadTimeConfig.BreakFilter = 0; |
elijahsj | 2:30503be9a375 | 444 | sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; |
elijahsj | 2:30503be9a375 | 445 | if (HAL_TIMEx_ConfigBreakDeadTime(&htim17, &sBreakDeadTimeConfig) != HAL_OK) |
elijahsj | 2:30503be9a375 | 446 | { |
elijahsj | 2:30503be9a375 | 447 | //Error_Handler(); |
elijahsj | 2:30503be9a375 | 448 | } |
elijahsj | 2:30503be9a375 | 449 | HAL_TIM_MspPostInit(&htim17); |
elijahsj | 2:30503be9a375 | 450 | |
elijahsj | 1:4c3c2b7337a6 | 451 | } |
elijahsj | 1:4c3c2b7337a6 | 452 | |
elijahsj | 1:4c3c2b7337a6 | 453 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) |
elijahsj | 1:4c3c2b7337a6 | 454 | { |
elijahsj | 2:30503be9a375 | 455 | /* GPIO Ports Clock Enable */ |
elijahsj | 1:4c3c2b7337a6 | 456 | __HAL_RCC_GPIOE_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 457 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 458 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 459 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 460 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 461 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 462 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 463 | __HAL_RCC_GPIOG_CLK_ENABLE(); |
elijahsj | 1:4c3c2b7337a6 | 464 | |
elijahsj | 1:4c3c2b7337a6 | 465 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
elijahsj | 1:4c3c2b7337a6 | 466 | if(htim->Instance==TIM12) |
elijahsj | 1:4c3c2b7337a6 | 467 | { |
elijahsj | 1:4c3c2b7337a6 | 468 | |
elijahsj | 1:4c3c2b7337a6 | 469 | /**TIM12 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 470 | PB14 ------> TIM12_CH1 |
elijahsj | 1:4c3c2b7337a6 | 471 | PB15 ------> TIM12_CH2 |
elijahsj | 1:4c3c2b7337a6 | 472 | */ |
elijahsj | 1:4c3c2b7337a6 | 473 | GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15; |
elijahsj | 1:4c3c2b7337a6 | 474 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 475 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 476 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 477 | GPIO_InitStruct.Alternate = GPIO_AF2_TIM12; |
elijahsj | 1:4c3c2b7337a6 | 478 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 479 | } |
elijahsj | 1:4c3c2b7337a6 | 480 | else if(htim->Instance==TIM13) |
elijahsj | 1:4c3c2b7337a6 | 481 | { |
elijahsj | 1:4c3c2b7337a6 | 482 | /**TIM13 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 483 | PA6 ------> TIM13_CH1 |
elijahsj | 1:4c3c2b7337a6 | 484 | */ |
elijahsj | 1:4c3c2b7337a6 | 485 | GPIO_InitStruct.Pin = GPIO_PIN_6; |
elijahsj | 1:4c3c2b7337a6 | 486 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 487 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 488 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 489 | GPIO_InitStruct.Alternate = GPIO_AF9_TIM13; |
elijahsj | 1:4c3c2b7337a6 | 490 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 491 | } |
elijahsj | 1:4c3c2b7337a6 | 492 | else if(htim->Instance==TIM14) |
elijahsj | 1:4c3c2b7337a6 | 493 | { |
elijahsj | 1:4c3c2b7337a6 | 494 | /**TIM14 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 495 | PF9 ------> TIM14_CH1 |
elijahsj | 1:4c3c2b7337a6 | 496 | */ |
elijahsj | 1:4c3c2b7337a6 | 497 | GPIO_InitStruct.Pin = GPIO_PIN_9; |
elijahsj | 1:4c3c2b7337a6 | 498 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 499 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 500 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 501 | GPIO_InitStruct.Alternate = GPIO_AF9_TIM14; |
elijahsj | 1:4c3c2b7337a6 | 502 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 503 | } |
elijahsj | 1:4c3c2b7337a6 | 504 | else if(htim->Instance==TIM15) |
elijahsj | 1:4c3c2b7337a6 | 505 | { |
elijahsj | 1:4c3c2b7337a6 | 506 | /**TIM15 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 507 | PE5 ------> TIM15_CH1 |
elijahsj | 1:4c3c2b7337a6 | 508 | PE6 ------> TIM15_CH2 |
elijahsj | 1:4c3c2b7337a6 | 509 | */ |
elijahsj | 1:4c3c2b7337a6 | 510 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6; |
elijahsj | 1:4c3c2b7337a6 | 511 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 512 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 513 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 514 | GPIO_InitStruct.Alternate = GPIO_AF4_TIM15; |
elijahsj | 1:4c3c2b7337a6 | 515 | HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 516 | } |
elijahsj | 1:4c3c2b7337a6 | 517 | else if(htim->Instance==TIM16) |
elijahsj | 1:4c3c2b7337a6 | 518 | { |
elijahsj | 1:4c3c2b7337a6 | 519 | /**TIM16 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 520 | PF6 ------> TIM16_CH1 |
elijahsj | 1:4c3c2b7337a6 | 521 | */ |
elijahsj | 1:4c3c2b7337a6 | 522 | GPIO_InitStruct.Pin = GPIO_PIN_6; |
elijahsj | 1:4c3c2b7337a6 | 523 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 524 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 525 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 526 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM16; |
elijahsj | 1:4c3c2b7337a6 | 527 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 528 | } |
elijahsj | 1:4c3c2b7337a6 | 529 | else if(htim->Instance==TIM17) |
elijahsj | 1:4c3c2b7337a6 | 530 | { |
elijahsj | 1:4c3c2b7337a6 | 531 | /**TIM17 GPIO Configuration |
elijahsj | 1:4c3c2b7337a6 | 532 | PF7 ------> TIM17_CH1 |
elijahsj | 1:4c3c2b7337a6 | 533 | */ |
elijahsj | 1:4c3c2b7337a6 | 534 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
elijahsj | 1:4c3c2b7337a6 | 535 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
elijahsj | 1:4c3c2b7337a6 | 536 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
elijahsj | 1:4c3c2b7337a6 | 537 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
elijahsj | 1:4c3c2b7337a6 | 538 | GPIO_InitStruct.Alternate = GPIO_AF1_TIM17; |
elijahsj | 1:4c3c2b7337a6 | 539 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); |
elijahsj | 1:4c3c2b7337a6 | 540 | } |
elijahsj | 1:4c3c2b7337a6 | 541 | |
elijahsj | 1:4c3c2b7337a6 | 542 | } |
elijahsj | 1:4c3c2b7337a6 | 543 | |
elijahsj | 1:4c3c2b7337a6 | 544 | |
elijahsj | 1:4c3c2b7337a6 | 545 | |
elijahsj | 1:4c3c2b7337a6 | 546 |