Rev 29 | Rev 31 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 30 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* USER CODE BEGIN Header */ |
1 | /* USER CODE BEGIN Header */ |
2 | /** |
2 | /** |
3 | ****************************************************************************** |
3 | ****************************************************************************** |
4 | * @file : main.c |
4 | * @file : main.c |
5 | * @brief : Main program body |
5 | * @brief : Main program body |
6 | ****************************************************************************** |
6 | ****************************************************************************** |
7 | * @attention |
7 | * @attention |
8 | * |
8 | * |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
10 | * All rights reserved.</center></h2> |
10 | * All rights reserved.</center></h2> |
11 | * |
11 | * |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
12 | * This software component is licensed by ST under BSD 3-Clause license, |
13 | * the "License"; You may not use this file except in compliance with the |
13 | * the "License"; You may not use this file except in compliance with the |
14 | * License. You may obtain a copy of the License at: |
14 | * License. You may obtain a copy of the License at: |
15 | * opensource.org/licenses/BSD-3-Clause |
15 | * opensource.org/licenses/BSD-3-Clause |
16 | * |
16 | * |
17 | ****************************************************************************** |
17 | ****************************************************************************** |
18 | */ |
18 | */ |
19 | /* USER CODE END Header */ |
19 | /* USER CODE END Header */ |
20 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
21 | #include "main.h" |
21 | #include "main.h" |
22 | 22 | ||
23 | /* Private includes ----------------------------------------------------------*/ |
23 | /* Private includes ----------------------------------------------------------*/ |
Line 58... | Line 58... | ||
58 | /* Private variables ---------------------------------------------------------*/ |
58 | /* Private variables ---------------------------------------------------------*/ |
59 | 59 | ||
60 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
60 | // with a dwell angle of 45 degrees , 4 cylinders and a maximum RPM of 5000 |
61 | // freq = 5000/60 * 2 = 166Hz. Because the breaker might bounce , we accept the first pulse longer than 1/300 of a second as being a proper closure . |
61 | // freq = 5000/60 * 2 = 166Hz. Because the breaker might bounce , we accept the first pulse longer than 1/300 of a second as being a proper closure . |
62 | // the TIM2 counter counts in 10uS increments, |
62 | // the TIM2 counter counts in 10uS increments, |
63 | - | ||
64 | // TODO this is wrong algo. Accept FIRST pulse, skip shorter pulses |
63 | // TODO this is wrong algo. Accept FIRST pulse, skip shorter pulses |
65 | #define BREAKER_MIN (RPM_COUNT_RATE/300) |
64 | #define BREAKER_MIN (RPM_COUNT_RATE/300) |
66 | 65 | ||
67 | #define RPM_AVERAGE 4 |
66 | #define RPM_AVERAGE 4 |
68 | 67 | ||
Line 81... | Line 80... | ||
81 | #define Scale 1024.0 |
80 | #define Scale 1024.0 |
82 | const float ADC_Scale = 3.3 / (Scale * 4096.0); // convert to a voltage |
81 | const float ADC_Scale = 3.3 / (Scale * 4096.0); // convert to a voltage |
83 | 82 | ||
84 | uint32_t FILT_Samples[6]; // filtered ADC samples * 1024 |
83 | uint32_t FILT_Samples[6]; // filtered ADC samples * 1024 |
85 | // Rev counter processing from original RevCounter Project |
84 | // Rev counter processing from original RevCounter Project |
86 | unsigned int RPM_Diff = 0; |
85 | uint16_t RPM_Diff = 0; |
87 | unsigned int RPM_Count_Latch = 0; |
86 | uint16_t RPM_Count_Latch = 0; |
88 | // accumulators |
87 | // accumulators |
89 | unsigned int RPM_Pulsecount = 0; |
88 | uint16_t RPM_Pulsecount = 0; |
90 | unsigned int RPM_FilteredWidth = 0; |
89 | unsigned int RPM_FilteredWidth = 0; |
91 | 90 | ||
92 | // last time we detected end of dwell i.e. ignition pulse |
91 | // last time we detected end of dwell i.e. ignition pulse |
93 | unsigned int last_dwell_end = 0; |
92 | uint16_t last_dwell_end = 0; |
94 | unsigned int RPM_Period[RPM_AVERAGE]; |
93 | uint16_t RPM_Period[RPM_AVERAGE]; |
95 | unsigned int RPM_Period_Ptr = 0; |
94 | unsigned int RPM_Period_Ptr = 0; |
96 | 95 | ||
97 | - | ||
98 | unsigned int Coded_RPM = 0; |
96 | unsigned int Coded_RPM = 0; |
99 | unsigned int Coded_CHT = 0; |
97 | unsigned int Coded_CHT = 0; |
100 | 98 | ||
101 | uint32_t Power_CHT_Timer; |
99 | uint32_t Power_CHT_Timer; |
102 | 100 | ||
103 | uint16_t Starter_Debounce = 0; |
101 | uint16_t Starter_Debounce = 0; |
104 | 102 | ||
105 | /* USER CODE END PV */ |
103 | /* USER CODE END PV */ |
106 | 104 | ||
107 | /* Private function prototypes -----------------------------------------------*/ |
105 | /* Private function prototypes -----------------------------------------------*/ |
- | 106 | void |
|
108 | void SystemClock_Config(void); |
107 | SystemClock_Config (void); |
- | 108 | static void |
|
109 | static void MX_GPIO_Init(void); |
109 | MX_GPIO_Init (void); |
- | 110 | static void |
|
110 | static void MX_DMA_Init(void); |
111 | MX_DMA_Init (void); |
- | 112 | static void |
|
111 | static void MX_ADC_Init(void); |
113 | MX_ADC_Init (void); |
- | 114 | static void |
|
112 | static void MX_SPI1_Init(void); |
115 | MX_SPI1_Init (void); |
- | 116 | static void |
|
113 | static void MX_TIM2_Init(void); |
117 | MX_TIM2_Init (void); |
- | 118 | static void |
|
114 | static void MX_TIM6_Init(void); |
119 | MX_TIM6_Init (void); |
- | 120 | static void |
|
115 | static void MX_USART1_UART_Init(void); |
121 | MX_USART1_UART_Init (void); |
- | 122 | static void |
|
116 | static void MX_USART2_UART_Init(void); |
123 | MX_USART2_UART_Init (void); |
- | 124 | static void |
|
117 | static void MX_TIM3_Init(void); |
125 | MX_TIM3_Init (void); |
118 | /* USER CODE BEGIN PFP */ |
126 | /* USER CODE BEGIN PFP */ |
119 | /* Private function prototypes -----------------------------------------------*/ |
127 | /* Private function prototypes -----------------------------------------------*/ |
120 | 128 | ||
121 | /* USER CODE END PFP */ |
129 | /* USER CODE END PFP */ |
122 | 130 | ||
123 | /* Private user code ---------------------------------------------------------*/ |
131 | /* Private user code ---------------------------------------------------------*/ |
124 | /* USER CODE BEGIN 0 */ |
132 | /* USER CODE BEGIN 0 */ |
125 | 133 | ||
- | 134 | void |
|
126 | void plx_sendword(int x) |
135 | plx_sendword (int x) |
127 | { |
136 | { |
128 | PutCharSerial(&uc1, ((x) >> 6) & 0x3F); |
137 | PutCharSerial (&uc1, ((x) >> 6) & 0x3F); |
129 | PutCharSerial(&uc1, (x) & 0x3F); |
138 | PutCharSerial (&uc1, (x) & 0x3F); |
130 | } |
139 | } |
131 | 140 | ||
- | 141 | void |
|
132 | void init_ADC_filter() |
142 | init_ADC_filter () |
133 | { |
143 | { |
134 | int i; |
144 | int i; |
135 | for (i = 0; i < 6; i++) |
145 | for (i = 0; i < 6; i++) |
136 | { |
146 | { |
137 | FILT_Samples[i] = 0; |
147 | FILT_Samples[i] = 0; |
138 | } |
148 | } |
139 | } |
149 | } |
140 | 150 | ||
- | 151 | void |
|
141 | void filter_ADC_samples() |
152 | filter_ADC_samples () |
142 | { |
153 | { |
143 | int i; |
154 | int i; |
144 | for (i = 0; i < 6; i++) |
155 | for (i = 0; i < 6; i++) |
145 | { |
156 | { |
146 | FILT_Samples[i] += (ADC_Samples[i] * Scale - FILT_Samples[i]) / 2; |
157 | FILT_Samples[i] += (ADC_Samples[i] * Scale - FILT_Samples[i]) / 2; |
147 | } |
158 | } |
148 | } |
159 | } |
149 | 160 | ||
- | 161 | void |
|
150 | void ProcessRPM(int instance) |
162 | ProcessRPM (int instance) |
151 | { |
163 | { |
152 | // compute the timer values |
164 | // compute the timer values |
153 | // snapshot timers |
165 | // snapshot timers |
154 | unsigned long RPM_Pulsewidth; |
166 | unsigned long RPM_Pulsewidth; |
155 | // current RPM pulse next slot index |
167 | // current RPM pulse next slot index |
156 | unsigned long RPM_Count_Val; |
168 | unsigned long RPM_Count_Val; |
157 | __disable_irq(); // copy the counter value |
169 | __disable_irq (); // copy the counter value |
158 | RPM_Count_Val = RPM_Count; |
170 | RPM_Count_Val = RPM_Count; |
159 | __enable_irq(); |
171 | __enable_irq (); |
160 | // do calculations |
172 | // do calculations |
161 | // if there is only one entry, cannot get difference |
173 | // if there is only one entry, cannot get difference |
162 | if (RPM_Count_Latch != RPM_Count_Val) |
174 | if (RPM_Count_Latch != RPM_Count_Val) |
- | 175 | { |
|
- | 176 | while (1) |
|
163 | { |
177 | { |
164 | while (1) |
- | |
165 | { |
- | |
166 | unsigned int base_time; |
178 | unsigned int base_time; |
167 | unsigned int new_time; |
179 | unsigned int new_time; |
168 | // if we are at N-1, stop. |
180 | // if we are at N-1, stop. |
169 | unsigned int next_count = (RPM_Count_Latch + 1) % RPM_SAMPLES; |
181 | unsigned int next_count = (RPM_Count_Latch + 1) % RPM_SAMPLES; |
170 | if (next_count == RPM_Count_Val) |
182 | if (next_count == RPM_Count_Val) |
171 | { |
183 | { |
172 | break; // completed loop |
184 | break; // completed loop |
173 | } |
185 | } |
174 | char pulse_level = RPM_Level[RPM_Count_Latch]; |
186 | char pulse_level = RPM_Level[RPM_Count_Latch]; |
175 | base_time = RPM_Time[RPM_Count_Latch]; |
187 | base_time = RPM_Time[RPM_Count_Latch]; |
176 | new_time = RPM_Time[next_count]; |
188 | new_time = RPM_Time[next_count]; |
177 | RPM_Count_Latch = next_count; |
189 | RPM_Count_Latch = next_count; |
178 | 190 | ||
179 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
191 | RPM_Pulsewidth = new_time - base_time; // not wrapped |
180 | 192 | ||
181 | // if the pulse was low, |
193 | // if the pulse was low, |
182 | if(pulse_level == 0 && RPM_Pulsewidth > BREAKER_MIN) |
194 | if (pulse_level == 0 && RPM_Pulsewidth > BREAKER_MIN) |
183 | { |
195 | { |
184 | RPM_Diff = new_time - last_dwell_end; |
- | |
185 | last_dwell_end = new_time; |
- | |
186 | 196 | ||
- | 197 | RPM_Diff = new_time - last_dwell_end; |
|
187 | 198 | ||
188 | RPM_Period[RPM_Period_Ptr] = RPM_Diff; |
199 | RPM_Period[RPM_Period_Ptr] = RPM_Diff; |
189 | RPM_Period_Ptr = (RPM_Period_Ptr+1) % RPM_AVERAGE; |
200 | RPM_Period_Ptr = (RPM_Period_Ptr + 1) % RPM_AVERAGE; |
190 | if(RPM_Pulsecount < RPM_AVERAGE) |
201 | if (RPM_Pulsecount < RPM_AVERAGE) |
191 | RPM_Pulsecount++; // count one pulse |
202 | RPM_Pulsecount++; // count one pulse |
192 | } |
203 | last_dwell_end = new_time; |
193 | } |
- | |
194 | 204 | ||
- | 205 | } |
|
195 | } |
206 | } |
196 | 207 | ||
197 | if (RPM_Pulsecount == RPM_AVERAGE) |
- | |
198 | { |
- | |
199 | // now have time for N pulses in clocks |
- | |
200 | // need to scale by 19.55: one unit is 19.55 RPM |
- | |
201 | // 1Hz is 60 RPM |
- | |
202 | int i; |
208 | } |
203 | RPM_FilteredWidth = 0; |
- | |
204 | for (i=0;i<RPM_AVERAGE;i++) |
- | |
205 | RPM_FilteredWidth += RPM_Period[i]; |
- | |
206 | 209 | ||
- | 210 | if (RPM_Pulsecount == RPM_AVERAGE) |
|
- | 211 | { |
|
- | 212 | // now have time for N pulses in clocks |
|
- | 213 | // need to scale by 19.55: one unit is 19.55 RPM |
|
- | 214 | // 1Hz is 30 RPM |
|
- | 215 | int i; |
|
- | 216 | RPM_FilteredWidth = 0; |
|
- | 217 | for (i = 0; i < RPM_AVERAGE; i++) |
|
- | 218 | RPM_FilteredWidth += RPM_Period[i]; |
|
207 | 219 | ||
208 | float New_RPM = (30.0 / 19.55 * RPM_Pulsecount * RPM_COUNT_RATE) |
220 | Coded_RPM = (Scale * 30.0 * RPM_AVERAGE * RPM_COUNT_RATE) |
209 | / (RPM_FilteredWidth) + 0.5; |
221 | / (19.55 * RPM_FilteredWidth); |
210 | // increase RPM filtering |
- | |
211 | Coded_RPM += (New_RPM * Scale - Coded_RPM) / 8; |
- | |
212 | 222 | ||
213 | #if !defined MY_DEBUG |
223 | #if !defined MY_DEBUG |
214 | // reset here unless we want to debug |
224 | // reset here unless we want to debug |
215 | RPM_Pulsecount = 0; |
225 | RPM_Pulsecount = 0; |
216 | RPM_FilteredWidth = 0; |
226 | RPM_FilteredWidth = 0; |
217 | #endif |
227 | #endif |
218 | } |
228 | } |
219 | 229 | ||
220 | // send the current RPM *calculation |
230 | // send the current RPM *calculation |
221 | plx_sendword(PLX_RPM); |
231 | plx_sendword (PLX_RPM); |
222 | PutCharSerial(&uc1, instance); |
232 | PutCharSerial (&uc1, instance); |
223 | plx_sendword(Coded_RPM / Scale); |
233 | plx_sendword (Coded_RPM / Scale); |
224 | } |
234 | } |
225 | 235 | ||
226 | // this uses a MAX6675 which is a simple 16 bit read |
236 | // this uses a MAX6675 which is a simple 16 bit read |
227 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
237 | // SPI is configured for 8 bits so I can use an OLED display if I need it |
228 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
238 | // must wait > 0.22 seconds between conversion attempts as this is the measurement time |
Line 231... | Line 241... | ||
231 | FunctionalState CHT_Enable = ENABLE; |
241 | FunctionalState CHT_Enable = ENABLE; |
232 | 242 | ||
233 | #define CORR 3 |
243 | #define CORR 3 |
234 | 244 | ||
235 | uint8_t CHT_Timer[2] = |
245 | uint8_t CHT_Timer[2] = |
236 | { 0, 0 }; // two temperature readings : from two sensors |
246 | { 0, 0 }; // two temperature readings : from two sensors |
237 | - | ||
238 | 247 | ||
239 | uint16_t CHT_Observations[2] = |
248 | uint16_t CHT_Observations[2] = |
240 | { 0, 0 }; |
249 | { 0, 0 }; |
241 | 250 | ||
242 | // look for the trigger pin being high then low - the points |
251 | // look for the trigger pin being high then low - the points |
243 | // are opening, and skip the reading |
252 | // are opening, and skip the reading |
244 | 253 | ||
245 | 254 | void |
|
246 | void ProcessCHT(int instance) |
255 | ProcessCHT (int instance) |
247 | { |
256 | { |
248 | uint8_t buffer[2]; |
257 | uint8_t buffer[2]; |
249 | if (instance > 2) |
258 | if (instance > 2) |
250 | return; |
259 | return; |
251 | CHT_Timer[instance]++; |
260 | CHT_Timer[instance]++; |
252 | 261 | ||
253 | static uint8_t prevCB; |
262 | static uint8_t prevCB; |
254 | 263 | ||
255 | uint8_t readCB = |
- | |
256 | HAL_GPIO_ReadPin(CB_Pulse_GPIO_Port, CB_Pulse_Pin); |
264 | uint8_t readCB = HAL_GPIO_ReadPin (CB_Pulse_GPIO_Port, CB_Pulse_Pin); |
257 | 265 | ||
258 | if(!(prevCB == GPIO_PIN_SET && readCB == |
266 | if (!(prevCB == GPIO_PIN_SET && readCB == GPIO_PIN_RESET)) |
259 | GPIO_PIN_RESET) ) |
- | |
260 | { |
267 | { |
261 | 268 | ||
262 | if ((CHT_Enable == ENABLE) && (CHT_Timer[instance] >= 4)) // every 300 milliseconds |
269 | if ((CHT_Enable == ENABLE) && (CHT_Timer[instance] >= 4)) // every 300 milliseconds |
263 | { |
270 | { |
264 | 271 | ||
265 | CHT_Timer[instance] = 0; |
272 | CHT_Timer[instance] = 0; |
266 | 273 | ||
267 | uint16_t Pin = (instance == 0) ? SPI_NS_Temp_Pin : SPI_NS_Temp2_Pin; |
274 | uint16_t Pin = (instance == 0) ? SPI_NS_Temp_Pin : SPI_NS_Temp2_Pin; |
268 | 275 | ||
269 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, Pin, GPIO_PIN_RESET); |
276 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, Pin, GPIO_PIN_RESET); |
270 | 277 | ||
271 | HAL_SPI_Receive(&hspi1, buffer, 2, 2); |
278 | HAL_SPI_Receive (&hspi1, buffer, 2, 2); |
272 | 279 | ||
273 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, Pin, GPIO_PIN_SET); |
280 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, Pin, GPIO_PIN_SET); |
274 | 281 | ||
275 | uint16_t obs = (buffer[0] << 8) | buffer[1]; |
282 | uint16_t obs = (buffer[0] << 8) | buffer[1]; |
276 | 283 | ||
277 | // good observation if the status bit is clear, and the reading is less than 1023 |
284 | // good observation if the status bit is clear, and the reading is less than 1023 |
278 | 285 | ||
279 | uint16_t temp_c = obs>>5; |
286 | uint16_t temp_c = obs >> 5; |
280 | 287 | ||
281 | uint8_t good = ((obs & 7) == 0) && (temp_c > 0) && (temp_c < 250); |
288 | uint8_t good = ((obs & 7) == 0) && (temp_c > 0) && (temp_c < 250); |
282 | 289 | ||
283 | if (good) |
290 | if (good) |
284 | { |
291 | { |
285 | CHT_Observations[instance]=temp_c; |
292 | CHT_Observations[instance] = temp_c; |
286 | 293 | ||
287 | } |
294 | } |
288 | 295 | ||
289 | } |
296 | } |
290 | } |
297 | } |
291 | 298 | ||
292 | prevCB= readCB; |
299 | prevCB = readCB; |
293 | plx_sendword(PLX_X_CHT); |
300 | plx_sendword (PLX_X_CHT); |
294 | PutCharSerial(&uc1, instance); |
301 | PutCharSerial (&uc1, instance); |
295 | plx_sendword(CHT_Observations[instance]); |
302 | plx_sendword (CHT_Observations[instance]); |
296 | 303 | ||
297 | } |
304 | } |
298 | 305 | ||
- | 306 | void |
|
299 | void EnableCHT(FunctionalState state) |
307 | EnableCHT (FunctionalState state) |
- | 308 | ||
- | 309 | { |
|
- | 310 | GPIO_InitTypeDef GPIO_InitStruct; |
|
- | 311 | ||
- | 312 | CHT_Enable = state; |
|
- | 313 | ||
- | 314 | /* enable SPI in live mode : assume it and its GPIOs are already initialised in SPI mode */ |
|
- | 315 | if (state == ENABLE) |
|
- | 316 | { |
|
- | 317 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_SET); |
|
- | 318 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
|
- | 319 | HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
|
- | 320 | GPIO_PIN_SET); |
|
- | 321 | ||
- | 322 | /* put the SPI pins back into SPI AF mode */ |
|
- | 323 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
|
- | 324 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
|
- | 325 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
|
- | 326 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
|
- | 327 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; |
|
- | 328 | HAL_GPIO_Init (SPI1_SCK_GPIO_Port, &GPIO_InitStruct); |
|
- | 329 | ||
- | 330 | } |
|
- | 331 | else |
|
- | 332 | { |
|
- | 333 | /* Power down the SPI interface taking signals all low */ |
|
- | 334 | HAL_GPIO_WritePin (ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
|
- | 335 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, |
|
- | 336 | GPIO_PIN_RESET); |
|
- | 337 | HAL_GPIO_WritePin (SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
|
- | 338 | GPIO_PIN_RESET); |
|
- | 339 | ||
- | 340 | HAL_GPIO_WritePin (SPI1_SCK_GPIO_Port, |
|
- | 341 | SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin, |
|
- | 342 | GPIO_PIN_RESET); |
|
- | 343 | ||
- | 344 | /* put the SPI pins back into GPIO mode */ |
|
- | 345 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
|
- | 346 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
- | 347 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
|
- | 348 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
|
- | 349 | HAL_GPIO_Init (SPI1_SCK_GPIO_Port, &GPIO_InitStruct); |
|
300 | 350 | ||
301 | { |
- | |
302 | GPIO_InitTypeDef GPIO_InitStruct; |
- | |
303 | - | ||
304 | CHT_Enable = state; |
- | |
305 | - | ||
306 | - | ||
307 | /* enable SPI in live mode : assume it and its GPIOs are already initialised in SPI mode */ |
- | |
308 | if (state == ENABLE) |
- | |
309 | { |
- | |
310 | HAL_GPIO_WritePin(ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_SET ); |
- | |
311 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
- | |
312 | HAL_GPIO_WritePin(SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
- | |
313 | GPIO_PIN_SET); |
- | |
314 | - | ||
315 | /* put the SPI pins back into SPI AF mode */ |
- | |
316 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
- | |
317 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
- | |
318 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
- | |
319 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
- | |
320 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; |
- | |
321 | HAL_GPIO_Init(SPI1_SCK_GPIO_Port, &GPIO_InitStruct); |
- | |
322 | - | ||
323 | } |
- | |
324 | else |
351 | } |
325 | { |
- | |
326 | /* Power down the SPI interface taking signals all low */ |
- | |
327 | HAL_GPIO_WritePin(ENA_AUX_5V_GPIO_Port, ENA_AUX_5V_Pin, GPIO_PIN_RESET ); |
- | |
328 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, |
- | |
329 | GPIO_PIN_RESET); |
- | |
330 | HAL_GPIO_WritePin(SPI_NS_Temp2_GPIO_Port, SPI_NS_Temp2_Pin, |
- | |
331 | GPIO_PIN_RESET); |
- | |
332 | - | ||
333 | HAL_GPIO_WritePin(SPI1_SCK_GPIO_Port, |
- | |
334 | SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin, GPIO_PIN_RESET); |
- | |
335 | - | ||
336 | /* put the SPI pins back into GPIO mode */ |
- | |
337 | GPIO_InitStruct.Pin = SPI1_MOSI_Pin | SPI1_MISO_Pin | SPI1_SCK_Pin; |
- | |
338 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
- | |
339 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
- | |
340 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
- | |
341 | HAL_GPIO_Init(SPI1_SCK_GPIO_Port, &GPIO_InitStruct); |
- | |
342 | - | ||
343 | } |
- | |
344 | 352 | ||
345 | } |
353 | } |
346 | 354 | ||
347 | // 1023 is 20.00 volts. |
355 | // 1023 is 20.00 volts. |
- | 356 | void |
|
348 | void ProcessBatteryVoltage(int instance) |
357 | ProcessBatteryVoltage (int instance) |
349 | { |
358 | { |
350 | float reading = FILT_Samples[instance] * ADC_Scale; |
359 | float reading = FILT_Samples[instance] * ADC_Scale; |
351 | reading = reading * 7.8125; // real voltage |
360 | reading = reading * 7.8125; // real voltage |
352 | reading = reading * 51.15; // 1023/20 |
361 | reading = reading * 51.15; // 1023/20 |
353 | 362 | ||
354 | plx_sendword(PLX_Volts); |
363 | plx_sendword (PLX_Volts); |
355 | PutCharSerial(&uc1, instance); |
364 | PutCharSerial (&uc1, instance); |
356 | plx_sendword((uint16_t) reading); |
365 | plx_sendword ((uint16_t) reading); |
357 | 366 | ||
358 | } |
367 | } |
359 | 368 | ||
360 | /****! |
369 | /****! |
361 | * @brief this reads the reference voltage within the STM32L151 |
370 | * @brief this reads the reference voltage within the STM32L151 |
Line 364... | Line 373... | ||
364 | */ |
373 | */ |
365 | 374 | ||
366 | uint32_t ADC_VREF_MV = 3300; // 3.300V typical |
375 | uint32_t ADC_VREF_MV = 3300; // 3.300V typical |
367 | const uint16_t STM32REF_MV = 1224; // 1.224V typical |
376 | const uint16_t STM32REF_MV = 1224; // 1.224V typical |
368 | 377 | ||
- | 378 | void |
|
369 | void CalibrateADC(void) |
379 | CalibrateADC (void) |
370 | { |
380 | { |
371 | uint32_t adc_val = FILT_Samples[5]; // as set up in device config |
381 | uint32_t adc_val = FILT_Samples[5]; // as set up in device config |
372 | ADC_VREF_MV = (STM32REF_MV * 4096) / adc_val; |
382 | ADC_VREF_MV = (STM32REF_MV * 4096) / adc_val; |
373 | } |
383 | } |
374 | 384 | ||
- | 385 | void |
|
375 | void ProcessCPUTemperature(int instance) |
386 | ProcessCPUTemperature (int instance) |
376 | { |
387 | { |
377 | int32_t temp_val; |
388 | int32_t temp_val; |
378 | 389 | ||
379 | uint16_t TS_CAL30 = *(uint16_t *) (0x1FF8007AUL); /* ADC reading for temperature sensor at 30 degrees C with Vref = 3000mV */ |
390 | uint16_t TS_CAL30 = *(uint16_t*) (0x1FF8007AUL); /* ADC reading for temperature sensor at 30 degrees C with Vref = 3000mV */ |
380 | uint16_t TS_CAL110 = *(uint16_t *) (0x1FF8007EUL); /* ADC reading for temperature sensor at 110 degrees C with Vref = 3000mV */ |
391 | uint16_t TS_CAL110 = *(uint16_t*) (0x1FF8007EUL); /* ADC reading for temperature sensor at 110 degrees C with Vref = 3000mV */ |
381 | /* get the ADC reading corresponding to ADC channel 16 after turning on the ADC */ |
392 | /* get the ADC reading corresponding to ADC channel 16 after turning on the ADC */ |
382 | 393 | ||
383 | temp_val = FILT_Samples[5]; |
394 | temp_val = FILT_Samples[5]; |
384 | 395 | ||
385 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
396 | /* renormalise temperature value to account for different ADC Vref : normalise to that which we would get for a 3000mV reference */ |
386 | temp_val = temp_val * ADC_VREF_MV / (Scale * 3000UL); |
397 | temp_val = temp_val * ADC_VREF_MV / (Scale * 3000UL); |
387 | 398 | ||
388 | int32_t result = 800 * ((int32_t) temp_val - TS_CAL30); |
399 | int32_t result = 800 * ((int32_t) temp_val - TS_CAL30); |
389 | result = result / (TS_CAL110 - TS_CAL30) + 300; |
400 | result = result / (TS_CAL110 - TS_CAL30) + 300; |
390 | 401 | ||
391 | if (result < 0) |
402 | if (result < 0) |
392 | { |
403 | { |
393 | result = 0; |
404 | result = 0; |
394 | } |
405 | } |
395 | plx_sendword(PLX_FluidTemp); |
406 | plx_sendword (PLX_FluidTemp); |
396 | PutCharSerial(&uc1, instance); |
407 | PutCharSerial (&uc1, instance); |
397 | plx_sendword(result / 10); |
408 | plx_sendword (result / 10); |
398 | 409 | ||
399 | } |
410 | } |
400 | 411 | ||
401 | // the MAP sensor is giving us a reading of |
412 | // the MAP sensor is giving us a reading of |
402 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
413 | // 4.6 volts for 1019mB or 2.27 volts at the ADC input (resistive divider by 2.016) |
Line 405... | Line 416... | ||
405 | // Real Displayed |
416 | // Real Displayed |
406 | // 989 968 |
417 | // 989 968 |
407 | // 994.1 986 |
418 | // 994.1 986 |
408 | // 992.3 984 |
419 | // 992.3 984 |
409 | 420 | ||
- | 421 | void |
|
410 | void ProcessMAP(int instance) |
422 | ProcessMAP (int instance) |
411 | { |
423 | { |
412 | // Using ADC_Samples[3] as the MAP input |
424 | // Using ADC_Samples[3] as the MAP input |
413 | float reading = FILT_Samples[3] * ADC_Scale; |
425 | float reading = FILT_Samples[3] * ADC_Scale; |
414 | reading = reading * 2.016; // real voltage |
426 | reading = reading * 2.016; // real voltage |
415 | // values computed from slope / intercept of map.ods |
427 | // values computed from slope / intercept of map.ods |
416 | //reading = (reading) * 56.23 + 743.2; // do not assume 0.5 volt offset : reading from 0 to 4.5 instead of 0.5 to 4.5 |
428 | //reading = (reading) * 56.23 + 743.2; // do not assume 0.5 volt offset : reading from 0 to 4.5 instead of 0.5 to 4.5 |
417 | // using a pressure gauge. |
429 | // using a pressure gauge. |
418 | reading = (reading) * 150 + 326; |
430 | reading = (reading) * 150 + 326; |
419 | 431 | ||
420 | plx_sendword(PLX_MAP); |
432 | plx_sendword (PLX_MAP); |
421 | PutCharSerial(&uc1, instance); |
433 | PutCharSerial (&uc1, instance); |
422 | plx_sendword((uint16_t) reading); |
434 | plx_sendword ((uint16_t) reading); |
423 | 435 | ||
424 | } |
436 | } |
425 | 437 | ||
426 | // the Oil pressi sensor is giving us a reading of |
438 | // the Oil pressi sensor is giving us a reading of |
427 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
439 | // 4.5 volts for 100 PSI or 2.25 volts at the ADC input (resistive divider by 2.016) |
428 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
440 | // I believe the sensor reads 4.5V at 100PSI and 0.5V at 0PSI |
429 | // an observation of 1024 is 200PSI, so observation of 512 is 100 PSI. |
441 | // an observation of 1024 is 200PSI, so observation of 512 is 100 PSI. |
430 | 442 | ||
- | 443 | void |
|
431 | void ProcessOilPress(int instance) |
444 | ProcessOilPress (int instance) |
432 | { |
445 | { |
433 | // Using ADC_Samples[2] as the MAP input |
446 | // Using ADC_Samples[2] as the MAP input |
434 | float reading = FILT_Samples[2] * ADC_Scale; |
447 | float reading = FILT_Samples[2] * ADC_Scale; |
435 | reading = reading * 2.00; // real voltage |
448 | reading = reading * 2.00; // real voltage |
436 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
449 | reading = (reading - 0.5) * 512 / 4; // this is 1023 * 100/200 |
437 | 450 | ||
438 | plx_sendword(PLX_FluidPressure); |
451 | plx_sendword (PLX_FluidPressure); |
439 | PutCharSerial(&uc1, instance); |
452 | PutCharSerial (&uc1, instance); |
440 | plx_sendword((uint16_t) reading); |
453 | plx_sendword ((uint16_t) reading); |
441 | 454 | ||
442 | } |
455 | } |
443 | 456 | ||
- | 457 | void |
|
444 | void ProcessTiming(int instance) |
458 | ProcessTiming (int instance) |
445 | { |
459 | { |
446 | plx_sendword(PLX_Timing); |
460 | plx_sendword (PLX_Timing); |
447 | PutCharSerial(&uc1, instance); |
461 | PutCharSerial (&uc1, instance); |
448 | plx_sendword(64 - 15); // make it negative |
462 | plx_sendword (64 - 15); // make it negative |
449 | } |
463 | } |
450 | 464 | ||
451 | /* USER CODE END 0 */ |
465 | /* USER CODE END 0 */ |
452 | 466 | ||
453 | /** |
467 | /** |
454 | * @brief The application entry point. |
468 | * @brief The application entry point. |
455 | * @retval int |
469 | * @retval int |
456 | */ |
470 | */ |
- | 471 | int |
|
457 | int main(void) |
472 | main (void) |
458 | { |
473 | { |
459 | /* USER CODE BEGIN 1 */ |
474 | /* USER CODE BEGIN 1 */ |
460 | 475 | ||
461 | /* USER CODE END 1 */ |
476 | /* USER CODE END 1 */ |
462 | 477 | ||
463 | /* MCU Configuration--------------------------------------------------------*/ |
478 | /* MCU Configuration--------------------------------------------------------*/ |
464 | 479 | ||
465 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
480 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
466 | HAL_Init(); |
481 | HAL_Init (); |
467 | 482 | ||
468 | /* USER CODE BEGIN Init */ |
483 | /* USER CODE BEGIN Init */ |
469 | 484 | ||
470 | /* USER CODE END Init */ |
485 | /* USER CODE END Init */ |
471 | 486 | ||
472 | /* Configure the system clock */ |
487 | /* Configure the system clock */ |
473 | SystemClock_Config(); |
488 | SystemClock_Config (); |
474 | 489 | ||
475 | /* USER CODE BEGIN SysInit */ |
490 | /* USER CODE BEGIN SysInit */ |
476 | 491 | ||
477 | /* USER CODE END SysInit */ |
492 | /* USER CODE END SysInit */ |
478 | 493 | ||
479 | /* Initialize all configured peripherals */ |
494 | /* Initialize all configured peripherals */ |
480 | MX_GPIO_Init(); |
495 | MX_GPIO_Init (); |
481 | MX_DMA_Init(); |
496 | MX_DMA_Init (); |
482 | MX_ADC_Init(); |
497 | MX_ADC_Init (); |
483 | MX_SPI1_Init(); |
498 | MX_SPI1_Init (); |
484 | MX_TIM2_Init(); |
499 | MX_TIM2_Init (); |
485 | MX_TIM6_Init(); |
500 | MX_TIM6_Init (); |
486 | MX_USART1_UART_Init(); |
501 | MX_USART1_UART_Init (); |
487 | MX_USART2_UART_Init(); |
502 | MX_USART2_UART_Init (); |
488 | MX_TIM3_Init(); |
503 | MX_TIM3_Init (); |
489 | /* USER CODE BEGIN 2 */ |
504 | /* USER CODE BEGIN 2 */ |
490 | HAL_MspInit(); |
505 | HAL_MspInit (); |
491 | 506 | ||
492 | // Not using HAL USART code |
507 | // Not using HAL USART code |
493 | __HAL_RCC_USART1_CLK_ENABLE() |
508 | __HAL_RCC_USART1_CLK_ENABLE() |
494 | ; // PLX comms port |
509 | ; // PLX comms port |
495 | __HAL_RCC_USART2_CLK_ENABLE() |
510 | __HAL_RCC_USART2_CLK_ENABLE() |
496 | ; // Debug comms port |
511 | ; // Debug comms port |
497 | /* setup the USART control blocks */ |
512 | /* setup the USART control blocks */ |
498 | init_usart_ctl(&uc1, huart1.Instance); |
513 | init_usart_ctl (&uc1, huart1.Instance); |
499 | init_usart_ctl(&uc2, huart2.Instance); |
514 | init_usart_ctl (&uc2, huart2.Instance); |
500 | 515 | ||
501 | EnableSerialRxInterrupt(&uc1); |
516 | EnableSerialRxInterrupt (&uc1); |
502 | EnableSerialRxInterrupt(&uc2); |
517 | EnableSerialRxInterrupt (&uc2); |
503 | 518 | ||
504 | HAL_SPI_MspInit(&hspi1); |
519 | HAL_SPI_MspInit (&hspi1); |
505 | 520 | ||
506 | HAL_ADC_MspInit(&hadc); |
521 | HAL_ADC_MspInit (&hadc); |
507 | 522 | ||
508 | HAL_ADC_Start_DMA(&hadc, ADC_Samples, 6); |
523 | HAL_ADC_Start_DMA (&hadc, ADC_Samples, 6); |
509 | 524 | ||
510 | HAL_ADC_Start_IT(&hadc); |
525 | HAL_ADC_Start_IT (&hadc); |
511 | 526 | ||
512 | HAL_TIM_Base_MspInit(&htim6); |
527 | HAL_TIM_Base_MspInit (&htim6); |
513 | HAL_TIM_Base_Start_IT(&htim6); |
528 | HAL_TIM_Base_Start_IT (&htim6); |
514 | 529 | ||
515 | // initialise all the STMCubeMX stuff |
530 | // initialise all the STMCubeMX stuff |
516 | HAL_TIM_Base_MspInit(&htim2); |
531 | HAL_TIM_Base_MspInit (&htim2); |
517 | // Start the counter |
532 | // Start the counter |
518 | HAL_TIM_Base_Start(&htim2); |
533 | HAL_TIM_Base_Start (&htim2); |
519 | // Start the input capture and the interrupt |
534 | // Start the input capture and the interrupt |
520 | HAL_TIM_IC_Start_IT(&htim2, TIM_CHANNEL_1); |
535 | HAL_TIM_IC_Start_IT (&htim2, TIM_CHANNEL_1); |
521 | - | ||
522 | init_ADC_filter(); |
- | |
523 | - | ||
524 | uint32_t Ticks = HAL_GetTick() + 100; |
- | |
525 | int CalCounter = 0; |
- | |
526 | - | ||
527 | Power_CHT_Timer = HAL_GetTick() + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
- | |
528 | 536 | ||
- | 537 | init_ADC_filter (); |
|
529 | 538 | ||
- | 539 | uint32_t Ticks = HAL_GetTick () + 100; |
|
- | 540 | int CalCounter = 0; |
|
530 | 541 | ||
- | 542 | Power_CHT_Timer = HAL_GetTick () + 1000; /* wait 10 seconds before powering up the CHT sensor */ |
|
531 | 543 | ||
532 | /* USER CODE END 2 */ |
544 | /* USER CODE END 2 */ |
533 | 545 | ||
534 | /* Infinite loop */ |
546 | /* Infinite loop */ |
535 | /* USER CODE BEGIN WHILE */ |
547 | /* USER CODE BEGIN WHILE */ |
536 | while (1) |
548 | while (1) |
- | 549 | { |
|
- | 550 | /* USER CODE END WHILE */ |
|
- | 551 | ||
- | 552 | /* USER CODE BEGIN 3 */ |
|
- | 553 | ||
- | 554 | if (HAL_GetTick () > Ticks) |
|
537 | { |
555 | { |
- | 556 | Ticks += 100; |
|
- | 557 | filter_ADC_samples (); |
|
538 | /* USER CODE END WHILE */ |
558 | // delay to calibrate ADC |
- | 559 | if (CalCounter < 1000) |
|
- | 560 | { |
|
- | 561 | CalCounter += 100; |
|
- | 562 | } |
|
- | 563 | ||
- | 564 | if (CalCounter == 900) |
|
- | 565 | { |
|
- | 566 | CalibrateADC (); |
|
- | 567 | } |
|
- | 568 | } |
|
- | 569 | /* when the starter motor is on then power down the CHT sensors as they seem to fail */ |
|
539 | 570 | ||
- | 571 | if (HAL_GPIO_ReadPin (STARTER_ON_GPIO_Port, STARTER_ON_Pin) |
|
- | 572 | == GPIO_PIN_RESET) |
|
- | 573 | { |
|
- | 574 | if (Starter_Debounce < STARTER_LIMIT) |
|
- | 575 | { |
|
- | 576 | Starter_Debounce++; |
|
- | 577 | } |
|
- | 578 | } |
|
- | 579 | else |
|
- | 580 | { |
|
540 | /* USER CODE BEGIN 3 */ |
581 | if (Starter_Debounce > 0) |
- | 582 | { |
|
- | 583 | Starter_Debounce--; |
|
- | 584 | } |
|
- | 585 | } |
|
541 | 586 | ||
542 | if (HAL_GetTick() > Ticks) |
- | |
543 | { |
- | |
544 | Ticks += 100; |
- | |
545 | filter_ADC_samples(); |
- | |
546 | // delay to calibrate ADC |
- | |
547 | if (CalCounter < 1000) |
- | |
548 | { |
- | |
549 | CalCounter += 100; |
- | |
550 | } |
- | |
551 | - | ||
552 | if (CalCounter == 900) |
- | |
553 | { |
- | |
554 | CalibrateADC(); |
- | |
555 | } |
- | |
556 | } |
- | |
557 | /* when the starter motor is on then power down the CHT sensors as they seem to fail */ |
- | |
558 | - | ||
559 | if (HAL_GPIO_ReadPin(STARTER_ON_GPIO_Port, STARTER_ON_Pin) |
- | |
560 | == GPIO_PIN_RESET ) |
- | |
561 | { |
- | |
562 | if(Starter_Debounce < STARTER_LIMIT) |
- | |
563 | { |
- | |
564 | Starter_Debounce++; |
- | |
565 | } |
- | |
566 | } |
- | |
567 | else |
- | |
568 | { |
- | |
569 | if(Starter_Debounce > 0) |
- | |
570 | { |
- | |
571 | Starter_Debounce --; |
- | |
572 | } |
- | |
573 | } |
- | |
574 | - | ||
575 | if (Starter_Debounce == STARTER_LIMIT) |
587 | if (Starter_Debounce == STARTER_LIMIT) |
576 | { |
588 | { |
577 | EnableCHT(DISABLE); |
589 | EnableCHT (DISABLE); |
578 | Power_CHT_Timer = HAL_GetTick() + 1000; |
590 | Power_CHT_Timer = HAL_GetTick () + 1000; |
579 | } |
591 | } |
580 | else |
592 | else |
581 | /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */ |
593 | /* if the Power_CHT_Timer is set then wait for it to timeout, then power up CHT */ |
582 | { |
594 | { |
583 | if ((Power_CHT_Timer > 0) && (HAL_GetTick() > Power_CHT_Timer)) |
595 | if ((Power_CHT_Timer > 0) && (HAL_GetTick () > Power_CHT_Timer)) |
584 | { |
596 | { |
585 | EnableCHT(ENABLE); |
597 | EnableCHT (ENABLE); |
586 | Power_CHT_Timer = 0; |
598 | Power_CHT_Timer = 0; |
587 | } |
599 | } |
588 | } |
600 | } |
589 | - | ||
590 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
- | |
591 | int c; |
- | |
592 | char send = 0; |
- | |
593 | - | ||
594 | // poll the input for a stop bit or timeout |
- | |
595 | if (PollSerial(&uc1)) |
- | |
596 | { |
- | |
597 | resetSerialTimeout(); |
- | |
598 | c = GetCharSerial(&uc1); |
- | |
599 | if (c != PLX_Stop) |
- | |
600 | { |
- | |
601 | PutCharSerial(&uc1, c); // echo all but the stop bit |
- | |
602 | } |
- | |
603 | else |
- | |
604 | { // must be a stop character |
- | |
605 | send = 1; // start our sending process. |
- | |
606 | } |
- | |
607 | } |
- | |
608 | - | ||
609 | // sort out auto-sending |
- | |
610 | if (TimerFlag) |
- | |
611 | { |
- | |
612 | TimerFlag = 0; |
- | |
613 | if (NoSerialIn) |
- | |
614 | { |
- | |
615 | PutCharSerial(&uc1, PLX_Start); |
- | |
616 | send = 1; |
- | |
617 | } |
- | |
618 | } |
- | |
619 | if (send) |
- | |
620 | { |
- | |
621 | send = 0; |
- | |
622 | - | ||
623 | uint16_t val; |
- | |
624 | val = __HAL_TIM_GET_COMPARE(&htim2,TIM_CHANNEL_1); |
- | |
625 | PutCharSerial(&uc2, (val & 31) + 32); |
- | |
626 | - | ||
627 | // send the observations |
- | |
628 | ProcessRPM(0); |
- | |
629 | ProcessCHT(0); |
- | |
630 | ProcessCHT(1); |
- | |
631 | ProcessBatteryVoltage(0); // Batt 1 |
- | |
632 | ProcessBatteryVoltage(1); // Batt 2 |
- | |
633 | ProcessCPUTemperature(0); // built in temperature sensor |
- | |
634 | 601 | ||
- | 602 | // check to see if we have any incoming data, copy and append if so, if no data then create our own frames. |
|
635 | ProcessMAP(0); |
603 | int c; |
636 | ProcessOilPress(0); |
604 | char send = 0; |
637 | 605 | ||
- | 606 | // poll the input for a stop bit or timeout |
|
- | 607 | if (PollSerial (&uc1)) |
|
- | 608 | { |
|
- | 609 | resetSerialTimeout (); |
|
638 | PutCharSerial(&uc1, PLX_Stop); |
610 | c = GetCharSerial (&uc1); |
- | 611 | if (c != PLX_Stop) |
|
- | 612 | { |
|
- | 613 | PutCharSerial (&uc1, c); // echo all but the stop bit |
|
- | 614 | } |
|
- | 615 | else |
|
- | 616 | { // must be a stop character |
|
- | 617 | send = 1; // start our sending process. |
|
639 | } |
618 | } |
640 | } |
619 | } |
- | 620 | ||
- | 621 | // sort out auto-sending |
|
- | 622 | if (TimerFlag) |
|
- | 623 | { |
|
- | 624 | TimerFlag = 0; |
|
- | 625 | if (NoSerialIn) |
|
- | 626 | { |
|
- | 627 | PutCharSerial (&uc1, PLX_Start); |
|
- | 628 | send = 1; |
|
- | 629 | } |
|
- | 630 | } |
|
- | 631 | if (send) |
|
- | 632 | { |
|
- | 633 | send = 0; |
|
- | 634 | ||
- | 635 | uint16_t val; |
|
- | 636 | val = __HAL_TIM_GET_COMPARE(&htim2, TIM_CHANNEL_1); |
|
- | 637 | PutCharSerial (&uc2, (val & 31) + 32); |
|
- | 638 | ||
- | 639 | // send the observations |
|
- | 640 | ProcessRPM (0); |
|
- | 641 | ProcessCHT (0); |
|
- | 642 | ProcessCHT (1); |
|
- | 643 | ProcessBatteryVoltage (0); // Batt 1 |
|
- | 644 | ProcessBatteryVoltage (1); // Batt 2 |
|
- | 645 | ProcessCPUTemperature (0); // built in temperature sensor |
|
- | 646 | ||
- | 647 | ProcessMAP (0); |
|
- | 648 | ProcessOilPress (0); |
|
- | 649 | ||
- | 650 | PutCharSerial (&uc1, PLX_Stop); |
|
- | 651 | } |
|
- | 652 | } |
|
641 | /* USER CODE END 3 */ |
653 | /* USER CODE END 3 */ |
642 | } |
654 | } |
643 | 655 | ||
644 | /** |
656 | /** |
645 | * @brief System Clock Configuration |
657 | * @brief System Clock Configuration |
646 | * @retval None |
658 | * @retval None |
647 | */ |
659 | */ |
- | 660 | void |
|
648 | void SystemClock_Config(void) |
661 | SystemClock_Config (void) |
649 | { |
662 | { |
650 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
663 | RCC_OscInitTypeDef RCC_OscInitStruct = |
- | 664 | { 0 }; |
|
651 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
665 | RCC_ClkInitTypeDef RCC_ClkInitStruct = |
- | 666 | { 0 }; |
|
652 | 667 | ||
653 | /** Configure the main internal regulator output voltage |
668 | /** Configure the main internal regulator output voltage |
654 | */ |
669 | */ |
655 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
670 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
656 | /** Initializes the RCC Oscillators according to the specified parameters |
671 | /** Initializes the RCC Oscillators according to the specified parameters |
657 | * in the RCC_OscInitTypeDef structure. |
672 | * in the RCC_OscInitTypeDef structure. |
658 | */ |
673 | */ |
659 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
674 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
660 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
675 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
661 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
676 | RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; |
662 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
677 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
663 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
678 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
664 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; |
679 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; |
665 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
680 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
666 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
681 | if (HAL_RCC_OscConfig (&RCC_OscInitStruct) != HAL_OK) |
667 | { |
682 | { |
668 | Error_Handler(); |
683 | Error_Handler (); |
669 | } |
684 | } |
670 | /** Initializes the CPU, AHB and APB buses clocks |
685 | /** Initializes the CPU, AHB and APB buses clocks |
671 | */ |
686 | */ |
672 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
687 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
673 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
688 | | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
674 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
689 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
675 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
690 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
676 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
691 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
677 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
692 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
678 | 693 | ||
679 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
694 | if (HAL_RCC_ClockConfig (&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
680 | { |
695 | { |
681 | Error_Handler(); |
696 | Error_Handler (); |
682 | } |
697 | } |
683 | } |
698 | } |
684 | 699 | ||
685 | /** |
700 | /** |
686 | * @brief ADC Initialization Function |
701 | * @brief ADC Initialization Function |
687 | * @param None |
702 | * @param None |
688 | * @retval None |
703 | * @retval None |
689 | */ |
704 | */ |
- | 705 | static void |
|
690 | static void MX_ADC_Init(void) |
706 | MX_ADC_Init (void) |
691 | { |
707 | { |
692 | 708 | ||
693 | /* USER CODE BEGIN ADC_Init 0 */ |
709 | /* USER CODE BEGIN ADC_Init 0 */ |
694 | 710 | ||
695 | /* USER CODE END ADC_Init 0 */ |
711 | /* USER CODE END ADC_Init 0 */ |
696 | 712 | ||
697 | ADC_ChannelConfTypeDef sConfig = {0}; |
713 | ADC_ChannelConfTypeDef sConfig = |
- | 714 | { 0 }; |
|
698 | 715 | ||
699 | /* USER CODE BEGIN ADC_Init 1 */ |
716 | /* USER CODE BEGIN ADC_Init 1 */ |
700 | 717 | ||
701 | /* USER CODE END ADC_Init 1 */ |
718 | /* USER CODE END ADC_Init 1 */ |
702 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
719 | /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) |
703 | */ |
720 | */ |
704 | hadc.Instance = ADC1; |
721 | hadc.Instance = ADC1; |
705 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
722 | hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; |
706 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
723 | hadc.Init.Resolution = ADC_RESOLUTION_12B; |
707 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
724 | hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
708 | hadc.Init.ScanConvMode = ADC_SCAN_ENABLE; |
725 | hadc.Init.ScanConvMode = ADC_SCAN_ENABLE; |
Line 714... | Line 731... | ||
714 | hadc.Init.NbrOfConversion = 6; |
731 | hadc.Init.NbrOfConversion = 6; |
715 | hadc.Init.DiscontinuousConvMode = DISABLE; |
732 | hadc.Init.DiscontinuousConvMode = DISABLE; |
716 | hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; |
733 | hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO; |
717 | hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; |
734 | hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; |
718 | hadc.Init.DMAContinuousRequests = ENABLE; |
735 | hadc.Init.DMAContinuousRequests = ENABLE; |
719 | if (HAL_ADC_Init(&hadc) != HAL_OK) |
736 | if (HAL_ADC_Init (&hadc) != HAL_OK) |
720 | { |
737 | { |
721 | Error_Handler(); |
738 | Error_Handler (); |
722 | } |
739 | } |
723 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
740 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
724 | */ |
741 | */ |
725 | sConfig.Channel = ADC_CHANNEL_10; |
742 | sConfig.Channel = ADC_CHANNEL_10; |
726 | sConfig.Rank = ADC_REGULAR_RANK_1; |
743 | sConfig.Rank = ADC_REGULAR_RANK_1; |
727 | sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES; |
744 | sConfig.SamplingTime = ADC_SAMPLETIME_384CYCLES; |
728 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
745 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
729 | { |
746 | { |
730 | Error_Handler(); |
747 | Error_Handler (); |
731 | } |
748 | } |
732 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
749 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
733 | */ |
750 | */ |
734 | sConfig.Channel = ADC_CHANNEL_11; |
751 | sConfig.Channel = ADC_CHANNEL_11; |
735 | sConfig.Rank = ADC_REGULAR_RANK_2; |
752 | sConfig.Rank = ADC_REGULAR_RANK_2; |
736 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
753 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
737 | { |
754 | { |
738 | Error_Handler(); |
755 | Error_Handler (); |
739 | } |
756 | } |
740 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
757 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
741 | */ |
758 | */ |
742 | sConfig.Channel = ADC_CHANNEL_12; |
759 | sConfig.Channel = ADC_CHANNEL_12; |
743 | sConfig.Rank = ADC_REGULAR_RANK_3; |
760 | sConfig.Rank = ADC_REGULAR_RANK_3; |
744 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
761 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
745 | { |
762 | { |
746 | Error_Handler(); |
763 | Error_Handler (); |
747 | } |
764 | } |
748 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
765 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
749 | */ |
766 | */ |
750 | sConfig.Channel = ADC_CHANNEL_13; |
767 | sConfig.Channel = ADC_CHANNEL_13; |
751 | sConfig.Rank = ADC_REGULAR_RANK_4; |
768 | sConfig.Rank = ADC_REGULAR_RANK_4; |
752 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
769 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
753 | { |
770 | { |
754 | Error_Handler(); |
771 | Error_Handler (); |
755 | } |
772 | } |
756 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
773 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
757 | */ |
774 | */ |
758 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
775 | sConfig.Channel = ADC_CHANNEL_TEMPSENSOR; |
759 | sConfig.Rank = ADC_REGULAR_RANK_5; |
776 | sConfig.Rank = ADC_REGULAR_RANK_5; |
760 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
777 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
761 | { |
778 | { |
762 | Error_Handler(); |
779 | Error_Handler (); |
763 | } |
780 | } |
764 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
781 | /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. |
765 | */ |
782 | */ |
766 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
783 | sConfig.Channel = ADC_CHANNEL_VREFINT; |
767 | sConfig.Rank = ADC_REGULAR_RANK_6; |
784 | sConfig.Rank = ADC_REGULAR_RANK_6; |
768 | if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) |
785 | if (HAL_ADC_ConfigChannel (&hadc, &sConfig) != HAL_OK) |
769 | { |
786 | { |
770 | Error_Handler(); |
787 | Error_Handler (); |
771 | } |
788 | } |
772 | /* USER CODE BEGIN ADC_Init 2 */ |
789 | /* USER CODE BEGIN ADC_Init 2 */ |
773 | 790 | ||
774 | /* USER CODE END ADC_Init 2 */ |
791 | /* USER CODE END ADC_Init 2 */ |
775 | 792 | ||
776 | } |
793 | } |
777 | 794 | ||
778 | /** |
795 | /** |
779 | * @brief SPI1 Initialization Function |
796 | * @brief SPI1 Initialization Function |
780 | * @param None |
797 | * @param None |
781 | * @retval None |
798 | * @retval None |
782 | */ |
799 | */ |
- | 800 | static void |
|
783 | static void MX_SPI1_Init(void) |
801 | MX_SPI1_Init (void) |
784 | { |
802 | { |
785 | 803 | ||
786 | /* USER CODE BEGIN SPI1_Init 0 */ |
804 | /* USER CODE BEGIN SPI1_Init 0 */ |
787 | 805 | ||
788 | /* USER CODE END SPI1_Init 0 */ |
806 | /* USER CODE END SPI1_Init 0 */ |
Line 801... | Line 819... | ||
801 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; |
819 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; |
802 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
820 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
803 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
821 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
804 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
822 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
805 | hspi1.Init.CRCPolynomial = 10; |
823 | hspi1.Init.CRCPolynomial = 10; |
806 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
824 | if (HAL_SPI_Init (&hspi1) != HAL_OK) |
807 | { |
825 | { |
808 | Error_Handler(); |
826 | Error_Handler (); |
809 | } |
827 | } |
810 | /* USER CODE BEGIN SPI1_Init 2 */ |
828 | /* USER CODE BEGIN SPI1_Init 2 */ |
811 | 829 | ||
812 | /* USER CODE END SPI1_Init 2 */ |
830 | /* USER CODE END SPI1_Init 2 */ |
813 | 831 | ||
814 | } |
832 | } |
815 | 833 | ||
816 | /** |
834 | /** |
817 | * @brief TIM2 Initialization Function |
835 | * @brief TIM2 Initialization Function |
818 | * @param None |
836 | * @param None |
819 | * @retval None |
837 | * @retval None |
820 | */ |
838 | */ |
- | 839 | static void |
|
821 | static void MX_TIM2_Init(void) |
840 | MX_TIM2_Init (void) |
822 | { |
841 | { |
823 | 842 | ||
824 | /* USER CODE BEGIN TIM2_Init 0 */ |
843 | /* USER CODE BEGIN TIM2_Init 0 */ |
825 | 844 | ||
826 | /* USER CODE END TIM2_Init 0 */ |
845 | /* USER CODE END TIM2_Init 0 */ |
827 | 846 | ||
828 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
847 | TIM_ClockConfigTypeDef sClockSourceConfig = |
- | 848 | { 0 }; |
|
829 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
849 | TIM_MasterConfigTypeDef sMasterConfig = |
- | 850 | { 0 }; |
|
830 | TIM_IC_InitTypeDef sConfigIC = {0}; |
851 | TIM_IC_InitTypeDef sConfigIC = |
- | 852 | { 0 }; |
|
831 | 853 | ||
832 | /* USER CODE BEGIN TIM2_Init 1 */ |
854 | /* USER CODE BEGIN TIM2_Init 1 */ |
833 | 855 | ||
834 | /* USER CODE END TIM2_Init 1 */ |
856 | /* USER CODE END TIM2_Init 1 */ |
835 | htim2.Instance = TIM2; |
857 | htim2.Instance = TIM2; |
836 | htim2.Init.Prescaler = 320; |
858 | htim2.Init.Prescaler = 320; |
837 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
859 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
838 | htim2.Init.Period = 65535; |
860 | htim2.Init.Period = 65535; |
839 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
861 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
840 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
862 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
841 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
863 | if (HAL_TIM_Base_Init (&htim2) != HAL_OK) |
842 | { |
864 | { |
843 | Error_Handler(); |
865 | Error_Handler (); |
844 | } |
866 | } |
845 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
867 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
846 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
868 | if (HAL_TIM_ConfigClockSource (&htim2, &sClockSourceConfig) != HAL_OK) |
847 | { |
869 | { |
848 | Error_Handler(); |
870 | Error_Handler (); |
849 | } |
871 | } |
850 | if (HAL_TIM_IC_Init(&htim2) != HAL_OK) |
872 | if (HAL_TIM_IC_Init (&htim2) != HAL_OK) |
851 | { |
873 | { |
852 | Error_Handler(); |
874 | Error_Handler (); |
853 | } |
875 | } |
854 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
876 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
855 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
877 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
856 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
878 | if (HAL_TIMEx_MasterConfigSynchronization (&htim2, &sMasterConfig) != HAL_OK) |
857 | { |
879 | { |
858 | Error_Handler(); |
880 | Error_Handler (); |
859 | } |
881 | } |
860 | sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE; |
882 | sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE; |
861 | sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; |
883 | sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; |
862 | sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; |
884 | sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; |
863 | sConfigIC.ICFilter = 15; |
885 | sConfigIC.ICFilter = 15; |
864 | if (HAL_TIM_IC_ConfigChannel(&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) |
886 | if (HAL_TIM_IC_ConfigChannel (&htim2, &sConfigIC, TIM_CHANNEL_1) != HAL_OK) |
865 | { |
887 | { |
866 | Error_Handler(); |
888 | Error_Handler (); |
867 | } |
889 | } |
868 | /* USER CODE BEGIN TIM2_Init 2 */ |
890 | /* USER CODE BEGIN TIM2_Init 2 */ |
869 | 891 | ||
870 | /* USER CODE END TIM2_Init 2 */ |
892 | /* USER CODE END TIM2_Init 2 */ |
871 | 893 | ||
872 | } |
894 | } |
873 | 895 | ||
874 | /** |
896 | /** |
875 | * @brief TIM3 Initialization Function |
897 | * @brief TIM3 Initialization Function |
876 | * @param None |
898 | * @param None |
877 | * @retval None |
899 | * @retval None |
878 | */ |
900 | */ |
- | 901 | static void |
|
879 | static void MX_TIM3_Init(void) |
902 | MX_TIM3_Init (void) |
880 | { |
903 | { |
881 | 904 | ||
882 | /* USER CODE BEGIN TIM3_Init 0 */ |
905 | /* USER CODE BEGIN TIM3_Init 0 */ |
883 | 906 | ||
884 | /* USER CODE END TIM3_Init 0 */ |
907 | /* USER CODE END TIM3_Init 0 */ |
885 | 908 | ||
886 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
909 | TIM_ClockConfigTypeDef sClockSourceConfig = |
- | 910 | { 0 }; |
|
887 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
911 | TIM_MasterConfigTypeDef sMasterConfig = |
- | 912 | { 0 }; |
|
888 | TIM_OC_InitTypeDef sConfigOC = {0}; |
913 | TIM_OC_InitTypeDef sConfigOC = |
- | 914 | { 0 }; |
|
889 | 915 | ||
890 | /* USER CODE BEGIN TIM3_Init 1 */ |
916 | /* USER CODE BEGIN TIM3_Init 1 */ |
891 | 917 | ||
892 | /* USER CODE END TIM3_Init 1 */ |
918 | /* USER CODE END TIM3_Init 1 */ |
893 | htim3.Instance = TIM3; |
919 | htim3.Instance = TIM3; |
894 | htim3.Init.Prescaler = 320; |
920 | htim3.Init.Prescaler = 320; |
895 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
921 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
896 | htim3.Init.Period = 1000; |
922 | htim3.Init.Period = 1000; |
897 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
923 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
898 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
924 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
899 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK) |
925 | if (HAL_TIM_Base_Init (&htim3) != HAL_OK) |
900 | { |
926 | { |
901 | Error_Handler(); |
927 | Error_Handler (); |
902 | } |
928 | } |
903 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
929 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
904 | if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) |
930 | if (HAL_TIM_ConfigClockSource (&htim3, &sClockSourceConfig) != HAL_OK) |
905 | { |
931 | { |
906 | Error_Handler(); |
932 | Error_Handler (); |
907 | } |
933 | } |
908 | if (HAL_TIM_OC_Init(&htim3) != HAL_OK) |
934 | if (HAL_TIM_OC_Init (&htim3) != HAL_OK) |
909 | { |
935 | { |
910 | Error_Handler(); |
936 | Error_Handler (); |
911 | } |
937 | } |
912 | if (HAL_TIM_OnePulse_Init(&htim3, TIM_OPMODE_SINGLE) != HAL_OK) |
938 | if (HAL_TIM_OnePulse_Init (&htim3, TIM_OPMODE_SINGLE) != HAL_OK) |
913 | { |
939 | { |
914 | Error_Handler(); |
940 | Error_Handler (); |
915 | } |
941 | } |
916 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1; |
942 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC1; |
917 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
943 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
918 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
944 | if (HAL_TIMEx_MasterConfigSynchronization (&htim3, &sMasterConfig) != HAL_OK) |
919 | { |
945 | { |
920 | Error_Handler(); |
946 | Error_Handler (); |
921 | } |
947 | } |
922 | sConfigOC.OCMode = TIM_OCMODE_TIMING; |
948 | sConfigOC.OCMode = TIM_OCMODE_TIMING; |
923 | sConfigOC.Pulse = 1000; |
949 | sConfigOC.Pulse = 1000; |
924 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
950 | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
925 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
951 | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
926 | if (HAL_TIM_OC_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
952 | if (HAL_TIM_OC_ConfigChannel (&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) |
927 | { |
953 | { |
928 | Error_Handler(); |
954 | Error_Handler (); |
929 | } |
955 | } |
930 | /* USER CODE BEGIN TIM3_Init 2 */ |
956 | /* USER CODE BEGIN TIM3_Init 2 */ |
931 | 957 | ||
932 | /* USER CODE END TIM3_Init 2 */ |
958 | /* USER CODE END TIM3_Init 2 */ |
933 | HAL_TIM_MspPostInit(&htim3); |
959 | HAL_TIM_MspPostInit (&htim3); |
934 | 960 | ||
935 | } |
961 | } |
936 | 962 | ||
937 | /** |
963 | /** |
938 | * @brief TIM6 Initialization Function |
964 | * @brief TIM6 Initialization Function |
939 | * @param None |
965 | * @param None |
940 | * @retval None |
966 | * @retval None |
941 | */ |
967 | */ |
- | 968 | static void |
|
942 | static void MX_TIM6_Init(void) |
969 | MX_TIM6_Init (void) |
943 | { |
970 | { |
944 | 971 | ||
945 | /* USER CODE BEGIN TIM6_Init 0 */ |
972 | /* USER CODE BEGIN TIM6_Init 0 */ |
946 | 973 | ||
947 | /* USER CODE END TIM6_Init 0 */ |
974 | /* USER CODE END TIM6_Init 0 */ |
948 | 975 | ||
949 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
976 | TIM_MasterConfigTypeDef sMasterConfig = |
- | 977 | { 0 }; |
|
950 | 978 | ||
951 | /* USER CODE BEGIN TIM6_Init 1 */ |
979 | /* USER CODE BEGIN TIM6_Init 1 */ |
952 | 980 | ||
953 | /* USER CODE END TIM6_Init 1 */ |
981 | /* USER CODE END TIM6_Init 1 */ |
954 | htim6.Instance = TIM6; |
982 | htim6.Instance = TIM6; |
955 | htim6.Init.Prescaler = 320; |
983 | htim6.Init.Prescaler = 320; |
956 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
984 | htim6.Init.CounterMode = TIM_COUNTERMODE_UP; |
957 | htim6.Init.Period = 9999; |
985 | htim6.Init.Period = 9999; |
958 | htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
986 | htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
959 | if (HAL_TIM_Base_Init(&htim6) != HAL_OK) |
987 | if (HAL_TIM_Base_Init (&htim6) != HAL_OK) |
960 | { |
988 | { |
961 | Error_Handler(); |
989 | Error_Handler (); |
962 | } |
990 | } |
963 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
991 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE; |
964 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
992 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
965 | if (HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig) != HAL_OK) |
993 | if (HAL_TIMEx_MasterConfigSynchronization (&htim6, &sMasterConfig) != HAL_OK) |
966 | { |
994 | { |
967 | Error_Handler(); |
995 | Error_Handler (); |
968 | } |
996 | } |
969 | /* USER CODE BEGIN TIM6_Init 2 */ |
997 | /* USER CODE BEGIN TIM6_Init 2 */ |
970 | 998 | ||
971 | /* USER CODE END TIM6_Init 2 */ |
999 | /* USER CODE END TIM6_Init 2 */ |
972 | 1000 | ||
973 | } |
1001 | } |
974 | 1002 | ||
975 | /** |
1003 | /** |
976 | * @brief USART1 Initialization Function |
1004 | * @brief USART1 Initialization Function |
977 | * @param None |
1005 | * @param None |
978 | * @retval None |
1006 | * @retval None |
979 | */ |
1007 | */ |
- | 1008 | static void |
|
980 | static void MX_USART1_UART_Init(void) |
1009 | MX_USART1_UART_Init (void) |
981 | { |
1010 | { |
982 | 1011 | ||
983 | /* USER CODE BEGIN USART1_Init 0 */ |
1012 | /* USER CODE BEGIN USART1_Init 0 */ |
984 | 1013 | ||
985 | /* USER CODE END USART1_Init 0 */ |
1014 | /* USER CODE END USART1_Init 0 */ |
Line 993... | Line 1022... | ||
993 | huart1.Init.StopBits = UART_STOPBITS_1; |
1022 | huart1.Init.StopBits = UART_STOPBITS_1; |
994 | huart1.Init.Parity = UART_PARITY_NONE; |
1023 | huart1.Init.Parity = UART_PARITY_NONE; |
995 | huart1.Init.Mode = UART_MODE_TX_RX; |
1024 | huart1.Init.Mode = UART_MODE_TX_RX; |
996 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
1025 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
997 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
1026 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
998 | if (HAL_UART_Init(&huart1) != HAL_OK) |
1027 | if (HAL_UART_Init (&huart1) != HAL_OK) |
999 | { |
1028 | { |
1000 | Error_Handler(); |
1029 | Error_Handler (); |
1001 | } |
1030 | } |
1002 | /* USER CODE BEGIN USART1_Init 2 */ |
1031 | /* USER CODE BEGIN USART1_Init 2 */ |
1003 | 1032 | ||
1004 | /* USER CODE END USART1_Init 2 */ |
1033 | /* USER CODE END USART1_Init 2 */ |
1005 | 1034 | ||
1006 | } |
1035 | } |
1007 | 1036 | ||
1008 | /** |
1037 | /** |
1009 | * @brief USART2 Initialization Function |
1038 | * @brief USART2 Initialization Function |
1010 | * @param None |
1039 | * @param None |
1011 | * @retval None |
1040 | * @retval None |
1012 | */ |
1041 | */ |
- | 1042 | static void |
|
1013 | static void MX_USART2_UART_Init(void) |
1043 | MX_USART2_UART_Init (void) |
1014 | { |
1044 | { |
1015 | 1045 | ||
1016 | /* USER CODE BEGIN USART2_Init 0 */ |
1046 | /* USER CODE BEGIN USART2_Init 0 */ |
1017 | 1047 | ||
1018 | /* USER CODE END USART2_Init 0 */ |
1048 | /* USER CODE END USART2_Init 0 */ |
Line 1026... | Line 1056... | ||
1026 | huart2.Init.StopBits = UART_STOPBITS_1; |
1056 | huart2.Init.StopBits = UART_STOPBITS_1; |
1027 | huart2.Init.Parity = UART_PARITY_NONE; |
1057 | huart2.Init.Parity = UART_PARITY_NONE; |
1028 | huart2.Init.Mode = UART_MODE_TX_RX; |
1058 | huart2.Init.Mode = UART_MODE_TX_RX; |
1029 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
1059 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
1030 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
1060 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
1031 | if (HAL_UART_Init(&huart2) != HAL_OK) |
1061 | if (HAL_UART_Init (&huart2) != HAL_OK) |
1032 | { |
1062 | { |
1033 | Error_Handler(); |
1063 | Error_Handler (); |
1034 | } |
1064 | } |
1035 | /* USER CODE BEGIN USART2_Init 2 */ |
1065 | /* USER CODE BEGIN USART2_Init 2 */ |
1036 | 1066 | ||
1037 | /* USER CODE END USART2_Init 2 */ |
1067 | /* USER CODE END USART2_Init 2 */ |
1038 | 1068 | ||
1039 | } |
1069 | } |
1040 | 1070 | ||
1041 | /** |
1071 | /** |
1042 | * Enable DMA controller clock |
1072 | * Enable DMA controller clock |
1043 | */ |
1073 | */ |
- | 1074 | static void |
|
1044 | static void MX_DMA_Init(void) |
1075 | MX_DMA_Init (void) |
1045 | { |
1076 | { |
1046 | 1077 | ||
1047 | /* DMA controller clock enable */ |
1078 | /* DMA controller clock enable */ |
1048 | __HAL_RCC_DMA1_CLK_ENABLE(); |
1079 | __HAL_RCC_DMA1_CLK_ENABLE(); |
1049 | 1080 | ||
1050 | /* DMA interrupt init */ |
1081 | /* DMA interrupt init */ |
1051 | /* DMA1_Channel1_IRQn interrupt configuration */ |
1082 | /* DMA1_Channel1_IRQn interrupt configuration */ |
1052 | HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 0, 0); |
1083 | HAL_NVIC_SetPriority (DMA1_Channel1_IRQn, 0, 0); |
1053 | HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); |
1084 | HAL_NVIC_EnableIRQ (DMA1_Channel1_IRQn); |
1054 | 1085 | ||
1055 | } |
1086 | } |
1056 | 1087 | ||
1057 | /** |
1088 | /** |
1058 | * @brief GPIO Initialization Function |
1089 | * @brief GPIO Initialization Function |
1059 | * @param None |
1090 | * @param None |
1060 | * @retval None |
1091 | * @retval None |
1061 | */ |
1092 | */ |
- | 1093 | static void |
|
1062 | static void MX_GPIO_Init(void) |
1094 | MX_GPIO_Init (void) |
1063 | { |
1095 | { |
1064 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
1096 | GPIO_InitTypeDef GPIO_InitStruct = |
- | 1097 | { 0 }; |
|
1065 | 1098 | ||
1066 | /* GPIO Ports Clock Enable */ |
1099 | /* GPIO Ports Clock Enable */ |
1067 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
1100 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
1068 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
1101 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
1069 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
1102 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
1070 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
1103 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
1071 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
1104 | __HAL_RCC_GPIOD_CLK_ENABLE(); |
1072 | 1105 | ||
1073 | /*Configure GPIO pin Output Level */ |
1106 | /*Configure GPIO pin Output Level */ |
1074 | HAL_GPIO_WritePin(LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
1107 | HAL_GPIO_WritePin (LED_Blink_GPIO_Port, LED_Blink_Pin, GPIO_PIN_RESET); |
1075 | 1108 | ||
1076 | /*Configure GPIO pin Output Level */ |
1109 | /*Configure GPIO pin Output Level */ |
1077 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
1110 | HAL_GPIO_WritePin (SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
1078 | 1111 | ||
1079 | /*Configure GPIO pin Output Level */ |
1112 | /*Configure GPIO pin Output Level */ |
1080 | HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
1113 | HAL_GPIO_WritePin (SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET); |
1081 | 1114 | ||
1082 | /*Configure GPIO pin Output Level */ |
1115 | /*Configure GPIO pin Output Level */ |
1083 | HAL_GPIO_WritePin(GPIOB, SPI_RESET_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin, GPIO_PIN_RESET); |
1116 | HAL_GPIO_WritePin (GPIOB, SPI_RESET_Pin | SPI_NS_Temp2_Pin | ENA_AUX_5V_Pin, |
- | 1117 | GPIO_PIN_RESET); |
|
1084 | 1118 | ||
1085 | /*Configure GPIO pin Output Level */ |
1119 | /*Configure GPIO pin Output Level */ |
1086 | HAL_GPIO_WritePin(SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
1120 | HAL_GPIO_WritePin (SPI_NS_Temp_GPIO_Port, SPI_NS_Temp_Pin, GPIO_PIN_SET); |
1087 | 1121 | ||
1088 | /*Configure GPIO pins : PC13 PC14 PC15 PC7 |
1122 | /*Configure GPIO pins : PC13 PC14 PC15 PC7 |
1089 | PC8 PC9 PC11 PC12 */ |
1123 | PC8 PC9 PC11 PC12 */ |
1090 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15|GPIO_PIN_7 |
1124 | GPIO_InitStruct.Pin = GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15 | GPIO_PIN_7 |
1091 | |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_11|GPIO_PIN_12; |
1125 | | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_11 | GPIO_PIN_12; |
1092 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1126 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1093 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1127 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1094 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
1128 | HAL_GPIO_Init (GPIOC, &GPIO_InitStruct); |
1095 | 1129 | ||
1096 | /*Configure GPIO pins : PH0 PH1 */ |
1130 | /*Configure GPIO pins : PH0 PH1 */ |
1097 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; |
1131 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; |
1098 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1132 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1099 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1133 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1100 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
1134 | HAL_GPIO_Init (GPIOH, &GPIO_InitStruct); |
1101 | 1135 | ||
1102 | /*Configure GPIO pins : PA0 PA1 PA8 PA11 |
1136 | /*Configure GPIO pins : PA0 PA1 PA8 PA11 |
1103 | PA12 */ |
1137 | PA12 */ |
1104 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11 |
1138 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_8 | GPIO_PIN_11 |
1105 | |GPIO_PIN_12; |
1139 | | GPIO_PIN_12; |
1106 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1140 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1107 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1141 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1108 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
1142 | HAL_GPIO_Init (GPIOA, &GPIO_InitStruct); |
1109 | 1143 | ||
1110 | /*Configure GPIO pin : LED_Blink_Pin */ |
1144 | /*Configure GPIO pin : LED_Blink_Pin */ |
1111 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
1145 | GPIO_InitStruct.Pin = LED_Blink_Pin; |
1112 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1146 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1113 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1147 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1114 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
1148 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
1115 | HAL_GPIO_Init(LED_Blink_GPIO_Port, &GPIO_InitStruct); |
1149 | HAL_GPIO_Init (LED_Blink_GPIO_Port, &GPIO_InitStruct); |
1116 | 1150 | ||
1117 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
1151 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
1118 | GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI_CD_Pin; |
1152 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_CD_Pin; |
1119 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1153 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1120 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1154 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1121 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1155 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1122 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
1156 | HAL_GPIO_Init (GPIOC, &GPIO_InitStruct); |
1123 | 1157 | ||
1124 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NS_Temp_Pin SPI_NS_Temp2_Pin ENA_AUX_5V_Pin */ |
1158 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NS_Temp_Pin SPI_NS_Temp2_Pin ENA_AUX_5V_Pin */ |
1125 | GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NS_Temp_Pin|SPI_NS_Temp2_Pin|ENA_AUX_5V_Pin; |
1159 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NS_Temp_Pin | SPI_NS_Temp2_Pin |
- | 1160 | | ENA_AUX_5V_Pin; |
|
1126 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1161 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
1127 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1162 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1128 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1163 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
1129 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1164 | HAL_GPIO_Init (GPIOB, &GPIO_InitStruct); |
1130 | 1165 | ||
1131 | /*Configure GPIO pins : PB11 PB12 PB13 PB14 |
1166 | /*Configure GPIO pins : PB11 PB12 PB13 PB14 |
1132 | PB15 PB3 PB4 PB5 |
1167 | PB15 PB3 PB4 PB5 |
1133 | PB6 PB7 PB8 PB9 */ |
1168 | PB6 PB7 PB8 PB9 */ |
1134 | GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14 |
1169 | GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |
1135 | |GPIO_PIN_15|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5 |
1170 | | GPIO_PIN_15 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
1136 | |GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9; |
1171 | | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9; |
1137 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1172 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1138 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1173 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1139 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
1174 | HAL_GPIO_Init (GPIOB, &GPIO_InitStruct); |
1140 | 1175 | ||
1141 | /*Configure GPIO pin : STARTER_ON_Pin */ |
1176 | /*Configure GPIO pin : STARTER_ON_Pin */ |
1142 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
1177 | GPIO_InitStruct.Pin = STARTER_ON_Pin; |
1143 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
1178 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
1144 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1179 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1145 | HAL_GPIO_Init(STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
1180 | HAL_GPIO_Init (STARTER_ON_GPIO_Port, &GPIO_InitStruct); |
1146 | 1181 | ||
1147 | /*Configure GPIO pin : PD2 */ |
1182 | /*Configure GPIO pin : PD2 */ |
1148 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
1183 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
1149 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1184 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1150 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1185 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
1151 | HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); |
1186 | HAL_GPIO_Init (GPIOD, &GPIO_InitStruct); |
1152 | 1187 | ||
1153 | } |
1188 | } |
1154 | 1189 | ||
1155 | /* USER CODE BEGIN 4 */ |
1190 | /* USER CODE BEGIN 4 */ |
1156 | 1191 | ||
1157 | /* USER CODE END 4 */ |
1192 | /* USER CODE END 4 */ |
1158 | 1193 | ||
1159 | /** |
1194 | /** |
1160 | * @brief This function is executed in case of error occurrence. |
1195 | * @brief This function is executed in case of error occurrence. |
1161 | * @retval None |
1196 | * @retval None |
1162 | */ |
1197 | */ |
- | 1198 | void |
|
1163 | void Error_Handler(void) |
1199 | Error_Handler (void) |
1164 | { |
1200 | { |
1165 | /* USER CODE BEGIN Error_Handler_Debug */ |
1201 | /* USER CODE BEGIN Error_Handler_Debug */ |
1166 | /* User can add his own implementation to report the HAL error return state */ |
1202 | /* User can add his own implementation to report the HAL error return state */ |
1167 | 1203 | ||
1168 | /* USER CODE END Error_Handler_Debug */ |
1204 | /* USER CODE END Error_Handler_Debug */ |