added some comments

This commit is contained in:
reivax-boucoi 2020-11-22 21:34:50 +01:00
parent d534824a18
commit 8ea6f2832c
2 changed files with 25 additions and 36 deletions

View file

@ -17,20 +17,20 @@ volatile uint32_t msTicks = 0;
volatile uint8_t expe = 0;
volatile uint8_t blue_mode = 0;
void SysTick_Handler()
void SysTick_Handler() //occurs every 10ms
{
if ( BLUE_BUTTON() ){
if ( BLUE_BUTTON() ){ //switch to blue mode if blue button was pressed
blue_mode = 1 ;
}
msTicks++; /* See startup file startup_LPC17xx.s for SysTick vector */
if (msTicks == 5 * expe){
msTicks++; //increment time counter
if (msTicks == 5 * expe){ //turn off led after 50ms*expe
LED_GREEN(0);
}else if(msTicks >= 200){
}else if(msTicks >= 200){ //turn on led every 2 seconds
msTicks = 0;
LED_GREEN(1);
}
if(expe == 2 || expe == 4){
if(expe == 2 || expe == 4){ //output a 50Hz clock on PC10 to evaluate frequency stability for expe 2 & 4
CLK_TOGGLE();
}
}
@ -50,8 +50,8 @@ int main(void)
LL_PWR_EnableBkUpAccess();
//expe = register RTC
expe = RTC->BKP0R;
if (expe == 0) {
expe = RTC->BKP0R; //Load expe number from backup register
if (expe == 0) { //if cold start : setup clock, LSE & set expe to 1
SystemClock_Config_24M_LSE();
expe = 1;
LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
@ -59,11 +59,11 @@ int main(void)
RTC->BKP0R = expe;
}
if (BLUE_BUTTON()){
if (BLUE_BUTTON()){ //if blue_button is pressed at reset, switch to next expe
expe ++;
blue_mode = 0;
if (expe > 8) expe = 1;
if (expe > 8) expe = 1; //rollover to expe 1
RTC->BKP0R = expe;
}
// }else{
@ -72,7 +72,6 @@ int main(void)
LL_PWR_DisableBkUpAccess();
switch(expe){
case 1:
/* Configure the system clock */
SystemClock_Config_80M();
//Setup Sleep mode
@ -107,7 +106,7 @@ int main(void)
}
// init systick timer (tick period at 1 ms)
// init systick timer (tick period at 10 ms)
LL_Init1msTick( SystemCoreClock );
LL_SYSTICK_EnableIT();
@ -117,7 +116,7 @@ int main(void)
while (1) {
if (blue_mode){
switch(expe){
case 5:
case 5: //cases 5-7 : start stop mode, and reconfigure at wakeup
case 6:
case 7:
LL_LPM_EnableDeepSleep();
@ -130,7 +129,7 @@ int main(void)
LL_SYSTICK_EnableIT();
break;
case 8:
LL_LPM_EnableDeepSleep();
LL_LPM_EnableDeepSleep(); //case 8 : shutdown (wakeup=>reset)
RTC_wakeup_init_from_standby_or_shutdown(10);
case 1:
case 3:
@ -138,18 +137,22 @@ int main(void)
break;
case 2:
case 4:
LL_RCC_MSI_EnablePLLMode();
LL_RCC_MSI_EnablePLLMode(); //case 4 : enable MSI calibration
break;
}
}else{
if (expe > 4) {
if (expe > 4) { //expe 5-8 : sleep as normal mode
LL_LPM_EnableSleep();
__WFI();
}
}
}
}
/**
* @brief System Clock Configuration
* @retval None
* 24Mhz + RTC + LSE + Flash latency 3 + Voltage scaling 2
*/
void SystemClock_Config_24M_LSE_FL3_VS2(void){
LL_APB1_GRP1_EnableClock( LL_APB1_GRP1_PERIPH_PWR );
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
@ -205,12 +208,6 @@ void SystemClock_Config_24M_LSE_FL3_VS2(void){
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_SetSystemCoreClock(24000000);
/* Update the time base */
if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
{
// Error_Handler();
}
}
/**
@ -274,15 +271,13 @@ void SystemClock_Config_24M_LSE(void)
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_SetSystemCoreClock(24000000);
/* Update the time base */
if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
{
// Error_Handler();
}
}
/**
* @brief System Clock Configuration
* @retval None
* 80MHz using PLL,default flash latency and voltage scaling
*/
void SystemClock_Config_80M(void)
{
LL_FLASH_SetLatency(LL_FLASH_LATENCY_4);
@ -320,12 +315,6 @@ void SystemClock_Config_80M(void)
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
LL_SetSystemCoreClock(80000000);
/* Update the time base */
if (HAL_InitTick (TICK_INT_PRIORITY) != HAL_OK)
{
// Error_Handler();
}
}
// partie commune a toutes les utilisations du wakeup timer

Binary file not shown.