comparison Small_CPU/Src/baseCPU2.c @ 887:17f02ac9da67 Evo_2_23

adding GNSS code
author heinrichsweikamp
date Tue, 03 Sep 2024 15:30:53 +0200
parents f012fcd7f465
children cf3967fe6924
comparison
equal deleted inserted replaced
886:d398ecc7d103 887:17f02ac9da67
214 214
215 #define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */ 215 #define VIBRATION_CONTROL_PIN GPIO_PIN_3 /* PortA */
216 #define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */ 216 #define LED_CONTROL_PIN_RED GPIO_PIN_2 /* PortA */
217 #define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */ 217 #define LED_CONTROL_PIN_GREEN GPIO_PIN_1 /* PortA */
218 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */ 218 #define MAINCPU_CONTROL_PIN GPIO_PIN_0 /* PortC */
219 #define GPS_POWER_CONTROL_PIN GPIO_PIN_15 /* PortB */
220 #define GPS_BCKP_CONTROL_PIN GPIO_PIN_14 /* PortB */
219 221
220 /* Private macro -------------------------------------------------------------*/ 222 /* Private macro -------------------------------------------------------------*/
221 223
222 /* Private variables ---------------------------------------------------------*/ 224 /* Private variables ---------------------------------------------------------*/
223 uint32_t global_test_time_counter = 0; 225 uint32_t global_test_time_counter = 0;
235 static void GPIO_LED_RED_ON(void); 237 static void GPIO_LED_RED_ON(void);
236 static void GPIO_LED_GREEN_OFF(void); 238 static void GPIO_LED_GREEN_OFF(void);
237 static void GPIO_LED_GREEN_ON(void); 239 static void GPIO_LED_GREEN_ON(void);
238 static void GPIO_VIBRATION_OFF(void); 240 static void GPIO_VIBRATION_OFF(void);
239 static void GPIO_VIBRATION_ON(void); 241 static void GPIO_VIBRATION_ON(void);
242 static void GPIO_GPS_OFF(void);
243 static void GPIO_GPS_ON(void);
244 static void GPIO_GPS_BCKP_OFF(void);
245 static void GPIO_GPS_BCKP_ON(void);
240 246
241 #ifdef DEBUG_I2C_LINES 247 #ifdef DEBUG_I2C_LINES
242 void GPIO_test_I2C_lines(void); 248 void GPIO_test_I2C_lines(void);
243 #endif 249 #endif
244 250
411 GPIO_LED_RED_ON(); 417 GPIO_LED_RED_ON();
412 GPIO_VIBRATION_ON(); 418 GPIO_VIBRATION_ON();
413 HAL_Delay(100); 419 HAL_Delay(100);
414 GPIO_LED_RED_OFF(); 420 GPIO_LED_RED_OFF();
415 GPIO_VIBRATION_OFF(); 421 GPIO_VIBRATION_OFF();
422 GPIO_GPS_ON();
423 GPIO_GPS_BCKP_ON();
416 } 424 }
417 SPI_synchronize_with_Master(); 425 SPI_synchronize_with_Master();
418 MX_DMA_Init(); 426 MX_DMA_Init();
419 MX_SPI1_Init(); 427 MX_SPI1_Init();
420 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */ 428 SPI_Start_single_TxRx_with_Master(); /* be prepared for the first data exchange */
474 global.mode = MODE_SLEEP; 482 global.mode = MODE_SLEEP;
475 MX_SPI3_Init(); 483 MX_SPI3_Init();
476 break; 484 break;
477 485
478 case MODE_SLEEP: 486 case MODE_SLEEP:
479 /*
480 sleep_prepare();
481 scheduleSleepMode_test();
482 */
483 /*
484 GPIO_Power_MainCPU_OFF();
485 EXTI_Test_Button_DeInit();
486 EXTI_Wakeup_Button_Init();
487 NOT_USED_AT_THE_MOMENT_scheduleSleepMode();
488 */
489
490 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF); 487 externalInterface_SwitchUART(EXT_INTERFACE_UART_OFF);
491 externalInterface_SwitchPower33(false); 488 externalInterface_SwitchPower33(false);
492 if (hasExternalClock()) 489 if (hasExternalClock())
493 SystemClock_Config_HSI(); 490 SystemClock_Config_HSI();
491 GPIO_LEDs_VIBRATION_Init();
494 sleep_prepare(); 492 sleep_prepare();
495
496 GPIO_LEDs_VIBRATION_Init();
497 493
498 scheduleSleepMode(); 494 scheduleSleepMode();
499 if (hasExternalClock()) 495 if (hasExternalClock())
500 SystemClock_Config_HSE(); 496 SystemClock_Config_HSE();
501 EXTI_Wakeup_Button_DeInit(); 497 EXTI_Wakeup_Button_DeInit();
595 RCC_ClkInitTypeDef RCC_ClkInitStruct; 591 RCC_ClkInitTypeDef RCC_ClkInitStruct;
596 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 592 // RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
597 593
598 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE(); 594 __PWR_CLK_ENABLE(); // is identical to __HAL_RCC_PWR_CLK_ENABLE();
599 595
600 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); 596 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
601 597
602 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE; 598 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; //|RCC_OSCILLATORTYPE_LSE;
603 RCC_OscInitStruct.HSEState = RCC_HSE_ON; 599 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
604 //RCC_OscInitStruct.LSEState = RCC_LSE_ON; 600 //RCC_OscInitStruct.LSEState = RCC_LSE_ON;
605 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 601 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
638 __HAL_RCC_PWR_CLK_ENABLE(); 634 __HAL_RCC_PWR_CLK_ENABLE();
639 635
640 /* The voltage scaling allows optimizing the power consumption when the device is 636 /* The voltage scaling allows optimizing the power consumption when the device is
641 clocked below the maximum system frequency, to update the voltage scaling value 637 clocked below the maximum system frequency, to update the voltage scaling value
642 regarding system frequency refer to product datasheet. */ 638 regarding system frequency refer to product datasheet. */
643 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); 639 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
644 640
645 /* Enable HSI Oscillator and activate PLL with HSI as source */ 641 /* Enable HSI Oscillator and activate PLL with HSI as source */
646 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 642 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
647 RCC_OscInitStruct.HSIState = RCC_HSI_ON; 643 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
648 RCC_OscInitStruct.HSICalibrationValue = 0x10; 644 RCC_OscInitStruct.HSICalibrationValue = 0x10;
662 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 658 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
663 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 659 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
664 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 660 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
665 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); 661 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
666 } 662 }
667 /* 663
668 RCC_OscInitTypeDef RCC_OscInitStruct;
669 RCC_ClkInitTypeDef RCC_ClkInitStruct;
670
671 __HAL_RCC_PWR_CLK_ENABLE();
672
673 //__PWR_CLK_ENABLE();
674
675 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
676
677 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
678 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
679 RCC_OscInitStruct.HSIState = RCC_HSI_ON;
680 RCC_OscInitStruct.HSICalibrationValue = 16;
681 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
682 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
683 RCC_OscInitStruct.PLL.PLLM = 16;
684 RCC_OscInitStruct.PLL.PLLN = 320;
685 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
686 RCC_OscInitStruct.PLL.PLLQ = 4;
687 HAL_RCC_OscConfig(&RCC_OscInitStruct);
688
689 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
690 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
691 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
692 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
693 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
694 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
695 }
696
697 static void RtcClock_Config(void)
698 {
699 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
700 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
701 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
702 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
703 }
704 */
705 664
706 /** 665 /**
707 * @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
708 * and select PLL as system clock source. 667 * and select PLL as system clock source.
709 * @param None 668 * @param None
814 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN; 773 GPIO_InitStructure.Pin = VIBRATION_CONTROL_PIN;
815 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 774 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
816 GPIO_InitStructure.Pull = GPIO_PULLDOWN; 775 GPIO_InitStructure.Pull = GPIO_PULLDOWN;
817 GPIO_InitStructure.Speed = GPIO_SPEED_LOW; 776 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
818 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure); 777 HAL_GPIO_Init( GPIOA, &GPIO_InitStructure);
778
779 __GPIOB_CLK_ENABLE();
780 GPIO_InitStructure.Pin = GPS_POWER_CONTROL_PIN;
781 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
782 GPIO_InitStructure.Pull = GPIO_PULLUP;
783 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
784 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure);
785
786 GPIO_InitStructure.Pin = GPS_BCKP_CONTROL_PIN;
787 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
788 GPIO_InitStructure.Pull = GPIO_PULLDOWN;
789 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
790 HAL_GPIO_Init( GPIOB, &GPIO_InitStructure);
791
819 } 792 }
820 793
821 void GPIO_new_DEBUG_Init(void) { 794 void GPIO_new_DEBUG_Init(void) {
822 #ifdef DEBUG_PIN_ACTIVE 795 #ifdef DEBUG_PIN_ACTIVE
823 GPIO_InitTypeDef GPIO_InitStructure; 796 GPIO_InitTypeDef GPIO_InitStructure;
884 857
885 static void GPIO_VIBRATION_OFF(void) { 858 static void GPIO_VIBRATION_OFF(void) {
886 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET); 859 HAL_GPIO_WritePin( GPIOA, VIBRATION_CONTROL_PIN, GPIO_PIN_RESET);
887 } 860 }
888 861
862 static void GPIO_GPS_ON(void) {
863 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_RESET);
864 }
865
866 static void GPIO_GPS_OFF(void) {
867 HAL_GPIO_WritePin( GPIOB, GPS_POWER_CONTROL_PIN, GPIO_PIN_SET);
868 }
869
870 static void GPIO_GPS_BCKP_ON(void) {
871 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_SET);
872 }
873
874 static void GPIO_GPS_BCKP_OFF(void) {
875 HAL_GPIO_WritePin( GPIOB, GPS_BCKP_CONTROL_PIN, GPIO_PIN_RESET);
876 }
877
889 878
890 /** 879 /**
891 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode 880 * @brief Configures EXTI Line0 (connected to PA0 + PA1 pin) in interrupt mode
892 * @param None 881 * @param None
893 * @retval None 882 * @retval None
964 __HAL_RCC_GPIOB_CLK_ENABLE(); 953 __HAL_RCC_GPIOB_CLK_ENABLE();
965 __HAL_RCC_GPIOC_CLK_ENABLE(); 954 __HAL_RCC_GPIOC_CLK_ENABLE();
966 __HAL_RCC_GPIOH_CLK_ENABLE(); 955 __HAL_RCC_GPIOH_CLK_ENABLE();
967 956
968 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; 957 GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
969 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 958 GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
970 GPIO_InitStruct.Pull = GPIO_NOPULL; 959 GPIO_InitStruct.Pull = GPIO_NOPULL;
971 GPIO_InitStruct.Pin = GPIO_PIN_All; 960 GPIO_InitStruct.Pin = GPIO_PIN_All;
972 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); 961 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct);
973 #ifdef DEBUGMODE 962 #ifdef DEBUGMODE
974 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */ 963 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_3 | GPIO_PIN_8 | GPIO_PIN_9); /* debug */
975 #endif 964 #endif
965
966 GPIO_InitStruct.Pin = GPIO_PIN_All ^ (GPS_POWER_CONTROL_PIN | GPS_BCKP_CONTROL_PIN);
976 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct); 967 HAL_GPIO_Init( GPIOB, &GPIO_InitStruct);
977 968
978 GPIO_InitStruct.Pin = 969 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | EXT33V_CONTROL_PIN); /* power off & charger in & charge out & OSC32 & ext33Volt */
979 GPIO_PIN_All
980 ^ ( MAINCPU_CONTROL_PIN | CHARGE_OUT_PIN | CHARGE_IN_PIN | EXT33V_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN); /* power off & charger in & charge out & OSC32 & ext33Volt */
981 970
982 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct); 971 HAL_GPIO_Init( GPIOC, &GPIO_InitStruct);
983 972
984 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0); 973 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | VIBRATION_CONTROL_PIN | LED_CONTROL_PIN_RED | LED_CONTROL_PIN_GREEN);
985 #ifdef DEBUGMODE 974 #ifdef DEBUGMODE
986 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */ 975 GPIO_InitStruct.Pin = GPIO_PIN_All ^ ( GPIO_PIN_0 | GPIO_PIN_13 | GPIO_PIN_14); /* wake up button & debug */
987 #endif 976 #endif
988 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct); 977 HAL_GPIO_Init( GPIOA, &GPIO_InitStruct);
989 978
991 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct); 980 HAL_GPIO_Init( GPIOH, &GPIO_InitStruct);
992 981
993 GPIO_Power_MainCPU_OFF(); 982 GPIO_Power_MainCPU_OFF();
994 GPIO_LED_GREEN_OFF(); 983 GPIO_LED_GREEN_OFF();
995 GPIO_LED_RED_OFF(); 984 GPIO_LED_RED_OFF();
985 GPIO_VIBRATION_OFF();
986 GPIO_GPS_BCKP_ON(); // mH : costs 100µA in sleep - beware
987 GPIO_GPS_OFF();
996 988
997 989
998 #ifndef DEBUGMODE 990 #ifndef DEBUGMODE
999 __HAL_RCC_GPIOB_CLK_DISABLE(); 991 __HAL_RCC_GPIOB_CLK_DISABLE();
1000 #endif 992 #endif