Mercurial > public > ostc4
comparison Small_CPU/Src/baseCPU2.c @ 160:e3ca52b8e7fa
Merge with FlipDisplay
author | heinrichsweikamp |
---|---|
date | Thu, 07 Mar 2019 15:06:43 +0100 |
parents | ee744c7160ce |
children | c659fda83e44 |
comparison
equal
deleted
inserted
replaced
80:cc2bb7bb8456 | 160:e3ca52b8e7fa |
---|---|
151 | 151 |
152 // From Common/Drivers/ | 152 // From Common/Drivers/ |
153 #include "stm32f4xx_hal.h" | 153 #include "stm32f4xx_hal.h" |
154 #include <stdio.h> | 154 #include <stdio.h> |
155 | 155 |
156 uint8_t hasExternalClock(void) | 156 uint8_t hasExternalClock(void) { |
157 { | 157 if ((TM_OTP_Read(0, 0) > 0) && (TM_OTP_Read(0, 0) < 0xFF)) |
158 if( (TM_OTP_Read( 0, 0 ) > 0) && (TM_OTP_Read( 0, 0 ) < 0xFF) ) | 158 return 1; |
159 return 1; | 159 else |
160 else | 160 return 0; |
161 return 0; | |
162 } | 161 } |
163 | 162 |
164 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. | 163 // SHALL LOAD AT 0x08000000 + 0x00005000 = 0x08005000. |
165 // See CPU2-RTE.ld | 164 // See CPU2-RTE.ld |
166 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") )) | 165 const SFirmwareData cpu2_FirmwareData __attribute__(( section(".firmware_data") ))= { |
167 = | 166 .versionFirst = 1, |
168 { | 167 .versionSecond = 7, |
169 .versionFirst = 1, | 168 .versionThird = 0, |
170 .versionSecond = 6, | 169 .versionBeta = 0, |
171 .versionThird = 0, | 170 |
172 .versionBeta = 0, | 171 /* 4 bytes with trailing 0 */ |
173 | 172 .signature = "mh", |
174 /* 4 bytes with trailing 0 */ | 173 |
175 .signature = "mh", | 174 .release_year = 18, |
176 | 175 .release_month = 7, |
177 .release_year = 18, | 176 .release_day = 29, |
178 .release_month = 7, | 177 .release_sub = 0, |
179 .release_day = 29, | 178 |
180 .release_sub = 0, | 179 /* max 48 with trailing 0 */ |
181 | 180 //release_info ="12345678901234567890123456789012345678901" |
182 /* max 48 with trailing 0 */ | 181 .release_info = "compass stuff", |
183 //release_info ="12345678901234567890123456789012345678901" | 182 |
184 .release_info = "compass stuff", | 183 /* for safety reasons and coming functions */ |
185 | 184 .magic[0] = FIRMWARE_MAGIC_FIRST, .magic[1] = FIRMWARE_MAGIC_SECOND, |
186 /* for safety reasons and coming functions */ | 185 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ |
187 .magic[0] = FIRMWARE_MAGIC_FIRST, | 186 .magic[3] = FIRMWARE_MAGIC_END }; |
188 .magic[1] = FIRMWARE_MAGIC_SECOND, | 187 |
189 .magic[2] = FIRMWARE_MAGIC_CPU2_RTE, /* the magic byte for RTE */ | 188 uint8_t firmwareVersionHigh(void) { |
190 .magic[3] = FIRMWARE_MAGIC_END | 189 return cpu2_FirmwareData.versionFirst; |
191 }; | 190 } |
192 | 191 |
193 uint8_t firmwareVersionHigh(void) | 192 uint8_t firmwareVersionLow(void) { |
194 { | 193 return cpu2_FirmwareData.versionSecond; |
195 return cpu2_FirmwareData.versionFirst; | |
196 } | |
197 | |
198 uint8_t firmwareVersionLow(void) | |
199 { | |
200 return cpu2_FirmwareData.versionSecond; | |
201 } | 194 } |
202 | 195 |
203 /** @addtogroup OSTC4 | 196 /** @addtogroup OSTC4 |
204 * @{ | 197 * @{ |
205 */ | 198 */ |
271 void GPIO_new_DEBUG_LOW(void); | 264 void GPIO_new_DEBUG_LOW(void); |
272 void GPIO_new_DEBUG_HIGH(void); | 265 void GPIO_new_DEBUG_HIGH(void); |
273 | 266 |
274 #define REGULAR_RUN | 267 #define REGULAR_RUN |
275 | 268 |
276 int __io_putchar(int ch) | 269 int __io_putchar(int ch) { |
277 { | 270 ITM_SendChar(ch); |
278 ITM_SendChar( ch ); | 271 return ch; |
279 return ch; | |
280 } | 272 } |
281 | 273 |
282 /* Private functions ---------------------------------------------------------*/ | 274 /* Private functions ---------------------------------------------------------*/ |
283 | 275 |
284 /** | 276 /** |
285 * @brief Main program | 277 * @brief Main program |
286 * @param None | 278 * @param None |
287 * @retval None | 279 * @retval None |
288 */ | 280 */ |
289 | 281 /* #define DEBUG_RUNTIME TRUE */ |
290 int main(void) | 282 #ifdef DEBUG_RUNTIME |
291 { | 283 #define MEASURECNT 60 /* number of measuremets to be stored */ |
292 HAL_Init(); | 284 static uint32_t loopcnt[MEASURECNT]; |
293 SystemClock_Config(); | 285 extern RTC_HandleTypeDef RTCHandle; |
294 | 286 #endif |
295 HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq() / 1000 ); | 287 |
296 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK ); | 288 int main(void) { |
297 HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 ); | 289 |
298 | 290 #ifdef DEBUG_RUNTIME |
299 MX_RTC_init(); | 291 RTC_TimeTypeDef Stime; |
300 GPIO_LED_Init(); | 292 uint8_t measurementindex = 0; |
301 GPIO_new_DEBUG_Init(); // added 170322 hw | 293 uint8_t lastsecond = 0xFF; |
302 initGlobals(); | 294 #endif |
303 | 295 |
304 printf("CPU2-RTE running...\n"); | 296 HAL_Init(); |
305 | 297 SystemClock_Config(); |
306 MX_I2C1_Init(); | 298 |
307 if( global.I2C_SystemStatus != HAL_OK ) | 299 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); |
308 { | 300 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK); |
309 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) | 301 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
310 { | 302 |
311 MX_I2C1_TestAndClear(); // do it a second time | 303 MX_RTC_init(); |
312 } | 304 GPIO_LED_Init(); |
313 MX_I2C1_Init(); | 305 GPIO_new_DEBUG_Init(); // added 170322 hw |
314 } | 306 initGlobals(); |
315 | 307 |
316 //dangerous: TM_OTP_Write(0,0, 0x01); | 308 /* printf("CPU2-RTE running...\n"); */ |
309 | |
310 MX_I2C1_Init(); | |
311 if (global.I2C_SystemStatus != HAL_OK) { | |
312 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
313 MX_I2C1_TestAndClear(); // do it a second time | |
314 } | |
315 MX_I2C1_Init(); | |
316 } | |
317 | |
318 //dangerous: TM_OTP_Write(0,0, 0x01); | |
317 #ifdef REGULAR_RUN | 319 #ifdef REGULAR_RUN |
318 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | 320 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
319 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | 321 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; |
320 if( global.I2C_SystemStatus != HAL_OK ) | 322 if (global.I2C_SystemStatus != HAL_OK) { |
321 { | 323 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { |
322 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) | 324 MX_I2C1_TestAndClear(); // do it a second time |
323 { | 325 } |
324 MX_I2C1_TestAndClear(); // do it a second time | 326 MX_I2C1_Init(); |
325 } | 327 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); |
326 MX_I2C1_Init(); | 328 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; |
327 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); | 329 } |
328 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; | 330 |
329 } | 331 global.dataSendToMaster.sensorErrors = |
330 | 332 global.sensorError[SENSOR_PRESSURE_ID]; |
331 global.dataSendToMaster.sensorErrors = | 333 init_surface_ring(); |
332 global.sensorError[SENSOR_PRESSURE_ID]; | 334 init_battery_gas_gauge(); |
333 init_surface_ring(); | 335 HAL_Delay(10); |
334 init_battery_gas_gauge(); | 336 battery_gas_gauge_get_data(); |
335 HAL_Delay( 10 ); | |
336 battery_gas_gauge_get_data(); | |
337 // battery_gas_gauge_set(0); | 337 // battery_gas_gauge_set(0); |
338 | 338 |
339 global.lifeData.battery_voltage = get_voltage(); | 339 global.lifeData.battery_voltage = get_voltage(); |
340 global.lifeData.battery_charge = get_charge(); | 340 global.lifeData.battery_charge = get_charge(); |
341 copyBatteryData(); | 341 copyBatteryData(); |
342 | 342 |
343 MX_SPI3_Init(); | 343 MX_SPI3_Init(); |
344 if( !scheduleSetButtonResponsiveness() ) | 344 if (!scheduleSetButtonResponsiveness()) { |
345 { | 345 HAL_Delay(1); |
346 HAL_Delay( 1 ); | 346 scheduleSetButtonResponsiveness(); // init |
347 scheduleSetButtonResponsiveness(); // init | 347 HAL_Delay(1); |
348 HAL_Delay( 1 ); | 348 if (!scheduleSetButtonResponsiveness()) // send again, if problem it's not my problem here. |
349 if( !scheduleSetButtonResponsiveness() ) // send again, if problem it's not my problem here. | 349 { |
350 { | 350 HAL_Delay(1); |
351 HAL_Delay( 1 ); | 351 scheduleSetButtonResponsiveness(); // init |
352 scheduleSetButtonResponsiveness(); // init | 352 HAL_Delay(1); |
353 HAL_Delay( 1 ); | 353 } |
354 } | 354 } |
355 } | 355 |
356 | 356 ADCx_Init(); |
357 ADCx_Init(); | 357 GPIO_Power_MainCPU_Init(); |
358 GPIO_Power_MainCPU_Init(); | 358 global.mode = MODE_POWERUP; |
359 global.mode = MODE_POWERUP; | |
360 #else | 359 #else |
361 init_pressure(); | 360 init_pressure(); |
362 init_surface_ring(); | 361 init_surface_ring(); |
363 | 362 |
364 ADCx_Init(); | 363 ADCx_Init(); |
365 GPIO_Power_MainCPU_Init(); | 364 GPIO_Power_MainCPU_Init(); |
366 global.mode = MODE_TEST; | 365 global.mode = MODE_TEST; |
367 #endif | 366 #endif |
368 while( 1 ) | 367 while (1) { |
369 { | 368 /* printf("Global mode = %d\n", global.mode); */ |
370 printf("Global mode = %d\n", global.mode); | 369 |
371 | 370 switch (global.mode) { |
372 switch( global.mode ) | 371 case MODE_POWERUP: |
373 { | 372 case MODE_BOOT: |
374 case MODE_POWERUP: | 373 // ReInit_battery_charger_status_pins(); |
375 case MODE_BOOT: | 374 compass_init(0, 7); |
376 // ReInit_battery_charger_status_pins(); | 375 accelerator_init(); |
377 compass_init( 0, 7 ); | 376 wireless_init(); |
378 accelerator_init(); | 377 if (global.mode == MODE_BOOT) { |
379 wireless_init(); | 378 GPIO_Power_MainCPU_OFF(); |
380 if( global.mode == MODE_BOOT ) | 379 HAL_Delay(100); // for GPIO_Power_MainCPU_ON(); |
381 { | 380 GPIO_Power_MainCPU_ON(); |
382 GPIO_Power_MainCPU_OFF(); | 381 } |
383 HAL_Delay( 100 ); // for GPIO_Power_MainCPU_ON(); | 382 SPI_synchronize_with_Master(); |
384 GPIO_Power_MainCPU_ON(); | 383 MX_DMA_Init(); |
385 } | 384 MX_SPI1_Init(); |
386 SPI_synchronize_with_Master(); | 385 MX_EXTI_wireless_Init(); |
387 MX_DMA_Init(); | 386 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ |
388 MX_SPI1_Init(); | 387 dohardspisync = 1; |
389 MX_EXTI_wireless_Init(); | 388 EXTI_Test_Button_Init(); |
390 SPI_Start_single_TxRx_with_Master(); | 389 |
391 EXTI_Test_Button_Init(); | 390 /* |
392 | 391 uint8_t dataWireless[64]; |
393 /* | 392 while(1) |
394 uint8_t dataWireless[64]; | 393 { |
395 while(1) | 394 wireless_evaluate_and_debug(dataWireless,64); |
396 { | 395 } |
397 wireless_evaluate_and_debug(dataWireless,64); | 396 */ |
398 } | 397 global.mode = MODE_SURFACE; |
399 */ | 398 break; |
400 global.mode = MODE_SURFACE; | 399 |
401 break; | 400 case MODE_CALIB: |
402 | |
403 case MODE_CALIB: | |
404 scheduleCompassCalibrationMode(); | 401 scheduleCompassCalibrationMode(); |
405 break; | 402 break; |
406 | 403 |
407 case MODE_SURFACE: | 404 case MODE_SURFACE: |
408 scheduleSurfaceMode(); | 405 scheduleSurfaceMode(); |
409 break; | 406 break; |
410 | 407 |
411 case MODE_TEST: | 408 case MODE_TEST: |
412 GPIO_Power_MainCPU_ON(); | 409 break; |
413 SPI_synchronize_with_Master(); | 410 |
414 MX_DMA_Init(); | 411 case MODE_DIVE: |
415 MX_SPI1_Init(); | |
416 // MX_EXTI_wireless_Init(); | |
417 SPI_Start_single_TxRx_with_Master(); | |
418 // EXTI_Test_Button_Init(); | |
419 | |
420 scheduleTestMode(); | |
421 break; | |
422 | |
423 case MODE_DIVE: | |
424 backup.no_fly_time_minutes = global.no_fly_time_minutes; | 412 backup.no_fly_time_minutes = global.no_fly_time_minutes; |
425 backup.seconds_since_last_dive = global.seconds_since_last_dive; | 413 backup.seconds_since_last_dive = global.seconds_since_last_dive; |
426 | 414 |
427 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, | 415 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, |
428 global.seconds_since_last_dive ); | 416 global.seconds_since_last_dive ); |
452 global.lifeData.dive_time_seconds_without_surface_time = 0; | 440 global.lifeData.dive_time_seconds_without_surface_time = 0; |
453 global.lifeData.counterSecondsShallowDepth = 0; | 441 global.lifeData.counterSecondsShallowDepth = 0; |
454 | 442 |
455 backup.no_fly_time_minutes = 0; | 443 backup.no_fly_time_minutes = 0; |
456 backup.seconds_since_last_dive = 0; | 444 backup.seconds_since_last_dive = 0; |
457 break; | 445 break; |
458 | 446 |
459 case MODE_SHUTDOWN: | 447 case MODE_SHUTDOWN: |
460 HAL_Delay( 200 ); | 448 HAL_Delay(200); |
461 global.mode = MODE_SLEEP; | 449 global.mode = MODE_SLEEP; |
462 MX_SPI3_Init(); | 450 MX_SPI3_Init(); |
463 break; | 451 break; |
464 | 452 |
465 case MODE_SLEEP: | 453 case MODE_SLEEP: |
466 /* | 454 /* |
467 sleep_prepare(); | 455 sleep_prepare(); |
468 scheduleSleepMode_test(); | 456 scheduleSleepMode_test(); |
469 */ | 457 */ |
470 /* | 458 /* |
471 GPIO_Power_MainCPU_OFF(); | 459 GPIO_Power_MainCPU_OFF(); |
472 EXTI_Test_Button_DeInit(); | 460 EXTI_Test_Button_DeInit(); |
473 EXTI_Wakeup_Button_Init(); | 461 EXTI_Wakeup_Button_Init(); |
474 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); | 462 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); |
475 */ | 463 */ |
476 EXTI_Test_Button_DeInit(); | 464 EXTI_Test_Button_DeInit(); |
477 MX_EXTI_wireless_DeInit(); | 465 MX_EXTI_wireless_DeInit(); |
478 if( hasExternalClock() ) | 466 if (hasExternalClock()) |
479 SystemClock_Config_HSI(); | 467 SystemClock_Config_HSI(); |
480 sleep_prepare(); | 468 sleep_prepare(); |
481 | 469 |
482 GPIO_LED_Init(); | 470 GPIO_LED_Init(); |
483 | 471 |
484 scheduleSleepMode(); | 472 scheduleSleepMode(); |
485 if( hasExternalClock() ) | 473 if (hasExternalClock()) |
486 SystemClock_Config_HSE(); | 474 SystemClock_Config_HSE(); |
487 GPIO_LED_Init(); | 475 GPIO_LED_Init(); |
488 EXTI_Wakeup_Button_DeInit(); | 476 EXTI_Wakeup_Button_DeInit(); |
489 ADCx_Init(); | 477 ADCx_Init(); |
490 GPIO_Power_MainCPU_Init(); | 478 GPIO_Power_MainCPU_Init(); |
491 GPIO_Power_MainCPU_ON(); | 479 GPIO_Power_MainCPU_ON(); |
492 compass_init( 0, 7 ); | 480 compass_init(0, 7); |
493 accelerator_init(); | 481 accelerator_init(); |
494 wireless_init(); | 482 wireless_init(); |
495 SPI_synchronize_with_Master(); | 483 SPI_synchronize_with_Master(); |
496 MX_DMA_Init(); | 484 MX_DMA_Init(); |
497 MX_SPI1_Init(); | 485 MX_SPI1_Init(); |
498 MX_EXTI_wireless_Init(); | 486 MX_EXTI_wireless_Init(); |
499 SPI_Start_single_TxRx_with_Master(); | 487 SPI_Start_single_TxRx_with_Master(); |
500 | 488 |
501 // EXTILine0_Button_DeInit(); not now, later after testing | 489 // EXTILine0_Button_DeInit(); not now, later after testing |
502 break; | 490 break; |
491 } | |
492 | |
493 #ifdef DEBUG_RUNTIME | |
494 HAL_RTC_GetTime(&RTCHandle, &Stime, RTC_FORMAT_BCD); | |
495 | |
496 if(lastsecond == 0xFF) | |
497 { | |
498 measurementindex = 0; | |
499 loopcnt[measurementindex] = 0; | |
500 lastsecond = Stime.Seconds; | |
503 } | 501 } |
504 } | 502 loopcnt[measurementindex]++; |
503 | |
504 if(lastsecond != Stime.Seconds) | |
505 { | |
506 measurementindex++; | |
507 if (measurementindex == MEASURECNT) measurementindex = 0; | |
508 loopcnt[measurementindex] = 0; | |
509 lastsecond = Stime.Seconds; | |
510 if(measurementindex +1 < MEASURECNT) loopcnt[measurementindex +1] = 0xffff; /* helps to identify the latest value */ | |
511 } | |
512 #endif | |
513 } | |
505 } | 514 } |
506 | 515 |
507 /** @brief Button feedback - EXTI line detection callbacks | 516 /** @brief Button feedback - EXTI line detection callbacks |
508 * @param GPIO_Pin: Specifies the pins connected EXTI line | 517 * @param GPIO_Pin: Specifies the pins connected EXTI line |
509 * @retval None | 518 * @retval None |
510 */ | 519 */ |
511 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) | 520 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { |
512 { | 521 |
513 | 522 if (GPIO_Pin == WIRELSS_RISING_GPIO_PIN) { |
514 if( GPIO_Pin == WIRELSS_RISING_GPIO_PIN ) | 523 wireless_trigger_RisingEdgeSilence(); |
515 { | 524 } |
516 wireless_trigger_RisingEdgeSilence(); | 525 |
517 } | 526 else |
518 | 527 |
519 else | 528 if (GPIO_Pin == WIRELSS_FALLING_GPIO_PIN) { |
520 | 529 wireless_trigger_FallingEdgeSignalHigh(); |
521 if( GPIO_Pin == WIRELSS_FALLING_GPIO_PIN ) | 530 } |
522 { | 531 |
523 wireless_trigger_FallingEdgeSignalHigh(); | 532 else |
524 } | 533 |
525 | 534 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) { |
526 else | 535 if (global.mode == MODE_SLEEP) { |
527 | 536 global.mode = MODE_BOOT; |
528 if( GPIO_Pin == BUTTON_OSTC_GPIO_PIN ) | 537 } |
529 { | 538 } |
530 if( global.mode == MODE_SLEEP ) | 539 |
531 { | 540 else |
532 global.mode = MODE_BOOT; | 541 |
533 } | 542 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) { |
534 } | 543 if (!global.demo_mode && (global.mode == MODE_SURFACE)) { |
535 | 544 global.demo_mode = 1; |
536 else | 545 global.mode = MODE_DIVE; |
537 | 546 } else if (global.demo_mode && (global.mode == MODE_DIVE) |
538 if( GPIO_Pin == BUTTON_TEST_GPIO_PIN ) | 547 && (global.lifeData.dive_time_seconds > 10)) { |
539 { | 548 global.demo_mode = 0; |
540 if( !global.demo_mode && (global.mode == MODE_SURFACE) ) | 549 global.dataSendToMaster.mode = MODE_ENDDIVE; |
541 { | 550 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; |
542 global.demo_mode = 1; | 551 } |
543 global.mode = MODE_DIVE; | 552 } |
544 } | |
545 else if( global.demo_mode && (global.mode == MODE_DIVE) | |
546 && (global.lifeData.dive_time_seconds > 10) ) | |
547 { | |
548 global.demo_mode = 0; | |
549 global.dataSendToMaster.mode = MODE_ENDDIVE; | |
550 global.deviceDataSendToMaster.mode = MODE_ENDDIVE; | |
551 } | |
552 } | |
553 } | 553 } |
554 | 554 |
555 /** | 555 /** |
556 * @brief System Clock Configuration | 556 * @brief System Clock Configuration |
557 * The system Clock is configured as follow : | 557 * The system Clock is configured as follow : |
571 * Flash Latency(WS) = 3 | 571 * Flash Latency(WS) = 3 |
572 * @param None | 572 * @param None |
573 * @retval None | 573 * @retval None |
574 */ | 574 */ |
575 | 575 |
576 void SystemClock_Config(void) | 576 void SystemClock_Config(void) { |
577 { | 577 if (hasExternalClock()) |
578 if( hasExternalClock() ) | 578 SystemClock_Config_HSE(); |
579 SystemClock_Config_HSE(); | 579 else |
580 else | 580 SystemClock_Config_HSI(); |
581 SystemClock_Config_HSI(); | 581 } |
582 } | 582 |
583 | 583 void SYSCLKConfig_STOP(void) { |
584 void SYSCLKConfig_STOP(void) | 584 SYSCLKConfig_STOP_HSI(); |
585 { | 585 } |
586 SYSCLKConfig_STOP_HSI(); | 586 |
587 } | 587 void SystemClock_Config_HSE(void) { |
588 | 588 RCC_OscInitTypeDef RCC_OscInitStruct; |
589 void SystemClock_Config_HSE(void) | 589 RCC_ClkInitTypeDef RCC_ClkInitStruct; |
590 { | |
591 RCC_OscInitTypeDef RCC_OscInitStruct; | |
592 RCC_ClkInitTypeDef RCC_ClkInitStruct; | |
593 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | 590 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
594 | 591 |
595 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); | 592 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); |
596 | 593 |
597 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); | 594 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
598 | 595 |
599 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; | 596 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; |
600 RCC_OscInitStruct.HSEState = RCC_HSE_ON; | 597 RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
601 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; | 598 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; |
602 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | 599 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
603 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; | 600 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
604 RCC_OscInitStruct.PLL.PLLM = 8; | 601 RCC_OscInitStruct.PLL.PLLM = 8; |
605 RCC_OscInitStruct.PLL.PLLN = 320; | 602 RCC_OscInitStruct.PLL.PLLN = 320; |
606 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | 603 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; |
607 RCC_OscInitStruct.PLL.PLLQ = 4; | 604 RCC_OscInitStruct.PLL.PLLQ = 4; |
608 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | 605 HAL_RCC_OscConfig(&RCC_OscInitStruct); |
609 | 606 |
610 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | 607 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
611 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; | 608 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
612 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | 609 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
613 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | 610 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
614 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | 611 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
615 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | 612 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
616 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 ); | 613 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); |
617 | 614 |
618 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | 615 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; |
619 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | 616 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; |
620 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | 617 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); |
621 | 618 |
622 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); | 619 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
623 | 620 |
624 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); | 621 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
625 | 622 |
626 /* SysTick_IRQn interrupt configuration */ | 623 /* SysTick_IRQn interrupt configuration */ |
627 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); | 624 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
628 } | 625 } |
629 | 626 |
630 void SystemClock_Config_HSI(void) | 627 void SystemClock_Config_HSI(void) { |
631 { | 628 RCC_ClkInitTypeDef RCC_ClkInitStruct; |
632 RCC_ClkInitTypeDef RCC_ClkInitStruct; | 629 RCC_OscInitTypeDef RCC_OscInitStruct; |
633 RCC_OscInitTypeDef RCC_OscInitStruct; | 630 |
634 | 631 /* Enable Power Control clock */ |
635 /* Enable Power Control clock */ | 632 __HAL_RCC_PWR_CLK_ENABLE(); |
636 __HAL_RCC_PWR_CLK_ENABLE(); | 633 |
637 | 634 /* The voltage scaling allows optimizing the power consumption when the device is |
638 /* The voltage scaling allows optimizing the power consumption when the device is | 635 clocked below the maximum system frequency, to update the voltage scaling value |
639 clocked below the maximum system frequency, to update the voltage scaling value | 636 regarding system frequency refer to product datasheet. */ |
640 regarding system frequency refer to product datasheet. */ | 637 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); |
641 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); | 638 |
642 | 639 /* Enable HSI Oscillator and activate PLL with HSI as source */ |
643 /* Enable HSI Oscillator and activate PLL with HSI as source */ | 640 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
644 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | 641 RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
645 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | 642 RCC_OscInitStruct.HSICalibrationValue = 0x10; |
646 RCC_OscInitStruct.HSICalibrationValue = 0x10; | 643 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
647 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | 644 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; |
648 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; | 645 RCC_OscInitStruct.PLL.PLLM = 16; |
649 RCC_OscInitStruct.PLL.PLLM = 16; | 646 RCC_OscInitStruct.PLL.PLLN = 320; |
650 RCC_OscInitStruct.PLL.PLLN = 320; | 647 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; |
651 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; | 648 RCC_OscInitStruct.PLL.PLLQ = 4; |
652 RCC_OscInitStruct.PLL.PLLQ = 4; | 649 HAL_RCC_OscConfig(&RCC_OscInitStruct); |
653 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | 650 |
654 | 651 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
655 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | 652 clocks dividers */ |
656 clocks dividers */ | 653 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |
657 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | 654 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
658 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); | 655 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
659 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | 656 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
660 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; | 657 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; |
661 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; | 658 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
662 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; | 659 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); |
663 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 ); | |
664 } | 660 } |
665 /* | 661 /* |
666 RCC_OscInitTypeDef RCC_OscInitStruct; | 662 RCC_OscInitTypeDef RCC_OscInitStruct; |
667 RCC_ClkInitTypeDef RCC_ClkInitStruct; | 663 RCC_ClkInitTypeDef RCC_ClkInitStruct; |
668 | 664 |
705 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL | 701 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL |
706 * and select PLL as system clock source. | 702 * and select PLL as system clock source. |
707 * @param None | 703 * @param None |
708 * @retval None | 704 * @retval None |
709 */ | 705 */ |
710 void SYSCLKConfig_STOP_HSE(void) | 706 void SYSCLKConfig_STOP_HSE(void) { |
711 { | 707 RCC_ClkInitTypeDef RCC_ClkInitStruct; |
712 RCC_ClkInitTypeDef RCC_ClkInitStruct; | 708 RCC_OscInitTypeDef RCC_OscInitStruct; |
713 RCC_OscInitTypeDef RCC_OscInitStruct; | 709 uint32_t pFLatency = 0; |
714 uint32_t pFLatency = 0; | 710 |
715 | 711 /* Get the Oscillators configuration according to the internal RCC registers */ |
716 /* Get the Oscillators configuration according to the internal RCC registers */ | 712 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); |
717 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); | 713 |
718 | 714 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
719 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ | 715 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
720 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; | 716 RCC_OscInitStruct.HSIState = RCC_HSE_ON; |
721 RCC_OscInitStruct.HSIState = RCC_HSE_ON; | 717 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
722 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | 718 HAL_RCC_OscConfig(&RCC_OscInitStruct); |
723 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | 719 |
724 | 720 /* Get the Clocks configuration according to the internal RCC registers */ |
725 /* Get the Clocks configuration according to the internal RCC registers */ | 721 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); |
726 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); | 722 |
727 | 723 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
728 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | 724 clocks dividers */ |
729 clocks dividers */ | 725 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; |
730 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | 726 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
731 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | 727 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); |
732 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency ); | 728 } |
733 } | 729 |
734 | 730 void SYSCLKConfig_STOP_HSI(void) { |
735 void SYSCLKConfig_STOP_HSI(void) | 731 RCC_ClkInitTypeDef RCC_ClkInitStruct; |
736 { | 732 RCC_OscInitTypeDef RCC_OscInitStruct; |
737 RCC_ClkInitTypeDef RCC_ClkInitStruct; | 733 uint32_t pFLatency = 0; |
738 RCC_OscInitTypeDef RCC_OscInitStruct; | 734 |
739 uint32_t pFLatency = 0; | 735 /* Get the Oscillators configuration according to the internal RCC registers */ |
740 | 736 HAL_RCC_GetOscConfig(&RCC_OscInitStruct); |
741 /* Get the Oscillators configuration according to the internal RCC registers */ | 737 |
742 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); | 738 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ |
743 | 739 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
744 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ | 740 RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
745 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; | 741 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
746 RCC_OscInitStruct.HSIState = RCC_HSI_ON; | 742 RCC_OscInitStruct.HSICalibrationValue = 0x10; |
747 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; | 743 HAL_RCC_OscConfig(&RCC_OscInitStruct); |
748 RCC_OscInitStruct.HSICalibrationValue = 0x10; | 744 |
749 HAL_RCC_OscConfig( &RCC_OscInitStruct ); | 745 /* Get the Clocks configuration according to the internal RCC registers */ |
750 | 746 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency); |
751 /* Get the Clocks configuration according to the internal RCC registers */ | 747 |
752 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); | 748 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
753 | 749 clocks dividers */ |
754 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 | 750 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; |
755 clocks dividers */ | 751 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
756 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; | 752 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency); |
757 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; | |
758 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency ); | |
759 } | 753 } |
760 | 754 |
761 /** | 755 /** |
762 * @brief SYSTICK callback | 756 * @brief SYSTICK callback |
763 * @param None | 757 * @param None |
764 * @retval None | 758 * @retval None |
765 */ | 759 */ |
766 void HAL_SYSTICK_Callback(void) | 760 void HAL_SYSTICK_Callback(void) { |
767 { | 761 HAL_IncTick(); |
768 HAL_IncTick(); | |
769 } | 762 } |
770 | 763 |
771 /** | 764 /** |
772 * @brief Configures GPIO for LED | 765 * @brief Configures GPIO for LED |
773 * Might move with STM32Cube usage | 766 * Might move with STM32Cube usage |
794 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); | 787 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); |
795 HAL_Delay(10); | 788 HAL_Delay(10); |
796 } | 789 } |
797 */ | 790 */ |
798 | 791 |
799 static void GPIO_LED_Init(void) | 792 static void GPIO_LED_Init(void) { |
800 { | 793 GPIO_InitTypeDef GPIO_InitStructure; |
801 GPIO_InitTypeDef GPIO_InitStructure; | 794 |
802 | 795 __GPIOC_CLK_ENABLE(); |
803 __GPIOC_CLK_ENABLE(); | 796 GPIO_InitStructure.Pin = GPIO_PIN_3; |
804 GPIO_InitStructure.Pin = GPIO_PIN_3; | 797 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
805 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 798 GPIO_InitStructure.Pull = GPIO_PULLUP; |
806 GPIO_InitStructure.Pull = GPIO_PULLUP; | 799 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; |
807 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | 800 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); |
808 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); | 801 } |
809 } | 802 |
810 | 803 void GPIO_new_DEBUG_Init(void) { |
811 void GPIO_new_DEBUG_Init(void) | |
812 { | |
813 #ifdef DEBUG_PIN_ACTIVE | 804 #ifdef DEBUG_PIN_ACTIVE |
814 GPIO_InitTypeDef GPIO_InitStructure; | 805 GPIO_InitTypeDef GPIO_InitStructure; |
815 | 806 |
816 __GPIOC_CLK_ENABLE(); | 807 __GPIOC_CLK_ENABLE(); |
817 GPIO_InitStructure.Pin = GPIO_PIN_3; | 808 GPIO_InitStructure.Pin = GPIO_PIN_3; |
818 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 809 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
819 GPIO_InitStructure.Pull = GPIO_PULLUP; | 810 GPIO_InitStructure.Pull = GPIO_PULLUP; |
820 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; | 811 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; |
821 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); | 812 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
822 #endif | 813 #endif |
823 } | 814 } |
824 | 815 |
825 void GPIO_new_DEBUG_LOW(void) | 816 void GPIO_new_DEBUG_LOW(void) { |
826 { | |
827 #ifdef DEBUG_PIN_ACTIVE | 817 #ifdef DEBUG_PIN_ACTIVE |
828 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); | 818 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); |
829 #endif | 819 #endif |
830 } | 820 } |
831 | 821 |
832 void GPIO_new_DEBUG_HIGH(void) | 822 void GPIO_new_DEBUG_HIGH(void) { |
833 { | |
834 #ifdef DEBUG_PIN_ACTIVE | 823 #ifdef DEBUG_PIN_ACTIVE |
835 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); | 824 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); |
836 #endif | 825 #endif |
837 } | 826 } |
838 | 827 |
839 static void GPIO_Power_MainCPU_Init(void) | 828 static void GPIO_Power_MainCPU_Init(void) { |
840 { | 829 GPIO_InitTypeDef GPIO_InitStructure; |
841 GPIO_InitTypeDef GPIO_InitStructure; | 830 __GPIOC_CLK_ENABLE(); |
842 __GPIOC_CLK_ENABLE(); | 831 GPIO_InitStructure.Pin = GPIO_PIN_0; |
843 GPIO_InitStructure.Pin = GPIO_PIN_0; | 832 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
844 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 833 GPIO_InitStructure.Pull = GPIO_PULLUP; |
845 GPIO_InitStructure.Pull = GPIO_PULLUP; | 834 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
846 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | 835 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure); |
847 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); | 836 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); |
848 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); | 837 } |
849 } | 838 |
850 | 839 static void GPIO_Power_MainCPU_ON(void) { |
851 static void GPIO_Power_MainCPU_ON(void) | 840 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); |
852 { | 841 } |
853 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); | 842 |
854 } | 843 static void GPIO_Power_MainCPU_OFF(void) { |
855 | 844 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET); |
856 static void GPIO_Power_MainCPU_OFF(void) | |
857 { | |
858 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_SET ); | |
859 } | 845 } |
860 | 846 |
861 /** | 847 /** |
862 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode | 848 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode |
863 * @param None | 849 * @param None |
864 * @retval None | 850 * @retval None |
865 */ | 851 */ |
866 | 852 |
867 static void EXTI_Wakeup_Button_Init(void) | 853 static void EXTI_Wakeup_Button_Init(void) { |
868 { | 854 GPIO_InitTypeDef GPIO_InitStructure; |
869 GPIO_InitTypeDef GPIO_InitStructure; | 855 |
870 | 856 __HAL_RCC_GPIOA_CLK_ENABLE(); |
871 __HAL_RCC_GPIOA_CLK_ENABLE(); | 857 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); |
872 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); | 858 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
873 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | 859 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; |
874 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | 860 GPIO_InitStructure.Pull = GPIO_NOPULL; |
875 GPIO_InitStructure.Pull = GPIO_NOPULL; | 861 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); |
876 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); | 862 |
877 | 863 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0); |
878 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0 ); | 864 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn); |
879 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn ); | 865 } |
880 } | 866 |
881 | 867 static void EXTI_Wakeup_Button_DeInit(void) { |
882 static void EXTI_Wakeup_Button_DeInit(void) | 868 GPIO_InitTypeDef GPIO_InitStructure; |
883 { | 869 |
884 GPIO_InitTypeDef GPIO_InitStructure; | 870 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
885 | 871 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
886 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | 872 GPIO_InitStructure.Pull = GPIO_NOPULL; |
887 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | 873 |
888 GPIO_InitStructure.Pull = GPIO_NOPULL; | 874 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; |
889 | 875 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure); |
890 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; | 876 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn); |
891 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); | 877 } |
892 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn ); | 878 |
893 } | 879 static void EXTI_Test_Button_Init(void) { |
894 | 880 GPIO_InitTypeDef GPIO_InitStructure; |
895 static void EXTI_Test_Button_Init(void) | 881 |
896 { | 882 BUTTON_TEST_GPIO_CLK_ENABLE(); |
897 GPIO_InitTypeDef GPIO_InitStructure; | 883 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
898 | 884 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; |
899 BUTTON_TEST_GPIO_CLK_ENABLE(); | 885 GPIO_InitStructure.Pull = GPIO_PULLUP; |
900 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | 886 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); |
901 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | 887 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0); |
902 GPIO_InitStructure.Pull = GPIO_PULLUP; | 888 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn); |
903 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); | 889 } |
904 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0 ); | 890 |
905 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn ); | 891 static void EXTI_Test_Button_DeInit(void) { |
906 } | 892 GPIO_InitTypeDef GPIO_InitStructure; |
907 | 893 |
908 static void EXTI_Test_Button_DeInit(void) | 894 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
909 { | 895 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
910 GPIO_InitTypeDef GPIO_InitStructure; | 896 GPIO_InitStructure.Pull = GPIO_NOPULL; |
911 | 897 |
912 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | 898 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; |
913 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | 899 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure); |
914 GPIO_InitStructure.Pull = GPIO_NOPULL; | 900 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn); |
915 | 901 } |
916 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; | 902 |
917 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); | 903 static void MX_EXTI_wireless_Init(void) { |
918 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn ); | 904 GPIO_InitTypeDef GPIO_InitStructure; |
919 } | 905 |
920 | 906 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); |
921 static void MX_EXTI_wireless_Init(void) | 907 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; |
922 { | 908 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; |
923 GPIO_InitTypeDef GPIO_InitStructure; | 909 GPIO_InitStructure.Pull = GPIO_NOPULL; |
924 | 910 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); |
925 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); | 911 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, |
926 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | 912 GPIO_PIN_SET); |
927 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; | 913 |
928 GPIO_InitStructure.Pull = GPIO_NOPULL; | 914 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); |
929 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure ); | 915 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; |
930 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, | 916 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; |
931 GPIO_PIN_SET ); | 917 GPIO_InitStructure.Pull = GPIO_NOPULL; |
932 | 918 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); |
933 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); | 919 |
934 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | 920 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0); |
935 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; | 921 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn); |
936 GPIO_InitStructure.Pull = GPIO_NOPULL; | 922 |
937 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); | 923 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); |
938 | 924 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; |
939 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0 ); | 925 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; |
940 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn ); | 926 GPIO_InitStructure.Pull = GPIO_NOPULL; |
941 | 927 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); |
942 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); | 928 |
943 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | 929 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0); |
944 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | 930 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn); |
945 GPIO_InitStructure.Pull = GPIO_NOPULL; | 931 |
946 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); | 932 } |
947 | 933 |
948 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0 ); | 934 static void MX_EXTI_wireless_DeInit(void) { |
949 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn ); | 935 GPIO_InitTypeDef GPIO_InitStructure; |
950 | 936 |
951 } | 937 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; |
952 | 938 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; |
953 static void MX_EXTI_wireless_DeInit(void) | 939 GPIO_InitStructure.Pull = GPIO_NOPULL; |
954 { | 940 |
955 GPIO_InitTypeDef GPIO_InitStructure; | 941 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; |
956 | 942 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure); |
957 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; | 943 |
958 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; | 944 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; |
959 GPIO_InitStructure.Pull = GPIO_NOPULL; | 945 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure); |
960 | 946 |
961 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; | 947 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; |
962 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); | 948 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure); |
963 | 949 |
964 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; | 950 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn); |
965 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); | 951 HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn); |
966 | |
967 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; | |
968 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure ); | |
969 | |
970 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn ); | |
971 HAL_NVIC_DisableIRQ( WIRELSS_FALLING_IRQn ); | |
972 } | 952 } |
973 | 953 |
974 /* NUCLEO C 13 | 954 /* NUCLEO C 13 |
975 KEY_BUTTON_GPIO_CLK_ENABLE(); | 955 KEY_BUTTON_GPIO_CLK_ENABLE(); |
976 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; | 956 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; |
993 static uint8_t uwCounter = 0; | 973 static uint8_t uwCounter = 0; |
994 uwCounter = 1; | 974 uwCounter = 1; |
995 } | 975 } |
996 */ | 976 */ |
997 | 977 |
998 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) | 978 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
999 { | 979 |
1000 | 980 } |
1001 } | 981 |
1002 | 982 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) { |
1003 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) | 983 |
1004 { | 984 } |
1005 | 985 |
1006 } | 986 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) { |
1007 | 987 |
1008 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) | 988 } |
1009 { | 989 |
1010 | 990 void sleep_prepare(void) { |
1011 } | 991 EXTI_Wakeup_Button_Init(); |
1012 | 992 /* |
1013 void sleep_prepare(void) | 993 GPIO_InitStruct.Pull = GPIO_PULLUP; |
1014 { | 994 GPIO_InitStruct.Pin = GPIO_PIN_0; |
1015 EXTI_Wakeup_Button_Init(); | 995 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
1016 /* | 996 */ |
1017 GPIO_InitStruct.Pull = GPIO_PULLUP; | 997 compass_sleep(); |
1018 GPIO_InitStruct.Pin = GPIO_PIN_0; | 998 HAL_Delay(100); |
1019 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | 999 accelerator_sleep(); |
1020 */ | 1000 HAL_Delay(100); |
1021 compass_sleep(); | 1001 |
1022 HAL_Delay( 100 ); | 1002 I2C_DeInit(); |
1023 accelerator_sleep(); | 1003 MX_SPI_DeInit(); |
1024 HAL_Delay( 100 ); | 1004 MX_SPI3_DeInit(); |
1025 | 1005 ADCx_DeInit(); |
1026 I2C_DeInit(); | 1006 |
1027 MX_SPI_DeInit(); | 1007 GPIO_InitTypeDef GPIO_InitStruct; |
1028 MX_SPI3_DeInit(); | 1008 |
1029 ADCx_DeInit(); | 1009 __HAL_RCC_GPIOA_CLK_ENABLE(); |
1030 | 1010 __HAL_RCC_GPIOB_CLK_ENABLE(); |
1031 GPIO_InitTypeDef GPIO_InitStruct; | 1011 __HAL_RCC_GPIOC_CLK_ENABLE(); |
1032 | 1012 __HAL_RCC_GPIOH_CLK_ENABLE(); |
1033 __HAL_RCC_GPIOA_CLK_ENABLE(); | 1013 |
1034 __HAL_RCC_GPIOB_CLK_ENABLE(); | 1014 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
1035 __HAL_RCC_GPIOC_CLK_ENABLE(); | 1015 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
1036 __HAL_RCC_GPIOH_CLK_ENABLE(); | 1016 GPIO_InitStruct.Pull = GPIO_NOPULL; |
1037 | 1017 GPIO_InitStruct.Pin = GPIO_PIN_All; |
1038 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; | 1018 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); |
1039 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; | |
1040 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
1041 GPIO_InitStruct.Pin = GPIO_PIN_All; | |
1042 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct ); | |
1043 #ifdef DEBUGMODE | 1019 #ifdef DEBUGMODE |
1044 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ | 1020 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ |
1045 #endif | 1021 #endif |
1046 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct ); | 1022 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); |
1047 | 1023 |
1048 GPIO_InitStruct.Pin = GPIO_PIN_All | 1024 GPIO_InitStruct.Pin = |
1049 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ | 1025 GPIO_PIN_All |
1050 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct ); | 1026 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14 |
1051 | 1027 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/ |
1052 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | 1028 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); |
1029 | |
1030 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); | |
1053 #ifdef DEBUGMODE | 1031 #ifdef DEBUGMODE |
1054 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ | 1032 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ |
1055 #endif | 1033 #endif |
1056 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct ); | 1034 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); |
1057 | 1035 |
1058 GPIO_InitStruct.Pin = GPIO_PIN_All; | 1036 GPIO_InitStruct.Pin = GPIO_PIN_All; |
1059 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct ); | 1037 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); |
1060 | 1038 |
1061 GPIO_Power_MainCPU_OFF(); | 1039 GPIO_Power_MainCPU_OFF(); |
1062 | 1040 |
1063 #ifndef DEBUGMODE | 1041 #ifndef DEBUGMODE |
1064 __HAL_RCC_GPIOB_CLK_DISABLE(); | 1042 __HAL_RCC_GPIOB_CLK_DISABLE(); |
1065 #endif | 1043 #endif |
1066 __HAL_RCC_GPIOH_CLK_DISABLE(); | 1044 __HAL_RCC_GPIOH_CLK_DISABLE(); |
1067 | 1045 |
1068 HAL_Delay( 1000 ); | 1046 HAL_Delay(1000); |
1069 } | 1047 } |
1070 | 1048 |
1071 /* | 1049 /* |
1072 void sleep_test(void) | 1050 void sleep_test(void) |
1073 { | 1051 { |
1121 * @param line: assert_param error line source number | 1099 * @param line: assert_param error line source number |
1122 * @retval None | 1100 * @retval None |
1123 */ | 1101 */ |
1124 void assert_failed(uint8_t* file, uint32_t line) | 1102 void assert_failed(uint8_t* file, uint32_t line) |
1125 { | 1103 { |
1126 /* User can add his own implementation to report the file name and line number, | 1104 /* User can add his own implementation to report the file name and line number, |
1127 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ | 1105 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
1128 | 1106 |
1129 /* Infinite loop */ | 1107 /* Infinite loop */ |
1130 while (1) | 1108 while (1) |
1131 { | 1109 { |
1132 } | 1110 } |
1133 } | 1111 } |
1134 #endif | 1112 #endif |
1135 | 1113 |
1136 /** | 1114 /** |
1137 * @} | 1115 * @} |
1138 */ | 1116 */ |
1139 | 1117 /** |
1118 * @brief This function handles SysTick Handler. | |
1119 * @param None | |
1120 * @retval None | |
1121 */ | |
1122 | |
1123 /*TxRx only here. Every 100 ms.*/ | |
1124 uint8_t ticks100ms=0; | |
1125 void SysTick_Handler(void) | |
1126 { | |
1127 HAL_IncTick(); | |
1128 if(ticks100ms<100){ | |
1129 ticks100ms++; | |
1130 }else | |
1131 { | |
1132 ticks100ms=0; | |
1133 } | |
1134 } | |
1140 /** | 1135 /** |
1141 * @} | 1136 * @} |
1142 */ | 1137 */ |
1143 | 1138 |
1144 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | 1139 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |