No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

backup.txt 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Project L476_ats_blink for STM32L476 mounted on Nucleo board:
  2. * the user LED (mounted on pin PA-5) is flashed every second for 50 ms.
  3. * The time base is provided by Systick (1000 ticks per second).
  4. * The clock configuration is the default one (Sysclk = 80 MHz, derived from MSI and PLL).
  5. */
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "main.h"
  8. // #if defined(USE_FULL_ASSERT)
  9. // #include "stm32_assert.h"
  10. // #endif /* USE_FULL_ASSERT */
  11. #include "gpio.h"
  12. // systick interrupt handler
  13. volatile uint32_t msTicks = 0;
  14. volatile uint8_t expe = 2;
  15. volatile uint8_t blue_mode = 0;
  16. void SysTick_Handler()
  17. {
  18. if ( BLUE_BUTTON() ){
  19. blue_mode = 1 ;
  20. }
  21. msTicks++; /* See startup file startup_LPC17xx.s for SysTick vector */
  22. if (msTicks == 5 * expe){
  23. LED_GREEN(0);
  24. }else if(msTicks >= 200){
  25. msTicks = 0;
  26. LED_GREEN(1);
  27. }
  28. if(expe == 2){
  29. CLK_TOGGLE();
  30. }
  31. }
  32. int main(void)
  33. {
  34. // if (RCC->BDCR & RCC_BDCR_LSEON) {
  35. // LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
  36. // LL_PWR_EnableBkUpAccess();
  37. //
  38. // //expe = register RTC
  39. // expe = RTC->BKP0R;
  40. // if (expe == 0){
  41. // expe = 1;
  42. // RTC->BKP0R = expe;
  43. // }else if (expe != 0 && BLUE_BUTTON()){
  44. // expe ++;
  45. // RTC->BKP0R = expe;
  46. // }
  47. // }else{
  48. // SystemClock_Config_24M_LSE();
  49. // expe = 1;
  50. // LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
  51. // LL_PWR_EnableBkUpAccess();
  52. // RTC->BKP0R = expe;
  53. // }
  54. // LL_PWR_DisableBkUpAccess();
  55. switch(expe){
  56. case 1:
  57. /* Configure the system clock */
  58. SystemClock_Config_80M();
  59. break;
  60. case 2:
  61. /* Configure the system clock */
  62. SystemClock_Config_24M_LSE();
  63. break;
  64. }
  65. // config GPIO
  66. GPIO_init();
  67. // init systick timer (tick period at 1 ms)
  68. LL_Init1msTick( SystemCoreClock );
  69. LL_SYSTICK_EnableIT();
  70. //Setup Sleep mode
  71. LL_LPM_EnableSleep();
  72. //LL_LPM_EnableSleepOnExit();
  73. while (1) {
  74. if (blue_mode){
  75. switch(expe){
  76. case 1:
  77. __WFI();
  78. break;
  79. case 2:
  80. LL_RCC_MSI_EnablePLLMode();
  81. break;
  82. }
  83. }
  84. }
  85. }
  86. /**
  87. * @brief System Clock Configuration
  88. * @retval None
  89. * 24Mhz + RTC + LSE
  90. */
  91. void SystemClock_Config_24M_LSE(void)
  92. {
  93. LL_FLASH_SetLatency(LL_FLASH_LATENCY_1);
  94. while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_1)
  95. {
  96. }
  97. LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
  98. LL_RCC_MSI_Enable();
  99. /* Wait till MSI is ready */
  100. while(LL_RCC_MSI_IsReady() != 1)
  101. {
  102. }
  103. LL_RCC_LSE_Enable();
  104. /* Wait till LSE is ready */
  105. while(LL_RCC_LSE_IsReady() != 1)
  106. {
  107. }
  108. LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE);
  109. LL_RCC_EnableRTC();
  110. LL_RCC_MSI_EnableRangeSelection();
  111. LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
  112. LL_RCC_MSI_SetCalibTrimming(0);
  113. // LL_RCC_MSI_EnablePLLMode();
  114. LL_PWR_EnableBkUpAccess();
  115. LL_RCC_ForceBackupDomainReset();
  116. LL_RCC_ReleaseBackupDomainReset();
  117. LL_RCC_LSE_SetDriveCapability(LL_RCC_LSEDRIVE_LOW);
  118. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_MSI, LL_RCC_PLLM_DIV_1, 24, LL_RCC_PLLR_DIV_4);
  119. LL_RCC_PLL_EnableDomain_SYS();
  120. LL_RCC_PLL_Enable();
  121. /* Wait till PLL is ready */
  122. while(LL_RCC_PLL_IsReady() != 1)
  123. {
  124. }
  125. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  126. /* Wait till System clock is ready */
  127. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  128. {
  129. }
  130. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  131. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  132. LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
  133. LL_SetSystemCoreClock(24000000);
  134. /* Update the time base */
  135. if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
  136. {
  137. // Error_Handler();
  138. }
  139. }
  140. void SystemClock_Config_80M(void)
  141. {
  142. LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
  143. while(LL_FLASH_GetLatency()!= LL_FLASH_LATENCY_4)
  144. {
  145. }
  146. LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
  147. LL_RCC_MSI_Enable();
  148. /* Wait till MSI is ready */
  149. while(LL_RCC_MSI_IsReady() != 1)
  150. {
  151. }
  152. LL_RCC_MSI_EnableRangeSelection();
  153. LL_RCC_MSI_SetRange(LL_RCC_MSIRANGE_6);
  154. LL_RCC_MSI_SetCalibTrimming(0);
  155. LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_MSI, LL_RCC_PLLM_DIV_1, 40, LL_RCC_PLLR_DIV_2);
  156. LL_RCC_PLL_EnableDomain_SYS();
  157. LL_RCC_PLL_Enable();
  158. /* Wait till PLL is ready */
  159. while(LL_RCC_PLL_IsReady() != 1)
  160. {
  161. }
  162. LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
  163. /* Wait till System clock is ready */
  164. while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
  165. {
  166. }
  167. LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
  168. LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
  169. LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
  170. LL_SetSystemCoreClock(80000000);
  171. /* Update the time base */
  172. if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
  173. {
  174. // Error_Handler();
  175. }
  176. }