Rev 31 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 31 | Rev 32 | ||
---|---|---|---|
Line 62... | Line 62... | ||
62 | { |
62 | { |
63 | uint8_t dev_addr; |
63 | uint8_t dev_addr; |
64 | } interface_t; |
64 | } interface_t; |
65 | 65 | ||
66 | static int8_t |
66 | static int8_t |
67 | user_i2c_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
67 | user_i2c_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
68 | uint32_t len) |
68 | uint32_t len) |
69 | { |
69 | { |
70 | HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c2, i2c_addr << 1, reg_addr, 1, |
70 | HAL_StatusTypeDef st = HAL_I2C_Mem_Write(&hi2c2, i2c_addr << 1, reg_addr, 1, |
71 | reg_data, len, 1000); |
71 | reg_data, len, 1000); |
72 | 72 | ||
73 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
73 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
74 | - | ||
75 | } |
74 | } |
76 | static int8_t |
75 | static int8_t |
77 | user_i2c_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
76 | user_i2c_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
78 | uint32_t len) |
77 | uint32_t len) |
79 | { |
78 | { |
80 | HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c2, i2c_addr << 1, reg_addr, 1, |
79 | HAL_StatusTypeDef st = HAL_I2C_Mem_Read(&hi2c2, i2c_addr << 1, reg_addr, 1, |
81 | reg_data, len, 1000); |
80 | reg_data, len, 1000); |
82 | 81 | ||
83 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
82 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
84 | - | ||
85 | } |
83 | } |
86 | // the second I2C bus is I2C1, this is used for the external I2C thermometer to avoid problems with noise pickup . |
84 | // the second I2C bus is I2C1, this is used for the external I2C thermometer to avoid problems with noise pickup . |
87 | static int8_t |
85 | static int8_t |
88 | user_i2c2_write (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
86 | user_i2c2_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
89 | uint32_t len) |
87 | uint32_t len) |
90 | { |
88 | { |
91 | HAL_StatusTypeDef st = HAL_I2C_Mem_Write (&hi2c1, i2c_addr << 1, reg_addr, 1, |
89 | HAL_StatusTypeDef st = HAL_I2C_Mem_Write(&hi2c1, i2c_addr << 1, reg_addr, 1, |
92 | reg_data, len, 1000); |
90 | reg_data, len, 1000); |
93 | 91 | ||
94 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
92 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
95 | - | ||
96 | } |
93 | } |
97 | static int8_t |
94 | static int8_t |
98 | user_i2c2_read (uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
95 | user_i2c2_read(uint8_t i2c_addr, uint8_t reg_addr, uint8_t *reg_data, |
99 | uint32_t len) |
96 | uint32_t len) |
100 | { |
97 | { |
101 | HAL_StatusTypeDef st = HAL_I2C_Mem_Read (&hi2c1, i2c_addr << 1, reg_addr, 1, |
98 | HAL_StatusTypeDef st = HAL_I2C_Mem_Read(&hi2c1, i2c_addr << 1, reg_addr, 1, |
102 | reg_data, len, 1000); |
99 | reg_data, len, 1000); |
103 | 100 | ||
104 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
101 | return st != HAL_OK ? BMP280_E_COMM_FAIL : BMP280_OK; |
105 | - | ||
106 | } |
102 | } |
107 | 103 | ||
108 | - | ||
109 | static void |
104 | static void |
110 | user_delay_ms (uint32_t ms, void *handle) |
105 | user_delay_ms(uint32_t ms, void *handle) |
111 | { |
106 | { |
112 | HAL_Delay (ms); |
107 | HAL_Delay(ms); |
113 | - | ||
114 | } |
108 | } |
115 | 109 | ||
116 | struct bmp280_dev bmp = |
110 | struct bmp280_dev bmp = |
117 | { |
111 | { |
118 | .intf = BMP280_I2C_INTF, |
112 | .intf = BMP280_I2C_INTF, |
119 | .read = user_i2c_read, |
113 | .read = user_i2c_read, |
120 | .write = user_i2c_write, |
114 | .write = user_i2c_write, |
121 | .delay_ms = user_delay_ms, |
115 | .delay_ms = user_delay_ms, |
122 | 116 | ||
123 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
117 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
124 | .dev_id = BMP280_I2C_ADDR_PRIM |
118 | .dev_id = BMP280_I2C_ADDR_PRIM}; |
125 | }; |
- | |
126 | 119 | ||
127 | struct bmp280_dev bmp2 = |
120 | struct bmp280_dev bmp2 = |
128 | { |
121 | { |
129 | .intf = BMP280_I2C_INTF, |
122 | .intf = BMP280_I2C_INTF, |
130 | .read = user_i2c2_read, |
123 | .read = user_i2c2_read, |
131 | .write = user_i2c2_write, |
124 | .write = user_i2c2_write, |
132 | .delay_ms = user_delay_ms, |
125 | .delay_ms = user_delay_ms, |
133 | - | ||
134 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
- | |
135 | .dev_id = BMP280_I2C_ADDR_SEC |
- | |
136 | }; |
- | |
137 | 126 | ||
- | 127 | /* Update interface pointer with the structure that contains both device address and file descriptor */ |
|
138 | int8_t rslt; |
128 | .dev_id = BMP280_I2C_ADDR_SEC}; |
139 | 129 | ||
- | 130 | int8_t rslt; |
|
140 | 131 | ||
141 | struct bmp280_config conf; |
132 | struct bmp280_config conf; |
142 | struct bmp280_config conf2; |
133 | struct bmp280_config conf2; |
143 | 134 | ||
144 | /* USER CODE END PV */ |
135 | /* USER CODE END PV */ |
Line 162... | Line 153... | ||
162 | /* USER CODE BEGIN 0 */ |
153 | /* USER CODE BEGIN 0 */ |
163 | 154 | ||
164 | uint32_t const TICKS_LOOP = 50; // 50mS per loop. |
155 | uint32_t const TICKS_LOOP = 50; // 50mS per loop. |
165 | 156 | ||
166 | // initialise the BMP |
157 | // initialise the BMP |
167 | uint8_t init_bmp(struct bmp280_config * conf, struct bmp280_dev * bmp ) |
158 | uint8_t init_bmp(struct bmp280_config *conf, struct bmp280_dev *bmp) |
168 | { |
159 | { |
169 | rslt = bmp280_init(bmp); |
160 | rslt = bmp280_init(bmp); |
170 | if (rslt != BMP280_OK) |
161 | if (rslt != BMP280_OK) |
171 | return rslt; |
162 | return rslt; |
172 | 163 | ||
173 | rslt = bmp280_get_config (conf, bmp); |
164 | rslt = bmp280_get_config(conf, bmp); |
174 | if (rslt != BMP280_OK) |
165 | if (rslt != BMP280_OK) |
175 | return rslt; |
166 | return rslt; |
176 | /* configuring the temperature oversampling, filter coefficient and output data rate */ |
167 | /* configuring the temperature oversampling, filter coefficient and output data rate */ |
177 | /* Overwrite the desired settings */ |
168 | /* Overwrite the desired settings */ |
178 | conf->filter = BMP280_FILTER_COEFF_2; |
169 | conf->filter = BMP280_FILTER_COEFF_2; |
Line 183... | Line 174... | ||
183 | /* Pressure over sampling none (disabling pressure measurement) */ |
174 | /* Pressure over sampling none (disabling pressure measurement) */ |
184 | conf->os_pres = BMP280_OS_4X; |
175 | conf->os_pres = BMP280_OS_4X; |
185 | 176 | ||
186 | /* Setting the output data rate as 2HZ(500ms) */ |
177 | /* Setting the output data rate as 2HZ(500ms) */ |
187 | conf->odr = BMP280_ODR_500_MS; |
178 | conf->odr = BMP280_ODR_500_MS; |
188 | rslt = bmp280_set_config (conf, bmp); |
179 | rslt = bmp280_set_config(conf, bmp); |
189 | if (rslt != BMP280_OK) |
180 | if (rslt != BMP280_OK) |
190 | return rslt; |
181 | return rslt; |
191 | 182 | ||
192 | /* Always set the power mode after setting the configuration */ |
183 | /* Always set the power mode after setting the configuration */ |
193 | rslt = bmp280_set_power_mode (BMP280_NORMAL_MODE, bmp); |
184 | rslt = bmp280_set_power_mode(BMP280_NORMAL_MODE, bmp); |
194 | if (rslt != BMP280_OK) |
185 | if (rslt != BMP280_OK) |
195 | return rslt; |
186 | return rslt; |
196 | - | ||
197 | } |
187 | } |
198 | 188 | ||
199 | - | ||
200 | /////////////////////////////////////// |
189 | /////////////////////////////////////// |
201 | // code dealing with I2C1 |
190 | // code dealing with I2C1 |
202 | static void reset_I2C1(void) |
191 | static void reset_I2C1(void) |
203 | { |
192 | { |
204 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
193 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
205 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_8, GPIO_PIN_SET); |
194 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); |
206 | __HAL_AFIO_REMAP_I2C1_DISABLE(); |
195 | __HAL_AFIO_REMAP_I2C1_DISABLE(); |
207 | int i; |
196 | int i; |
208 | // clock 18 times |
197 | // clock 18 times |
209 | for (i=0;i<18;++i) |
198 | for (i = 0; i < 18; ++i) |
210 | { |
199 | { |
211 | HAL_Delay (1); |
200 | HAL_Delay(1); |
212 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
201 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
213 | HAL_Delay (1); |
202 | HAL_Delay(1); |
214 | HAL_GPIO_WritePin ( GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
203 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_9, GPIO_PIN_SET); |
215 | } |
204 | } |
216 | __HAL_AFIO_REMAP_I2C1_ENABLE(); |
205 | __HAL_AFIO_REMAP_I2C1_ENABLE(); |
217 | - | ||
218 | } |
206 | } |
219 | 207 | ||
220 | // the bus power also takes down the pullup power |
208 | // the bus power also takes down the pullup power |
221 | static void power_I2C1(uint8_t power) |
209 | static void power_I2C1(uint8_t power) |
222 | { |
210 | { |
223 | if(power) |
211 | if (power) |
224 | { |
212 | { |
225 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
213 | HAL_GPIO_WritePin(I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
226 | } |
214 | } |
227 | else |
215 | else |
228 | { |
216 | { |
229 | HAL_GPIO_WritePin (I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_RESET); |
217 | HAL_GPIO_WritePin(I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_RESET); |
230 | } |
218 | } |
231 | } |
219 | } |
232 | 220 | ||
233 | typedef enum |
221 | typedef enum |
234 | { |
222 | { |
235 | BMP_NORMAL, // normal operations |
223 | BMP_NORMAL, // normal operations |
236 | BMP_RESET_ACTIVE, // powering down |
224 | BMP_RESET_ACTIVE, // powering down |
237 | BMP_PAUSE // pause after powerup |
225 | BMP_PAUSE // pause after powerup |
238 | } bmp2state_t; |
226 | } bmp2state_t; |
239 | 227 | ||
240 | bmp2state_t bmp2state; |
228 | bmp2state_t bmp2state; |
241 | unsigned bmp2nextTime; |
229 | unsigned bmp2nextTime; |
242 | unsigned bmp2offset; |
230 | unsigned bmp2offset; |
243 | 231 | ||
244 | void initBmp2(void) |
232 | void initBmp2(void) |
245 | { |
233 | { |
246 | power_I2C1(1); |
234 | power_I2C1(1); |
247 | init_bmp(&conf2,&bmp2); |
235 | init_bmp(&conf2, &bmp2); |
248 | bmp2state = BMP_NORMAL; |
236 | bmp2state = BMP_NORMAL; |
249 | bmp2nextTime = 0; |
237 | bmp2nextTime = 0; |
250 | bmp2offset = 0; |
238 | bmp2offset = 0; |
251 | } |
239 | } |
252 | 240 | ||
253 | void resetBmp2(void) |
241 | void resetBmp2(void) |
254 | { |
242 | { |
255 | reset_I2C1(); // physically reset the hardware |
243 | reset_I2C1(); // physically reset the hardware |
256 | power_I2C1(0); // power down the bus and devices |
244 | power_I2C1(0); // power down the bus and devices |
257 | bmp2nextTime = HAL_GetTick(); // 600 milliseconds hold the bus reset for |
245 | bmp2nextTime = HAL_GetTick(); // 600 milliseconds hold the bus reset for |
258 | bmp2offset = 600; |
246 | bmp2offset = 600; |
259 | bmp2state = BMP_RESET_ACTIVE; |
247 | bmp2state = BMP_RESET_ACTIVE; |
260 | } |
248 | } |
261 | 249 | ||
262 | uint8_t pollBmp2State(void) |
250 | uint8_t pollBmp2State(void) |
263 | { |
251 | { |
264 | if (bmp2state == BMP_NORMAL) |
252 | if (bmp2state == BMP_NORMAL) |
265 | return 1; |
253 | return 1; |
266 | 254 | ||
267 | if (HAL_GetTick()-bmp2offset < bmp2nextTime) |
255 | if (HAL_GetTick() - bmp2offset < bmp2nextTime) |
268 | return 0; // currently timer running |
256 | return 0; // currently timer running |
269 | switch (bmp2state) |
257 | switch (bmp2state) |
270 | { |
258 | { |
271 | // at the end of the period, take action |
259 | // at the end of the period, take action |
272 | case BMP_RESET_ACTIVE: |
260 | case BMP_RESET_ACTIVE: |
273 | power_I2C1(1); |
261 | power_I2C1(1); |
274 | bmp2nextTime = HAL_GetTick(); |
262 | bmp2nextTime = HAL_GetTick(); |
275 | bmp2offset = 200; // power up and wait for 200 milliseconds |
263 | bmp2offset = 200; // power up and wait for 200 milliseconds |
276 | bmp2state = BMP_PAUSE; |
264 | bmp2state = BMP_PAUSE; |
277 | break; |
265 | break; |
278 | case BMP_PAUSE: |
266 | case BMP_PAUSE: |
279 | init_bmp(&conf2,&bmp2); |
267 | init_bmp(&conf2, &bmp2); |
280 | bmp2state = BMP_NORMAL; |
268 | bmp2state = BMP_NORMAL; |
281 | return 1; // now in normal operation |
269 | return 1; // now in normal operation |
282 | // can not get here in normal operation |
270 | // can not get here in normal operation |
283 | case BMP_NORMAL: |
271 | case BMP_NORMAL: |
284 | return 1; |
272 | return 1; |
285 | } |
273 | } |
286 | return 0; |
274 | return 0; |
287 | } |
275 | } |
288 | 276 | ||
289 | - | ||
290 | - | ||
291 | /* USER CODE END 0 */ |
277 | /* USER CODE END 0 */ |
292 | 278 | ||
293 | /** |
279 | /** |
294 | * @brief The application entry point. |
280 | * @brief The application entry point. |
295 | * @retval int |
281 | * @retval int |
296 | */ |
282 | */ |
297 | int main(void) |
283 | int main(void) |
298 | { |
284 | { |
299 | /* USER CODE BEGIN 1 */ |
285 | /* USER CODE BEGIN 1 */ |
300 | 286 | ||
301 | /* USER CODE END 1 */ |
287 | /* USER CODE END 1 */ |
Line 327... | Line 313... | ||
327 | MX_USB_DEVICE_Init(); |
313 | MX_USB_DEVICE_Init(); |
328 | MX_IWDG_Init(); |
314 | MX_IWDG_Init(); |
329 | MX_I2C1_Init(); |
315 | MX_I2C1_Init(); |
330 | /* USER CODE BEGIN 2 */ |
316 | /* USER CODE BEGIN 2 */ |
331 | 317 | ||
332 | HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET); |
318 | HAL_GPIO_WritePin(USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_RESET); |
333 | HAL_Delay (1000); |
319 | HAL_Delay(1000); |
334 | HAL_GPIO_WritePin ( USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET); |
320 | HAL_GPIO_WritePin(USB_PULLUP_GPIO_Port, USB_PULLUP_Pin, GPIO_PIN_SET); |
335 | /* setup the USART control blocks */ |
321 | /* setup the USART control blocks */ |
336 | 322 | ||
337 | #if defined SERIAL_UART1 |
323 | #if defined SERIAL_UART1 |
338 | init_usart_ctl (&uc1, &huart1); |
324 | init_usart_ctl(&uc1, &huart1); |
339 | - | ||
340 | 325 | ||
341 | EnableSerialRxInterrupt (&uc1); |
326 | EnableSerialRxInterrupt(&uc1); |
342 | 327 | ||
343 | #endif |
328 | #endif |
344 | 329 | ||
345 | init_bmp(&conf,&bmp); |
330 | init_bmp(&conf, &bmp); |
346 | initBmp2(); |
331 | initBmp2(); |
347 | 332 | ||
348 | cc_init (); |
333 | cc_init(); |
349 | - | ||
350 | 334 | ||
351 | uint32_t timeNext = HAL_GetTick () + TICKS_LOOP; |
335 | uint32_t timeNext = HAL_GetTick() + TICKS_LOOP; |
352 | 336 | ||
353 | /* USER CODE END 2 */ |
337 | /* USER CODE END 2 */ |
354 | 338 | ||
355 | /* Infinite loop */ |
339 | /* Infinite loop */ |
356 | /* USER CODE BEGIN WHILE */ |
340 | /* USER CODE BEGIN WHILE */ |
357 | while (1) |
341 | while (1) |
358 | { |
342 | { |
359 | uint32_t timeNow = HAL_GetTick (); |
343 | uint32_t timeNow = HAL_GetTick(); |
360 | - | ||
361 | if (timeNow < timeNext) |
- | |
362 | HAL_Delay (timeNext - timeNow); |
- | |
363 | timeNext += TICKS_LOOP; |
- | |
364 | cc_run (&bmp, &bmp2); |
- | |
365 | 344 | ||
366 | // refresh watchdog timer |
345 | if (timeNow < timeNext) |
367 | HAL_IWDG_Refresh(&hiwdg); |
346 | HAL_Delay(timeNext - timeNow); |
- | 347 | timeNext += TICKS_LOOP; |
|
- | 348 | cc_run(&bmp, &bmp2); |
|
368 | 349 | ||
- | 350 | // refresh watchdog timer |
|
- | 351 | HAL_IWDG_Refresh(&hiwdg); |
|
369 | 352 | ||
370 | /* USER CODE END WHILE */ |
353 | /* USER CODE END WHILE */ |
371 | 354 | ||
372 | /* USER CODE BEGIN 3 */ |
355 | /* USER CODE BEGIN 3 */ |
373 | } |
356 | } |
374 | /* USER CODE END 3 */ |
357 | /* USER CODE END 3 */ |
375 | } |
358 | } |
376 | 359 | ||
377 | /** |
360 | /** |
378 | * @brief System Clock Configuration |
361 | * @brief System Clock Configuration |
379 | * @retval None |
362 | * @retval None |
380 | */ |
363 | */ |
381 | void SystemClock_Config(void) |
364 | void SystemClock_Config(void) |
382 | { |
365 | { |
383 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
366 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
384 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
367 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
385 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
368 | RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; |
386 | 369 | ||
387 | /** Initializes the RCC Oscillators according to the specified parameters |
370 | /** Initializes the RCC Oscillators according to the specified parameters |
388 | * in the RCC_OscInitTypeDef structure. |
371 | * in the RCC_OscInitTypeDef structure. |
389 | */ |
372 | */ |
390 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE |
373 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_LSE; |
391 | |RCC_OSCILLATORTYPE_LSE; |
- | |
392 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
374 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
393 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
375 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; |
394 | RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
376 | RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
395 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
377 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
396 | RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
378 | RCC_OscInitStruct.LSIState = RCC_LSI_ON; |
Line 400... | Line 382... | ||
400 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
382 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
401 | { |
383 | { |
402 | Error_Handler(); |
384 | Error_Handler(); |
403 | } |
385 | } |
404 | /** Initializes the CPU, AHB and APB buses clocks |
386 | /** Initializes the CPU, AHB and APB buses clocks |
405 | */ |
387 | */ |
406 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
388 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
407 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; |
- | |
408 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
389 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
409 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
390 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
410 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
391 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
411 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
392 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
412 | 393 | ||
413 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
394 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) |
414 | { |
395 | { |
415 | Error_Handler(); |
396 | Error_Handler(); |
416 | } |
397 | } |
417 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB; |
398 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USB; |
418 | PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
399 | PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
419 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; |
400 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; |
420 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
401 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) |
421 | { |
402 | { |
422 | Error_Handler(); |
403 | Error_Handler(); |
423 | } |
404 | } |
424 | } |
405 | } |
425 | 406 | ||
426 | /** |
407 | /** |
427 | * @brief I2C1 Initialization Function |
408 | * @brief I2C1 Initialization Function |
428 | * @param None |
409 | * @param None |
429 | * @retval None |
410 | * @retval None |
430 | */ |
411 | */ |
431 | static void MX_I2C1_Init(void) |
412 | static void MX_I2C1_Init(void) |
432 | { |
413 | { |
433 | 414 | ||
434 | /* USER CODE BEGIN I2C1_Init 0 */ |
415 | /* USER CODE BEGIN I2C1_Init 0 */ |
435 | 416 | ||
Line 452... | Line 433... | ||
452 | Error_Handler(); |
433 | Error_Handler(); |
453 | } |
434 | } |
454 | /* USER CODE BEGIN I2C1_Init 2 */ |
435 | /* USER CODE BEGIN I2C1_Init 2 */ |
455 | 436 | ||
456 | /* USER CODE END I2C1_Init 2 */ |
437 | /* USER CODE END I2C1_Init 2 */ |
457 | - | ||
458 | } |
438 | } |
459 | 439 | ||
460 | /** |
440 | /** |
461 | * @brief I2C2 Initialization Function |
441 | * @brief I2C2 Initialization Function |
462 | * @param None |
442 | * @param None |
463 | * @retval None |
443 | * @retval None |
464 | */ |
444 | */ |
465 | static void MX_I2C2_Init(void) |
445 | static void MX_I2C2_Init(void) |
466 | { |
446 | { |
467 | 447 | ||
468 | /* USER CODE BEGIN I2C2_Init 0 */ |
448 | /* USER CODE BEGIN I2C2_Init 0 */ |
469 | 449 | ||
Line 486... | Line 466... | ||
486 | Error_Handler(); |
466 | Error_Handler(); |
487 | } |
467 | } |
488 | /* USER CODE BEGIN I2C2_Init 2 */ |
468 | /* USER CODE BEGIN I2C2_Init 2 */ |
489 | 469 | ||
490 | /* USER CODE END I2C2_Init 2 */ |
470 | /* USER CODE END I2C2_Init 2 */ |
491 | - | ||
492 | } |
471 | } |
493 | 472 | ||
494 | /** |
473 | /** |
495 | * @brief IWDG Initialization Function |
474 | * @brief IWDG Initialization Function |
496 | * @param None |
475 | * @param None |
497 | * @retval None |
476 | * @retval None |
498 | */ |
477 | */ |
499 | static void MX_IWDG_Init(void) |
478 | static void MX_IWDG_Init(void) |
500 | { |
479 | { |
501 | 480 | ||
502 | /* USER CODE BEGIN IWDG_Init 0 */ |
481 | /* USER CODE BEGIN IWDG_Init 0 */ |
503 | 482 | ||
Line 514... | Line 493... | ||
514 | Error_Handler(); |
493 | Error_Handler(); |
515 | } |
494 | } |
516 | /* USER CODE BEGIN IWDG_Init 2 */ |
495 | /* USER CODE BEGIN IWDG_Init 2 */ |
517 | 496 | ||
518 | /* USER CODE END IWDG_Init 2 */ |
497 | /* USER CODE END IWDG_Init 2 */ |
519 | - | ||
520 | } |
498 | } |
521 | 499 | ||
522 | /** |
500 | /** |
523 | * @brief RTC Initialization Function |
501 | * @brief RTC Initialization Function |
524 | * @param None |
502 | * @param None |
525 | * @retval None |
503 | * @retval None |
526 | */ |
504 | */ |
527 | static void MX_RTC_Init(void) |
505 | static void MX_RTC_Init(void) |
528 | { |
506 | { |
529 | 507 | ||
530 | /* USER CODE BEGIN RTC_Init 0 */ |
508 | /* USER CODE BEGIN RTC_Init 0 */ |
531 | 509 | ||
Line 536... | Line 514... | ||
536 | 514 | ||
537 | /* USER CODE BEGIN RTC_Init 1 */ |
515 | /* USER CODE BEGIN RTC_Init 1 */ |
538 | 516 | ||
539 | /* USER CODE END RTC_Init 1 */ |
517 | /* USER CODE END RTC_Init 1 */ |
540 | /** Initialize RTC Only |
518 | /** Initialize RTC Only |
541 | */ |
519 | */ |
542 | hrtc.Instance = RTC; |
520 | hrtc.Instance = RTC; |
543 | hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; |
521 | hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND; |
544 | hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM; |
522 | hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM; |
545 | if (HAL_RTC_Init(&hrtc) != HAL_OK) |
523 | if (HAL_RTC_Init(&hrtc) != HAL_OK) |
546 | { |
524 | { |
Line 550... | Line 528... | ||
550 | /* USER CODE BEGIN Check_RTC_BKUP */ |
528 | /* USER CODE BEGIN Check_RTC_BKUP */ |
551 | 529 | ||
552 | /* USER CODE END Check_RTC_BKUP */ |
530 | /* USER CODE END Check_RTC_BKUP */ |
553 | 531 | ||
554 | /** Initialize RTC and set the Time and Date |
532 | /** Initialize RTC and set the Time and Date |
555 | */ |
533 | */ |
556 | sTime.Hours = 0x0; |
534 | sTime.Hours = 0x0; |
557 | sTime.Minutes = 0x0; |
535 | sTime.Minutes = 0x0; |
558 | sTime.Seconds = 0x0; |
536 | sTime.Seconds = 0x0; |
559 | 537 | ||
560 | if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) |
538 | if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK) |
Line 571... | Line 549... | ||
571 | Error_Handler(); |
549 | Error_Handler(); |
572 | } |
550 | } |
573 | /* USER CODE BEGIN RTC_Init 2 */ |
551 | /* USER CODE BEGIN RTC_Init 2 */ |
574 | 552 | ||
575 | /* USER CODE END RTC_Init 2 */ |
553 | /* USER CODE END RTC_Init 2 */ |
576 | - | ||
577 | } |
554 | } |
578 | 555 | ||
579 | /** |
556 | /** |
580 | * @brief SPI1 Initialization Function |
557 | * @brief SPI1 Initialization Function |
581 | * @param None |
558 | * @param None |
582 | * @retval None |
559 | * @retval None |
583 | */ |
560 | */ |
584 | static void MX_SPI1_Init(void) |
561 | static void MX_SPI1_Init(void) |
585 | { |
562 | { |
586 | 563 | ||
587 | /* USER CODE BEGIN SPI1_Init 0 */ |
564 | /* USER CODE BEGIN SPI1_Init 0 */ |
588 | 565 | ||
Line 609... | Line 586... | ||
609 | Error_Handler(); |
586 | Error_Handler(); |
610 | } |
587 | } |
611 | /* USER CODE BEGIN SPI1_Init 2 */ |
588 | /* USER CODE BEGIN SPI1_Init 2 */ |
612 | 589 | ||
613 | /* USER CODE END SPI1_Init 2 */ |
590 | /* USER CODE END SPI1_Init 2 */ |
614 | - | ||
615 | } |
591 | } |
616 | 592 | ||
617 | /** |
593 | /** |
618 | * @brief TIM3 Initialization Function |
594 | * @brief TIM3 Initialization Function |
619 | * @param None |
595 | * @param None |
620 | * @retval None |
596 | * @retval None |
621 | */ |
597 | */ |
622 | static void MX_TIM3_Init(void) |
598 | static void MX_TIM3_Init(void) |
623 | { |
599 | { |
624 | 600 | ||
625 | /* USER CODE BEGIN TIM3_Init 0 */ |
601 | /* USER CODE BEGIN TIM3_Init 0 */ |
626 | 602 | ||
Line 661... | Line 637... | ||
661 | Error_Handler(); |
637 | Error_Handler(); |
662 | } |
638 | } |
663 | /* USER CODE BEGIN TIM3_Init 2 */ |
639 | /* USER CODE BEGIN TIM3_Init 2 */ |
664 | 640 | ||
665 | /* USER CODE END TIM3_Init 2 */ |
641 | /* USER CODE END TIM3_Init 2 */ |
666 | - | ||
667 | } |
642 | } |
668 | 643 | ||
669 | /** |
644 | /** |
670 | * @brief TIM4 Initialization Function |
645 | * @brief TIM4 Initialization Function |
671 | * @param None |
646 | * @param None |
672 | * @retval None |
647 | * @retval None |
673 | */ |
648 | */ |
674 | static void MX_TIM4_Init(void) |
649 | static void MX_TIM4_Init(void) |
675 | { |
650 | { |
676 | 651 | ||
677 | /* USER CODE BEGIN TIM4_Init 0 */ |
652 | /* USER CODE BEGIN TIM4_Init 0 */ |
678 | 653 | ||
Line 710... | Line 685... | ||
710 | Error_Handler(); |
685 | Error_Handler(); |
711 | } |
686 | } |
712 | /* USER CODE BEGIN TIM4_Init 2 */ |
687 | /* USER CODE BEGIN TIM4_Init 2 */ |
713 | 688 | ||
714 | /* USER CODE END TIM4_Init 2 */ |
689 | /* USER CODE END TIM4_Init 2 */ |
715 | - | ||
716 | } |
690 | } |
717 | 691 | ||
718 | /** |
692 | /** |
719 | * @brief USART1 Initialization Function |
693 | * @brief USART1 Initialization Function |
720 | * @param None |
694 | * @param None |
721 | * @retval None |
695 | * @retval None |
722 | */ |
696 | */ |
723 | static void MX_USART1_UART_Init(void) |
697 | static void MX_USART1_UART_Init(void) |
724 | { |
698 | { |
725 | 699 | ||
726 | /* USER CODE BEGIN USART1_Init 0 */ |
700 | /* USER CODE BEGIN USART1_Init 0 */ |
727 | 701 | ||
Line 743... | Line 717... | ||
743 | Error_Handler(); |
717 | Error_Handler(); |
744 | } |
718 | } |
745 | /* USER CODE BEGIN USART1_Init 2 */ |
719 | /* USER CODE BEGIN USART1_Init 2 */ |
746 | 720 | ||
747 | /* USER CODE END USART1_Init 2 */ |
721 | /* USER CODE END USART1_Init 2 */ |
748 | - | ||
749 | } |
722 | } |
750 | 723 | ||
751 | /** |
724 | /** |
752 | * @brief GPIO Initialization Function |
725 | * @brief GPIO Initialization Function |
753 | * @param None |
726 | * @param None |
754 | * @retval None |
727 | * @retval None |
755 | */ |
728 | */ |
756 | static void MX_GPIO_Init(void) |
729 | static void MX_GPIO_Init(void) |
757 | { |
730 | { |
758 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
731 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
759 | 732 | ||
760 | /* GPIO Ports Clock Enable */ |
733 | /* GPIO Ports Clock Enable */ |
Line 765... | Line 738... | ||
765 | 738 | ||
766 | /*Configure GPIO pin Output Level */ |
739 | /*Configure GPIO pin Output Level */ |
767 | HAL_GPIO_WritePin(Green_LED_GPIO_Port, Green_LED_Pin, GPIO_PIN_RESET); |
740 | HAL_GPIO_WritePin(Green_LED_GPIO_Port, Green_LED_Pin, GPIO_PIN_RESET); |
768 | 741 | ||
769 | /*Configure GPIO pin Output Level */ |
742 | /*Configure GPIO pin Output Level */ |
770 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin, GPIO_PIN_RESET); |
743 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin | SPI_RESET_Pin | SPI_NSS1_Pin, GPIO_PIN_RESET); |
771 | 744 | ||
772 | /*Configure GPIO pin Output Level */ |
745 | /*Configure GPIO pin Output Level */ |
773 | HAL_GPIO_WritePin(I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
746 | HAL_GPIO_WritePin(I2C1_BusPower_GPIO_Port, I2C1_BusPower_Pin, GPIO_PIN_SET); |
774 | 747 | ||
775 | /*Configure GPIO pin Output Level */ |
748 | /*Configure GPIO pin Output Level */ |
Line 781... | Line 754... | ||
781 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
754 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
782 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
755 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
783 | HAL_GPIO_Init(Green_LED_GPIO_Port, &GPIO_InitStruct); |
756 | HAL_GPIO_Init(Green_LED_GPIO_Port, &GPIO_InitStruct); |
784 | 757 | ||
785 | /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin SPI_NSS1_Pin */ |
758 | /*Configure GPIO pins : SPI_CD_Pin SPI_RESET_Pin SPI_NSS1_Pin */ |
786 | GPIO_InitStruct.Pin = SPI_CD_Pin|SPI_RESET_Pin|SPI_NSS1_Pin; |
759 | GPIO_InitStruct.Pin = SPI_CD_Pin | SPI_RESET_Pin | SPI_NSS1_Pin; |
787 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
760 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
788 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
761 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
789 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
762 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
790 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
763 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
791 | 764 | ||
Line 806... | Line 779... | ||
806 | /*Configure GPIO pin : encoder_push_Pin */ |
779 | /*Configure GPIO pin : encoder_push_Pin */ |
807 | GPIO_InitStruct.Pin = encoder_push_Pin; |
780 | GPIO_InitStruct.Pin = encoder_push_Pin; |
808 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
781 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
809 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
782 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
810 | HAL_GPIO_Init(encoder_push_GPIO_Port, &GPIO_InitStruct); |
783 | HAL_GPIO_Init(encoder_push_GPIO_Port, &GPIO_InitStruct); |
811 | - | ||
812 | } |
784 | } |
813 | 785 | ||
814 | /* USER CODE BEGIN 4 */ |
786 | /* USER CODE BEGIN 4 */ |
815 | 787 | ||
816 | /* USER CODE END 4 */ |
788 | /* USER CODE END 4 */ |
817 | 789 | ||
818 | /** |
790 | /** |
819 | * @brief This function is executed in case of error occurrence. |
791 | * @brief This function is executed in case of error occurrence. |
820 | * @retval None |
792 | * @retval None |
821 | */ |
793 | */ |
822 | void Error_Handler(void) |
794 | void Error_Handler(void) |
823 | { |
795 | { |
824 | /* USER CODE BEGIN Error_Handler_Debug */ |
796 | /* USER CODE BEGIN Error_Handler_Debug */ |
825 | /* User can add his own implementation to report the HAL error return state */ |
797 | /* User can add his own implementation to report the HAL error return state */ |
826 | 798 | ||
827 | /* USER CODE END Error_Handler_Debug */ |
799 | /* USER CODE END Error_Handler_Debug */ |
828 | } |
800 | } |
829 | 801 | ||
830 | #ifdef USE_FULL_ASSERT |
802 | #ifdef USE_FULL_ASSERT |
831 | /** |
803 | /** |
832 | * @brief Reports the name of the source file and the source line number |
804 | * @brief Reports the name of the source file and the source line number |
833 | * where the assert_param error has occurred. |
805 | * where the assert_param error has occurred. |
834 | * @param file: pointer to the source file name |
806 | * @param file: pointer to the source file name |
835 | * @param line: assert_param error line source number |
807 | * @param line: assert_param error line source number |
836 | * @retval None |
808 | * @retval None |
837 | */ |
809 | */ |
838 | void assert_failed(uint8_t *file, uint32_t line) |
810 | void assert_failed(uint8_t *file, uint32_t line) |
839 | { |
811 | { |
840 | /* USER CODE BEGIN 6 */ |
812 | /* USER CODE BEGIN 6 */ |
841 | /* User can add his own implementation to report the file name and line number, |
813 | /* User can add his own implementation to report the file name and line number, |
842 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
814 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |