comparison Small_CPU/Src/baseCPU2.c @ 115:3834b6272ee5 FlipDisplay

Merge with 68181cd61f2069d061621c2cd2a6afddb7486f5e
author Ideenmodellierer
date Thu, 03 Jan 2019 19:59:36 +0100
parents 68181cd61f20
children 6347a86caa18
comparison
equal deleted inserted replaced
114:79b19d56ab08 115:3834b6272ee5
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 = 5,
169 .versionFirst = 1, 168 .versionThird = 1,
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
290 int main(void) 282 int main(void) {
291 { 283 HAL_Init();
292 HAL_Init(); 284 SystemClock_Config();
293 SystemClock_Config(); 285
294 286 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
295 HAL_SYSTICK_Config( HAL_RCC_GetHCLKFreq() / 1000 ); 287 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK);
296 HAL_SYSTICK_CLKSourceConfig( SYSTICK_CLKSOURCE_HCLK ); 288 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
297 HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 ); 289
298 290 MX_RTC_init();
299 MX_RTC_init(); 291 GPIO_LED_Init();
300 GPIO_LED_Init(); 292 GPIO_new_DEBUG_Init(); // added 170322 hw
301 GPIO_new_DEBUG_Init(); // added 170322 hw 293 initGlobals();
302 initGlobals(); 294
303 295 printf("CPU2-RTE running...\n");
304 printf("CPU2-RTE running...\n"); 296
305 297 MX_I2C1_Init();
306 MX_I2C1_Init(); 298 if (global.I2C_SystemStatus != HAL_OK) {
307 if( global.I2C_SystemStatus != HAL_OK ) 299 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) {
308 { 300 MX_I2C1_TestAndClear(); // do it a second time
309 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) 301 }
310 { 302 MX_I2C1_Init();
311 MX_I2C1_TestAndClear(); // do it a second time 303 }
312 } 304
313 MX_I2C1_Init(); 305 //dangerous: TM_OTP_Write(0,0, 0x01);
314 }
315
316 //dangerous: TM_OTP_Write(0,0, 0x01);
317 #ifdef REGULAR_RUN 306 #ifdef REGULAR_RUN
318 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); 307 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure();
319 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; 308 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID];
320 if( global.I2C_SystemStatus != HAL_OK ) 309 if (global.I2C_SystemStatus != HAL_OK) {
321 { 310 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) {
322 if( MX_I2C1_TestAndClear() == GPIO_PIN_RESET ) 311 MX_I2C1_TestAndClear(); // do it a second time
323 { 312 }
324 MX_I2C1_TestAndClear(); // do it a second time 313 MX_I2C1_Init();
325 } 314 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure();
326 MX_I2C1_Init(); 315 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID];
327 global.sensorError[SENSOR_PRESSURE_ID] = init_pressure(); 316 }
328 global.I2C_SystemStatus = global.sensorError[SENSOR_PRESSURE_ID]; 317
329 } 318 global.dataSendToMaster.sensorErrors =
330 319 global.sensorError[SENSOR_PRESSURE_ID];
331 global.dataSendToMaster.sensorErrors = 320 init_surface_ring();
332 global.sensorError[SENSOR_PRESSURE_ID]; 321 init_battery_gas_gauge();
333 init_surface_ring(); 322 HAL_Delay(10);
334 init_battery_gas_gauge(); 323 battery_gas_gauge_get_data();
335 HAL_Delay( 10 );
336 battery_gas_gauge_get_data();
337 // battery_gas_gauge_set(0); 324 // battery_gas_gauge_set(0);
338 325
339 global.lifeData.battery_voltage = get_voltage(); 326 global.lifeData.battery_voltage = get_voltage();
340 global.lifeData.battery_charge = get_charge(); 327 global.lifeData.battery_charge = get_charge();
341 copyBatteryData(); 328 copyBatteryData();
342 329
343 MX_SPI3_Init(); 330 MX_SPI3_Init();
344 if( !scheduleSetButtonResponsiveness() ) 331 if (!scheduleSetButtonResponsiveness()) {
345 { 332 HAL_Delay(1);
346 HAL_Delay( 1 ); 333 scheduleSetButtonResponsiveness(); // init
347 scheduleSetButtonResponsiveness(); // init 334 HAL_Delay(1);
348 HAL_Delay( 1 ); 335 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. 336 {
350 { 337 HAL_Delay(1);
351 HAL_Delay( 1 ); 338 scheduleSetButtonResponsiveness(); // init
352 scheduleSetButtonResponsiveness(); // init 339 HAL_Delay(1);
353 HAL_Delay( 1 ); 340 }
354 } 341 }
355 } 342
356 343 ADCx_Init();
357 ADCx_Init(); 344 GPIO_Power_MainCPU_Init();
358 GPIO_Power_MainCPU_Init(); 345 global.mode = MODE_POWERUP;
359 global.mode = MODE_POWERUP;
360 #else 346 #else
361 init_pressure(); 347 init_pressure();
362 init_surface_ring(); 348 init_surface_ring();
363 349
364 ADCx_Init(); 350 ADCx_Init();
365 GPIO_Power_MainCPU_Init(); 351 GPIO_Power_MainCPU_Init();
366 global.mode = MODE_TEST; 352 global.mode = MODE_TEST;
367 #endif 353 #endif
368 while( 1 ) 354 while (1) {
369 { 355 printf("Global mode = %d\n", global.mode);
370 printf("Global mode = %d\n", global.mode); 356
371 357 switch (global.mode) {
372 switch( global.mode ) 358 case MODE_POWERUP:
373 { 359 case MODE_BOOT:
374 case MODE_POWERUP: 360 // ReInit_battery_charger_status_pins();
375 case MODE_BOOT: 361 compass_init(0, 7);
376 // ReInit_battery_charger_status_pins(); 362 accelerator_init();
377 compass_init( 0, 7 ); 363 wireless_init();
378 accelerator_init(); 364 if (global.mode == MODE_BOOT) {
379 wireless_init(); 365 GPIO_Power_MainCPU_OFF();
380 if( global.mode == MODE_BOOT ) 366 HAL_Delay(100); // for GPIO_Power_MainCPU_ON();
381 { 367 GPIO_Power_MainCPU_ON();
382 GPIO_Power_MainCPU_OFF(); 368 }
383 HAL_Delay( 100 ); // for GPIO_Power_MainCPU_ON(); 369 SPI_synchronize_with_Master();
384 GPIO_Power_MainCPU_ON(); 370 MX_DMA_Init();
385 } 371 MX_SPI1_Init();
386 SPI_synchronize_with_Master(); 372 MX_EXTI_wireless_Init();
387 MX_DMA_Init(); 373 // SPI_Start_single_TxRx_with_Master();
388 MX_SPI1_Init(); 374 EXTI_Test_Button_Init();
389 MX_EXTI_wireless_Init(); 375
390 SPI_Start_single_TxRx_with_Master(); 376 /*
391 EXTI_Test_Button_Init(); 377 uint8_t dataWireless[64];
392 378 while(1)
393 /* 379 {
394 uint8_t dataWireless[64]; 380 wireless_evaluate_and_debug(dataWireless,64);
395 while(1) 381 }
396 { 382 */
397 wireless_evaluate_and_debug(dataWireless,64); 383 global.mode = MODE_SURFACE;
398 } 384 break;
399 */ 385
400 global.mode = MODE_SURFACE; 386 case MODE_CALIB:
401 break;
402
403 case MODE_CALIB:
404 scheduleCompassCalibrationMode(); 387 scheduleCompassCalibrationMode();
405 break; 388 break;
406 389
407 case MODE_SURFACE: 390 case MODE_SURFACE:
408 scheduleSurfaceMode(); 391 scheduleSurfaceMode();
409 break; 392 break;
410 393
411 case MODE_TEST: 394 case MODE_TEST:
412 GPIO_Power_MainCPU_ON(); 395 break;
413 SPI_synchronize_with_Master(); 396
414 MX_DMA_Init(); 397 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; 398 backup.no_fly_time_minutes = global.no_fly_time_minutes;
425 backup.seconds_since_last_dive = global.seconds_since_last_dive; 399 backup.seconds_since_last_dive = global.seconds_since_last_dive;
426 400
427 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive, 401 vpm_init( &global.vpm, global.conservatism, global.repetitive_dive,
428 global.seconds_since_last_dive ); 402 global.seconds_since_last_dive );
452 global.lifeData.dive_time_seconds_without_surface_time = 0; 426 global.lifeData.dive_time_seconds_without_surface_time = 0;
453 global.lifeData.counterSecondsShallowDepth = 0; 427 global.lifeData.counterSecondsShallowDepth = 0;
454 428
455 backup.no_fly_time_minutes = 0; 429 backup.no_fly_time_minutes = 0;
456 backup.seconds_since_last_dive = 0; 430 backup.seconds_since_last_dive = 0;
457 break; 431 break;
458 432
459 case MODE_SHUTDOWN: 433 case MODE_SHUTDOWN:
460 HAL_Delay( 200 ); 434 HAL_Delay(200);
461 global.mode = MODE_SLEEP; 435 global.mode = MODE_SLEEP;
462 MX_SPI3_Init(); 436 MX_SPI3_Init();
463 break; 437 break;
464 438
465 case MODE_SLEEP: 439 case MODE_SLEEP:
466 /* 440 /*
467 sleep_prepare(); 441 sleep_prepare();
468 scheduleSleepMode_test(); 442 scheduleSleepMode_test();
469 */ 443 */
470 /* 444 /*
471 GPIO_Power_MainCPU_OFF(); 445 GPIO_Power_MainCPU_OFF();
472 EXTI_Test_Button_DeInit(); 446 EXTI_Test_Button_DeInit();
473 EXTI_Wakeup_Button_Init(); 447 EXTI_Wakeup_Button_Init();
474 NOT_USED_AT_THE_MOMENT_scheduleSleepMode(); 448 NOT_USED_AT_THE_MOMENT_scheduleSleepMode();
475 */ 449 */
476 EXTI_Test_Button_DeInit(); 450 EXTI_Test_Button_DeInit();
477 MX_EXTI_wireless_DeInit(); 451 MX_EXTI_wireless_DeInit();
478 if( hasExternalClock() ) 452 if (hasExternalClock())
479 SystemClock_Config_HSI(); 453 SystemClock_Config_HSI();
480 sleep_prepare(); 454 sleep_prepare();
481 455
482 GPIO_LED_Init(); 456 GPIO_LED_Init();
483 457
484 scheduleSleepMode(); 458 scheduleSleepMode();
485 if( hasExternalClock() ) 459 if (hasExternalClock())
486 SystemClock_Config_HSE(); 460 SystemClock_Config_HSE();
487 GPIO_LED_Init(); 461 GPIO_LED_Init();
488 EXTI_Wakeup_Button_DeInit(); 462 EXTI_Wakeup_Button_DeInit();
489 ADCx_Init(); 463 ADCx_Init();
490 GPIO_Power_MainCPU_Init(); 464 GPIO_Power_MainCPU_Init();
491 GPIO_Power_MainCPU_ON(); 465 GPIO_Power_MainCPU_ON();
492 compass_init( 0, 7 ); 466 compass_init(0, 7);
493 accelerator_init(); 467 accelerator_init();
494 wireless_init(); 468 wireless_init();
495 SPI_synchronize_with_Master(); 469 // SPI_synchronize_with_Master(); TODO: REMOVE
496 MX_DMA_Init(); 470 MX_DMA_Init();
497 MX_SPI1_Init(); 471 MX_SPI1_Init();
498 MX_EXTI_wireless_Init(); 472 MX_EXTI_wireless_Init();
499 SPI_Start_single_TxRx_with_Master(); 473 // SPI_Start_single_TxRx_with_Master();
500 474
501 // EXTILine0_Button_DeInit(); not now, later after testing 475 // EXTILine0_Button_DeInit(); not now, later after testing
502 break; 476 break;
503 } 477 }
504 } 478 }
505 } 479 }
506 480
507 /** @brief Button feedback - EXTI line detection callbacks 481 /** @brief Button feedback - EXTI line detection callbacks
508 * @param GPIO_Pin: Specifies the pins connected EXTI line 482 * @param GPIO_Pin: Specifies the pins connected EXTI line
509 * @retval None 483 * @retval None
510 */ 484 */
511 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) 485 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
512 { 486
513 487 if (GPIO_Pin == WIRELSS_RISING_GPIO_PIN) {
514 if( GPIO_Pin == WIRELSS_RISING_GPIO_PIN ) 488 wireless_trigger_RisingEdgeSilence();
515 { 489 }
516 wireless_trigger_RisingEdgeSilence(); 490
517 } 491 else
518 492
519 else 493 if (GPIO_Pin == WIRELSS_FALLING_GPIO_PIN) {
520 494 wireless_trigger_FallingEdgeSignalHigh();
521 if( GPIO_Pin == WIRELSS_FALLING_GPIO_PIN ) 495 }
522 { 496
523 wireless_trigger_FallingEdgeSignalHigh(); 497 else
524 } 498
525 499 if (GPIO_Pin == BUTTON_OSTC_GPIO_PIN) {
526 else 500 if (global.mode == MODE_SLEEP) {
527 501 global.mode = MODE_BOOT;
528 if( GPIO_Pin == BUTTON_OSTC_GPIO_PIN ) 502 }
529 { 503 }
530 if( global.mode == MODE_SLEEP ) 504
531 { 505 else
532 global.mode = MODE_BOOT; 506
533 } 507 if (GPIO_Pin == BUTTON_TEST_GPIO_PIN) {
534 } 508 if (!global.demo_mode && (global.mode == MODE_SURFACE)) {
535 509 global.demo_mode = 1;
536 else 510 global.mode = MODE_DIVE;
537 511 } else if (global.demo_mode && (global.mode == MODE_DIVE)
538 if( GPIO_Pin == BUTTON_TEST_GPIO_PIN ) 512 && (global.lifeData.dive_time_seconds > 10)) {
539 { 513 global.demo_mode = 0;
540 if( !global.demo_mode && (global.mode == MODE_SURFACE) ) 514 global.dataSendToMaster.mode = MODE_ENDDIVE;
541 { 515 global.deviceDataSendToMaster.mode = MODE_ENDDIVE;
542 global.demo_mode = 1; 516 }
543 global.mode = MODE_DIVE; 517 }
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 } 518 }
554 519
555 /** 520 /**
556 * @brief System Clock Configuration 521 * @brief System Clock Configuration
557 * The system Clock is configured as follow : 522 * The system Clock is configured as follow :
571 * Flash Latency(WS) = 3 536 * Flash Latency(WS) = 3
572 * @param None 537 * @param None
573 * @retval None 538 * @retval None
574 */ 539 */
575 540
576 void SystemClock_Config(void) 541 void SystemClock_Config(void) {
577 { 542 if (hasExternalClock())
578 if( hasExternalClock() ) 543 SystemClock_Config_HSE();
579 SystemClock_Config_HSE(); 544 else
580 else 545 SystemClock_Config_HSI();
581 SystemClock_Config_HSI(); 546 }
582 } 547
583 548 void SYSCLKConfig_STOP(void) {
584 void SYSCLKConfig_STOP(void) 549 SYSCLKConfig_STOP_HSI();
585 { 550 }
586 SYSCLKConfig_STOP_HSI(); 551
587 } 552 void SystemClock_Config_HSE(void) {
588 553 RCC_OscInitTypeDef RCC_OscInitStruct;
589 void SystemClock_Config_HSE(void) 554 RCC_ClkInitTypeDef RCC_ClkInitStruct;
590 {
591 RCC_OscInitTypeDef RCC_OscInitStruct;
592 RCC_ClkInitTypeDef RCC_ClkInitStruct;
593 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 555 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
594 556
595 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); 557 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE();
596 558
597 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); 559 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
598 560
599 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; 561 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE;
600 RCC_OscInitStruct.HSEState = RCC_HSE_ON; 562 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
601 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; 563 //RCC_OscInitStruct.LSEState = RCC_LSE_ON;
602 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 564 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
603 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 565 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
604 RCC_OscInitStruct.PLL.PLLM = 8; 566 RCC_OscInitStruct.PLL.PLLM = 8;
605 RCC_OscInitStruct.PLL.PLLN = 320; 567 RCC_OscInitStruct.PLL.PLLN = 320;
606 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; 568 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
607 RCC_OscInitStruct.PLL.PLLQ = 4; 569 RCC_OscInitStruct.PLL.PLLQ = 4;
608 HAL_RCC_OscConfig( &RCC_OscInitStruct ); 570 HAL_RCC_OscConfig(&RCC_OscInitStruct);
609 571
610 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK 572 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
611 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; 573 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
612 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 574 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
613 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 575 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
614 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 576 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
615 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 577 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
616 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 ); 578 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
617 579
618 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; 580 // PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
619 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; 581 // PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
620 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 582 // HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
621 583
622 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 584 // HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
623 585
624 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 586 // HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
625 587
626 /* SysTick_IRQn interrupt configuration */ 588 /* SysTick_IRQn interrupt configuration */
627 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 589 // HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
628 } 590 }
629 591
630 void SystemClock_Config_HSI(void) 592 void SystemClock_Config_HSI(void) {
631 { 593 RCC_ClkInitTypeDef RCC_ClkInitStruct;
632 RCC_ClkInitTypeDef RCC_ClkInitStruct; 594 RCC_OscInitTypeDef RCC_OscInitStruct;
633 RCC_OscInitTypeDef RCC_OscInitStruct; 595
634 596 /* Enable Power Control clock */
635 /* Enable Power Control clock */ 597 __HAL_RCC_PWR_CLK_ENABLE();
636 __HAL_RCC_PWR_CLK_ENABLE(); 598
637 599 /* 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 600 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 601 regarding system frequency refer to product datasheet. */
640 regarding system frequency refer to product datasheet. */ 602 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
641 __HAL_PWR_VOLTAGESCALING_CONFIG( PWR_REGULATOR_VOLTAGE_SCALE2 ); 603
642 604 /* Enable HSI Oscillator and activate PLL with HSI as source */
643 /* Enable HSI Oscillator and activate PLL with HSI as source */ 605 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
644 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 606 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
645 RCC_OscInitStruct.HSIState = RCC_HSI_ON; 607 RCC_OscInitStruct.HSICalibrationValue = 0x10;
646 RCC_OscInitStruct.HSICalibrationValue = 0x10; 608 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
647 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 609 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
648 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 610 RCC_OscInitStruct.PLL.PLLM = 16;
649 RCC_OscInitStruct.PLL.PLLM = 16; 611 RCC_OscInitStruct.PLL.PLLN = 320;
650 RCC_OscInitStruct.PLL.PLLN = 320; 612 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
651 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; 613 RCC_OscInitStruct.PLL.PLLQ = 4;
652 RCC_OscInitStruct.PLL.PLLQ = 4; 614 HAL_RCC_OscConfig(&RCC_OscInitStruct);
653 HAL_RCC_OscConfig( &RCC_OscInitStruct ); 615
654 616 /* 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 617 clocks dividers */
656 clocks dividers */ 618 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK
657 RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK 619 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
658 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); 620 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
659 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 621 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
660 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 622 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
661 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 623 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
662 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 624 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
663 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, FLASH_LATENCY_2 );
664 } 625 }
665 /* 626 /*
666 RCC_OscInitTypeDef RCC_OscInitStruct; 627 RCC_OscInitTypeDef RCC_OscInitStruct;
667 RCC_ClkInitTypeDef RCC_ClkInitStruct; 628 RCC_ClkInitTypeDef RCC_ClkInitStruct;
668 629
705 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL 666 * @brief Configures system clock after wake-up from STOP: enable HSI, PLL
706 * and select PLL as system clock source. 667 * and select PLL as system clock source.
707 * @param None 668 * @param None
708 * @retval None 669 * @retval None
709 */ 670 */
710 void SYSCLKConfig_STOP_HSE(void) 671 void SYSCLKConfig_STOP_HSE(void) {
711 { 672 RCC_ClkInitTypeDef RCC_ClkInitStruct;
712 RCC_ClkInitTypeDef RCC_ClkInitStruct; 673 RCC_OscInitTypeDef RCC_OscInitStruct;
713 RCC_OscInitTypeDef RCC_OscInitStruct; 674 uint32_t pFLatency = 0;
714 uint32_t pFLatency = 0; 675
715 676 /* Get the Oscillators configuration according to the internal RCC registers */
716 /* Get the Oscillators configuration according to the internal RCC registers */ 677 HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
717 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); 678
718 679 /* 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 */ 680 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
720 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 681 RCC_OscInitStruct.HSIState = RCC_HSE_ON;
721 RCC_OscInitStruct.HSIState = RCC_HSE_ON; 682 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
722 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 683 HAL_RCC_OscConfig(&RCC_OscInitStruct);
723 HAL_RCC_OscConfig( &RCC_OscInitStruct ); 684
724 685 /* Get the Clocks configuration according to the internal RCC registers */
725 /* Get the Clocks configuration according to the internal RCC registers */ 686 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
726 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); 687
727 688 /* 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 689 clocks dividers */
729 clocks dividers */ 690 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
730 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; 691 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
731 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 692 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency);
732 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency ); 693 }
733 } 694
734 695 void SYSCLKConfig_STOP_HSI(void) {
735 void SYSCLKConfig_STOP_HSI(void) 696 RCC_ClkInitTypeDef RCC_ClkInitStruct;
736 { 697 RCC_OscInitTypeDef RCC_OscInitStruct;
737 RCC_ClkInitTypeDef RCC_ClkInitStruct; 698 uint32_t pFLatency = 0;
738 RCC_OscInitTypeDef RCC_OscInitStruct; 699
739 uint32_t pFLatency = 0; 700 /* Get the Oscillators configuration according to the internal RCC registers */
740 701 HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
741 /* Get the Oscillators configuration according to the internal RCC registers */ 702
742 HAL_RCC_GetOscConfig( &RCC_OscInitStruct ); 703 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */
743 704 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
744 /* After wake-up from STOP reconfigure the system clock: Enable HSI and PLL */ 705 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
745 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 706 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
746 RCC_OscInitStruct.HSIState = RCC_HSI_ON; 707 RCC_OscInitStruct.HSICalibrationValue = 0x10;
747 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 708 HAL_RCC_OscConfig(&RCC_OscInitStruct);
748 RCC_OscInitStruct.HSICalibrationValue = 0x10; 709
749 HAL_RCC_OscConfig( &RCC_OscInitStruct ); 710 /* Get the Clocks configuration according to the internal RCC registers */
750 711 HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
751 /* Get the Clocks configuration according to the internal RCC registers */ 712
752 HAL_RCC_GetClockConfig( &RCC_ClkInitStruct, &pFLatency ); 713 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
753 714 clocks dividers */
754 /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 715 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
755 clocks dividers */ 716 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
756 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; 717 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency);
757 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
758 HAL_RCC_ClockConfig( &RCC_ClkInitStruct, pFLatency );
759 } 718 }
760 719
761 /** 720 /**
762 * @brief SYSTICK callback 721 * @brief SYSTICK callback
763 * @param None 722 * @param None
764 * @retval None 723 * @retval None
765 */ 724 */
766 void HAL_SYSTICK_Callback(void) 725 void HAL_SYSTICK_Callback(void) {
767 { 726 HAL_IncTick();
768 HAL_IncTick();
769 } 727 }
770 728
771 /** 729 /**
772 * @brief Configures GPIO for LED 730 * @brief Configures GPIO for LED
773 * Might move with STM32Cube usage 731 * Might move with STM32Cube usage
794 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET); 752 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,GPIO_PIN_RESET);
795 HAL_Delay(10); 753 HAL_Delay(10);
796 } 754 }
797 */ 755 */
798 756
799 static void GPIO_LED_Init(void) 757 static void GPIO_LED_Init(void) {
800 { 758 GPIO_InitTypeDef GPIO_InitStructure;
801 GPIO_InitTypeDef GPIO_InitStructure; 759
802 760 __GPIOC_CLK_ENABLE();
803 __GPIOC_CLK_ENABLE(); 761 GPIO_InitStructure.Pin = GPIO_PIN_3;
804 GPIO_InitStructure.Pin = GPIO_PIN_3; 762 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
805 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 763 GPIO_InitStructure.Pull = GPIO_PULLUP;
806 GPIO_InitStructure.Pull = GPIO_PULLUP; 764 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
807 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 765 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure);
808 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); 766 }
809 } 767
810 768 void GPIO_new_DEBUG_Init(void) {
811 void GPIO_new_DEBUG_Init(void)
812 {
813 #ifdef DEBUG_PIN_ACTIVE 769 #ifdef DEBUG_PIN_ACTIVE
814 GPIO_InitTypeDef GPIO_InitStructure; 770 GPIO_InitTypeDef GPIO_InitStructure;
815 771
816 __GPIOC_CLK_ENABLE(); 772 __GPIOC_CLK_ENABLE();
817 GPIO_InitStructure.Pin = GPIO_PIN_3; 773 GPIO_InitStructure.Pin = GPIO_PIN_3;
818 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 774 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
819 GPIO_InitStructure.Pull = GPIO_PULLUP; 775 GPIO_InitStructure.Pull = GPIO_PULLUP;
820 GPIO_InitStructure.Speed = GPIO_SPEED_FAST; 776 GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
821 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); 777 HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
822 #endif 778 #endif
823 } 779 }
824 780
825 void GPIO_new_DEBUG_LOW(void) 781 void GPIO_new_DEBUG_LOW(void) {
826 {
827 #ifdef DEBUG_PIN_ACTIVE 782 #ifdef DEBUG_PIN_ACTIVE
828 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET); 783 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_RESET);
829 #endif 784 #endif
830 } 785 }
831 786
832 void GPIO_new_DEBUG_HIGH(void) 787 void GPIO_new_DEBUG_HIGH(void) {
833 {
834 #ifdef DEBUG_PIN_ACTIVE 788 #ifdef DEBUG_PIN_ACTIVE
835 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET); 789 HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3,GPIO_PIN_SET);
836 #endif 790 #endif
837 } 791 }
838 792
839 static void GPIO_Power_MainCPU_Init(void) 793 static void GPIO_Power_MainCPU_Init(void) {
840 { 794 GPIO_InitTypeDef GPIO_InitStructure;
841 GPIO_InitTypeDef GPIO_InitStructure; 795 __GPIOC_CLK_ENABLE();
842 __GPIOC_CLK_ENABLE(); 796 GPIO_InitStructure.Pin = GPIO_PIN_0;
843 GPIO_InitStructure.Pin = GPIO_PIN_0; 797 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
844 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 798 GPIO_InitStructure.Pull = GPIO_PULLUP;
845 GPIO_InitStructure.Pull = GPIO_PULLUP; 799 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
846 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 800 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure);
847 HAL_GPIO_Init( GPIOC, &GPIO_InitStructure ); 801 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);
848 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); 802 }
849 } 803
850 804 static void GPIO_Power_MainCPU_ON(void) {
851 static void GPIO_Power_MainCPU_ON(void) 805 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);
852 { 806 }
853 HAL_GPIO_WritePin( GPIOC, GPIO_PIN_0, GPIO_PIN_RESET ); 807
854 } 808 static void GPIO_Power_MainCPU_OFF(void) {
855 809 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 } 810 }
860 811
861 /** 812 /**
862 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode 813 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode
863 * @param None 814 * @param None
864 * @retval None 815 * @retval None
865 */ 816 */
866 817
867 static void EXTI_Wakeup_Button_Init(void) 818 static void EXTI_Wakeup_Button_Init(void) {
868 { 819 GPIO_InitTypeDef GPIO_InitStructure;
869 GPIO_InitTypeDef GPIO_InitStructure; 820
870 821 __HAL_RCC_GPIOA_CLK_ENABLE();
871 __HAL_RCC_GPIOA_CLK_ENABLE(); 822 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE();
872 BUTTON_OSTC_HAL_RCC_GPIO_CLK_ENABLE(); 823 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN;
873 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; 824 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
874 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; 825 GPIO_InitStructure.Pull = GPIO_NOPULL;
875 GPIO_InitStructure.Pull = GPIO_NOPULL; 826 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure);
876 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); 827
877 828 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0);
878 HAL_NVIC_SetPriority( BUTTON_OSTC_IRQn, 0x0F, 0 ); 829 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn);
879 HAL_NVIC_EnableIRQ( BUTTON_OSTC_IRQn ); 830 }
880 } 831
881 832 static void EXTI_Wakeup_Button_DeInit(void) {
882 static void EXTI_Wakeup_Button_DeInit(void) 833 GPIO_InitTypeDef GPIO_InitStructure;
883 { 834
884 GPIO_InitTypeDef GPIO_InitStructure; 835 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
885 836 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
886 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; 837 GPIO_InitStructure.Pull = GPIO_NOPULL;
887 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 838
888 GPIO_InitStructure.Pull = GPIO_NOPULL; 839 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN;
889 840 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure);
890 GPIO_InitStructure.Pin = BUTTON_OSTC_GPIO_PIN; 841 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn);
891 HAL_GPIO_Init( BUTTON_OSTC_GPIO_PORT, &GPIO_InitStructure ); 842 }
892 HAL_NVIC_DisableIRQ( BUTTON_OSTC_IRQn ); 843
893 } 844 static void EXTI_Test_Button_Init(void) {
894 845 GPIO_InitTypeDef GPIO_InitStructure;
895 static void EXTI_Test_Button_Init(void) 846
896 { 847 BUTTON_TEST_GPIO_CLK_ENABLE();
897 GPIO_InitTypeDef GPIO_InitStructure; 848 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN;
898 849 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
899 BUTTON_TEST_GPIO_CLK_ENABLE(); 850 GPIO_InitStructure.Pull = GPIO_PULLUP;
900 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; 851 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure);
901 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; 852 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0);
902 GPIO_InitStructure.Pull = GPIO_PULLUP; 853 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn);
903 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); 854 }
904 HAL_NVIC_SetPriority( BUTTON_TEST_IRQn, 0x0F, 0 ); 855
905 HAL_NVIC_EnableIRQ( BUTTON_TEST_IRQn ); 856 static void EXTI_Test_Button_DeInit(void) {
906 } 857 GPIO_InitTypeDef GPIO_InitStructure;
907 858
908 static void EXTI_Test_Button_DeInit(void) 859 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
909 { 860 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
910 GPIO_InitTypeDef GPIO_InitStructure; 861 GPIO_InitStructure.Pull = GPIO_NOPULL;
911 862
912 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; 863 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN;
913 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 864 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure);
914 GPIO_InitStructure.Pull = GPIO_NOPULL; 865 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn);
915 866 }
916 GPIO_InitStructure.Pin = BUTTON_TEST_GPIO_PIN; 867
917 HAL_GPIO_Init( BUTTON_TEST_GPIO_PORT, &GPIO_InitStructure ); 868 static void MX_EXTI_wireless_Init(void) {
918 HAL_NVIC_DisableIRQ( BUTTON_TEST_IRQn ); 869 GPIO_InitTypeDef GPIO_InitStructure;
919 } 870
920 871 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE();
921 static void MX_EXTI_wireless_Init(void) 872 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN;
922 { 873 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
923 GPIO_InitTypeDef GPIO_InitStructure; 874 GPIO_InitStructure.Pull = GPIO_NOPULL;
924 875 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure);
925 WIRELSS_POWER_HAL_RCC_GPIO_CLK_ENABLE(); 876 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN,
926 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN; 877 GPIO_PIN_SET);
927 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 878
928 GPIO_InitStructure.Pull = GPIO_NOPULL; 879 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE();
929 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure ); 880 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN;
930 HAL_GPIO_WritePin( WIRELSS_POWER_GPIO_PORT, WIRELSS_POWER_GPIO_PIN, 881 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
931 GPIO_PIN_SET ); 882 GPIO_InitStructure.Pull = GPIO_NOPULL;
932 883 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure);
933 WIRELSS_RISING_HAL_RCC_GPIO_CLK_ENABLE(); 884
934 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; 885 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0);
935 GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING; 886 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn);
936 GPIO_InitStructure.Pull = GPIO_NOPULL; 887
937 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); 888 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE();
938 889 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN;
939 HAL_NVIC_SetPriority( WIRELSS_RISING_IRQn, 0x02, 0 ); 890 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
940 HAL_NVIC_EnableIRQ( WIRELSS_RISING_IRQn ); 891 GPIO_InitStructure.Pull = GPIO_NOPULL;
941 892 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure);
942 WIRELSS_FALLING_HAL_RCC_GPIO_CLK_ENABLE(); 893
943 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; 894 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0);
944 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; 895 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn);
945 GPIO_InitStructure.Pull = GPIO_NOPULL; 896
946 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); 897 }
947 898
948 HAL_NVIC_SetPriority( WIRELSS_FALLING_IRQn, 0x02, 0 ); 899 static void MX_EXTI_wireless_DeInit(void) {
949 HAL_NVIC_EnableIRQ( WIRELSS_FALLING_IRQn ); 900 GPIO_InitTypeDef GPIO_InitStructure;
950 901
951 } 902 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
952 903 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
953 static void MX_EXTI_wireless_DeInit(void) 904 GPIO_InitStructure.Pull = GPIO_NOPULL;
954 { 905
955 GPIO_InitTypeDef GPIO_InitStructure; 906 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN;
956 907 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure);
957 GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; 908
958 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 909 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN;
959 GPIO_InitStructure.Pull = GPIO_NOPULL; 910 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure);
960 911
961 GPIO_InitStructure.Pin = WIRELSS_RISING_GPIO_PIN; 912 GPIO_InitStructure.Pin = WIRELSS_POWER_GPIO_PIN;
962 HAL_GPIO_Init( WIRELSS_RISING_GPIO_PORT, &GPIO_InitStructure ); 913 HAL_GPIO_Init( WIRELSS_POWER_GPIO_PORT, &GPIO_InitStructure);
963 914
964 GPIO_InitStructure.Pin = WIRELSS_FALLING_GPIO_PIN; 915 HAL_NVIC_DisableIRQ( WIRELSS_RISING_IRQn);
965 HAL_GPIO_Init( WIRELSS_FALLING_GPIO_PORT, &GPIO_InitStructure ); 916 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 } 917 }
973 918
974 /* NUCLEO C 13 919 /* NUCLEO C 13
975 KEY_BUTTON_GPIO_CLK_ENABLE(); 920 KEY_BUTTON_GPIO_CLK_ENABLE();
976 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; 921 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
993 static uint8_t uwCounter = 0; 938 static uint8_t uwCounter = 0;
994 uwCounter = 1; 939 uwCounter = 1;
995 } 940 }
996 */ 941 */
997 942
998 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) 943 void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *I2cHandle) {
999 { 944
1000 945 }
1001 } 946
1002 947 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) {
1003 void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *I2cHandle) 948
1004 { 949 }
1005 950
1006 } 951 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) {
1007 952
1008 void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle) 953 }
1009 { 954
1010 955 void sleep_prepare(void) {
1011 } 956 EXTI_Wakeup_Button_Init();
1012 957 /*
1013 void sleep_prepare(void) 958 GPIO_InitStruct.Pull = GPIO_PULLUP;
1014 { 959 GPIO_InitStruct.Pin = GPIO_PIN_0;
1015 EXTI_Wakeup_Button_Init(); 960 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
1016 /* 961 */
1017 GPIO_InitStruct.Pull = GPIO_PULLUP; 962 compass_sleep();
1018 GPIO_InitStruct.Pin = GPIO_PIN_0; 963 HAL_Delay(100);
1019 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 964 accelerator_sleep();
1020 */ 965 HAL_Delay(100);
1021 compass_sleep(); 966
1022 HAL_Delay( 100 ); 967 I2C_DeInit();
1023 accelerator_sleep(); 968 MX_SPI_DeInit();
1024 HAL_Delay( 100 ); 969 MX_SPI3_DeInit();
1025 970 ADCx_DeInit();
1026 I2C_DeInit(); 971
1027 MX_SPI_DeInit(); 972 GPIO_InitTypeDef GPIO_InitStruct;
1028 MX_SPI3_DeInit(); 973
1029 ADCx_DeInit(); 974 __HAL_RCC_GPIOA_CLK_ENABLE();
1030 975 __HAL_RCC_GPIOB_CLK_ENABLE();
1031 GPIO_InitTypeDef GPIO_InitStruct; 976 __HAL_RCC_GPIOC_CLK_ENABLE();
1032 977 __HAL_RCC_GPIOH_CLK_ENABLE();
1033 __HAL_RCC_GPIOA_CLK_ENABLE(); 978
1034 __HAL_RCC_GPIOB_CLK_ENABLE(); 979 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
1035 __HAL_RCC_GPIOC_CLK_ENABLE(); 980 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
1036 __HAL_RCC_GPIOH_CLK_ENABLE(); 981 GPIO_InitStruct.Pull = GPIO_NOPULL;
1037 982 GPIO_InitStruct.Pin = GPIO_PIN_All;
1038 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 983 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 984 #ifdef DEBUGMODE
1044 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ 985 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */
1045 #endif 986 #endif
1046 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct ); 987 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct);
1047 988
1048 GPIO_InitStruct.Pin = GPIO_PIN_All 989 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*/ 990 GPIO_PIN_All
1050 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct ); 991 ^ ( GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_14
1051 992 | GPIO_PIN_15); /* power off & charger in & charge out & OSC32*/
1052 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); 993 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct);
994
995 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0);
1053 #ifdef DEBUGMODE 996 #ifdef DEBUGMODE
1054 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ 997 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */
1055 #endif 998 #endif
1056 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct ); 999 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct);
1057 1000
1058 GPIO_InitStruct.Pin = GPIO_PIN_All; 1001 GPIO_InitStruct.Pin = GPIO_PIN_All;
1059 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct ); 1002 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct);
1060 1003
1061 GPIO_Power_MainCPU_OFF(); 1004 GPIO_Power_MainCPU_OFF();
1062 1005
1063 #ifndef DEBUGMODE 1006 #ifndef DEBUGMODE
1064 __HAL_RCC_GPIOB_CLK_DISABLE(); 1007 __HAL_RCC_GPIOB_CLK_DISABLE();
1065 #endif 1008 #endif
1066 __HAL_RCC_GPIOH_CLK_DISABLE(); 1009 __HAL_RCC_GPIOH_CLK_DISABLE();
1067 1010
1068 HAL_Delay( 1000 ); 1011 HAL_Delay(1000);
1069 } 1012 }
1070 1013
1071 /* 1014 /*
1072 void sleep_test(void) 1015 void sleep_test(void)
1073 { 1016 {
1121 * @param line: assert_param error line source number 1064 * @param line: assert_param error line source number
1122 * @retval None 1065 * @retval None
1123 */ 1066 */
1124 void assert_failed(uint8_t* file, uint32_t line) 1067 void assert_failed(uint8_t* file, uint32_t line)
1125 { 1068 {
1126 /* User can add his own implementation to report the file name and line number, 1069 /* 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) */ 1070 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
1128 1071
1129 /* Infinite loop */ 1072 /* Infinite loop */
1130 while (1) 1073 while (1)
1131 { 1074 {
1132 } 1075 }
1133 } 1076 }
1134 #endif 1077 #endif
1135 1078
1136 /** 1079 /**
1137 * @} 1080 * @}
1138 */ 1081 */
1139 1082 /**
1083 * @brief This function handles SysTick Handler.
1084 * @param None
1085 * @retval None
1086 */
1087
1088 /*TxRx only here. Every 100 ms.*/
1089 uint8_t ticks100ms=0;
1090 void SysTick_Handler(void)
1091 {
1092 HAL_IncTick();
1093 if(ticks100ms<100){
1094 ticks100ms++;
1095 }else
1096 {
1097 ticks100ms=0;
1098 SPI_Start_single_TxRx_with_Master();
1099 }
1100 }
1140 /** 1101 /**
1141 * @} 1102 * @}
1142 */ 1103 */
1143 1104
1144 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 1105 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/