int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Init I/O ports */ Init_GPIOs (); /* Initializes ADC */ ADC_Icc_Init(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); while (1) { switch( State ) { case 0: //LED3 off and LED4 off blink = 0; GPIOB_ODR_value = 0x00000000; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 1: //LED3 on and LED4 off blink = 0; GPIOB_ODR_value = 0x00000080; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 2: //LED3 off and LED4 on blink = 0; GPIOB_ODR_value = 0x00000040; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; break; case 3: //LED3 and LED4 blink with 2 second period blink = 1; break; } if(blink == 1) { GPIOB_ODR_value = 0x000000C0; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; Delay(100); GPIOB_ODR_value = 0x00000000; ptr_PORTB->GPIOx_ODR = GPIOB_ODR_value; Delay(100); } } return(0); }
/** * @brief Current measurement in different MCU modes: * RUN/SLEEP/LowPower/STANDBY with/without RTC * @caller main and ADC_Icc_Test * @param MCU state * @retval ADC value. */ uint16_t ADC_Icc_Test(uint8_t Mcu_State) { GPIO_InitTypeDef GPIO_InitStructure; uint16_t adc_measure; uint32_t i; RCC_TypeDef SavRCC; /* Reset UserButton State */ UserButton = FALSE; /* Start counter */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Disable the RTC Wakeup Interrupt */ RTC_ITConfig(RTC_IT_WUT, DISABLE); /* Disable LCD */ LCD_Cmd(DISABLE); /* wait until LCD disable */ while (LCD_GetFlagStatus(LCD_FLAG_ENS) == SET); /*Reset Idd-WakeUP flag*/ Idd_WakeUP = FALSE; /* Set IO in lowpower configuration*/ GPIO_LowPower_Config(); /*Disable fast wakeUp*/ PWR_FastWakeUpCmd(DISABLE); /* Test MCU state for configuration */ switch (Mcu_State) { /* Run mode : Measurement Measurement performed with MSI 4 MHz without RTC*/ case MCU_RUN: /* switch on MSI clock */ SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; /* shitch on MSI clock */ Config_RCC(&SavRCC); SysTick->CTRL = 0; RCC->APB1ENR = 0; /* To run nops during measurement: it's the best case for low current */ for (i=0;i<0xffff;i++) { __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } break; /* SLEEP mode : Measurement performed with MSI 4 MHz without RTC in WFI mode*/ case MCU_SLEEP: SetHSICLKToMSI(RCC_MSIRange_6,NoDIV2,NoRTC) ; Config_RCC(&SavRCC); Config_Systick_50ms(); Delay(1); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_ON,PWR_SLEEPEntry_WFI); break; /* RUN LOW POWER mode : Measurement performed with MSI 32 Khz without RTC */ case MCU_LP_RUN: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable The ultra Low Power Mode */ PWR_UltraLowPowerCmd(ENABLE); /* Save the RCC configuration registers */ Config_RCC(&SavRCC); /* Stop the sys tick in order to avoid IT */ SysTick->CTRL = 0; #ifdef TESTINRAM SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; DisableInterrupts(); EnterLPRUNModeRAM(); EnableInterrupts(); #else /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_64KHz,DIV2,NoRTC) ; PWR_EnterLowPowerRunMode(ENABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) == RESET) ; /* Launch the counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* To run the nop during measurement: it's the best case for low current until counter reach detected by IT --> Idd_WakeUP */ do{ __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); } while (Idd_WakeUP == FALSE ); #endif PWR_EnterLowPowerRunMode(DISABLE); while(PWR_GetFlagStatus(PWR_FLAG_REGLP) != RESET) ; break; /* SLEEP LOW POWER mode Measurement done to MSI 32 Khz without RTC */ case MCU_LP_SLEEP: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; #ifdef TESTINRAM DisableInterrupts(); EnterLPSLEEPModeRAM(); EnableInterrupts(); #else /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSleepMode(PWR_Regulator_LowPower,PWR_SLEEPEntry_WFI); #endif break; /* STOP modes Measurement done to MSI 32 Khz without or with RTC */ case MCU_STOP_NoRTC: case MCU_STOP_RTC: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); /* To save the RCC configuration registers */ Config_RCC(&SavRCC); /* To stop the sys tick for avoid IT */ SysTick->CTRL = 0; /* Swith in MSI 32KHz */ if( Mcu_State == MCU_STOP_NoRTC ) SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; else SetHSICLKToMSI(RCC_MSIRange_0,DIV2,WITHRTC) ; /* Falling edge for start counter */ GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); /* Request Wait For Interrupt */ PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); break; /* Standby mode without RTC Measurement done to MSI 32 Khz without RTC */ case MCU_STBY: /* Disable PVD */ PWR_PVDCmd(DISABLE); /* Enable Ultra low power mode */ PWR_UltraLowPowerCmd(ENABLE); RTC_OutputTypeConfig(RTC_OutputType_PushPull); RTC_OutputConfig(RTC_Output_WakeUp,RTC_OutputPolarity_High); /* To configure PC13 WakeUP output */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ; //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_Init( GPIOC, &GPIO_InitStructure); // GPIO_Init( GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOC, GPIO_PinSource13,GPIO_AF_RTC_AF1) ; //GPIO_PinAFConfig(GPIOA, GPIO_PinSource0,GPIO_AF_RTC_AF1) ; Config_RCC(&SavRCC); SysTick->CTRL = 0; /* Swith in MSI 32KHz */ SetHSICLKToMSI(RCC_MSIRange_0,DIV2,NoRTC) ; PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE); PWR_UltraLowPowerCmd(ENABLE); PWR_EnterSTANDBYMode(); /* Stop here WakeUp EXIT on RESET */ break; } SetHSICLK(); Config_Systick(); RCC->AHBENR = SavRCC.AHBENR; PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Read ADC for current measurmeent */ adc_measure = Current_Measurement(); /* ICC_CNT_EN Hi */ GPIO_HIGH(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN); UserButton = TRUE; /* To restore RCC registers */ RCC->APB1ENR = SavRCC.APB1ENR; RCC->APB2ENR = SavRCC.APB2ENR; RCC->AHBLPENR = SavRCC.AHBLPENR; RCC->APB1LPENR = SavRCC.APB1LPENR; RCC->APB2LPENR = SavRCC.APB2LPENR; /* Need to reinit RCC for LCD*/ RCC_Configuration(); PWR_EnterLowPowerRunMode(DISABLE); /* Disable Ultra low power mode */ PWR_UltraLowPowerCmd(DISABLE); /* Disable FLASH during SLeep LP */ FLASH_SLEEPPowerDownCmd(DISABLE); Restore_GPIO_Config(); /* Clear Wake Up flag */ PWR_ClearFlag(PWR_FLAG_WU); /* Enable PVD */ PWR_PVDCmd(ENABLE); LCD_GLASS_Init(); return (adc_measure); }
int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Init I/O ports */ Init_GPIOs (); /* Initializes ADC */ ADC_Icc_Init(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); // EECE 337 Code -- Start int N; int f; char str[8]; N = 10; // Call to original factorial algorithm in C - for debugging //f = factorial_orig( N ); factorial(&f, N); // Copy result to f sprintf (str, "%X", f); //printf( "factorial of %i is %i\n", N, f); LCD_GLASS_DisplayString(str); // EECE 337 Code -- End return(0); }
int main(void) { bool StanbyWakeUp ; float Current_STBY; /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32l1xx_md.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ Int_CurrentSTBY = Current_Measurement(); /* Check if the StandBy flag is set */ if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET) { /* System resumed from STANDBY mode */ /* Clear StandBy flag */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_ClearFlag(PWR_FLAG_SB); StanbyWakeUp = TRUE; } else { StanbyWakeUp = FALSE; } PWR_PVDCmd(DISABLE); RCC_Configuration(); PWR_VoltageScalingConfig(PWR_VoltageScaling_Range1); /* Wait Until the Voltage Regulator is ready */ while (PWR_GetFlagStatus(PWR_FLAG_VOS) != RESET) ; /* Init I/O ports */ Init_GPIOs (); /* Initializes ADC */ ADC_Icc_Init(); enableInterrupts(); /* Warning ! in TSL Init the sysTick interrupt is setted to: SysTick_Config(RCC_Clocks.HCLK_Frequency / 2000 ---> 500 µs*/ /* Init Touch Sensing configuration */ TSL_Init(); sMCKeyInfo[0].Setting.b.IMPLEMENTED = 1; sMCKeyInfo[0].Setting.b.ENABLED = 1; sMCKeyInfo[0].DxSGroup = 0x00; /* Initializes the LCD glass */ LCD_GLASS_Init(); // EECE 337 Code -- Start char str[50]; // Used to display results unsigned int delay_time = 5000; // Will delay for 5 seconds const unsigned int numItems = 10; // # items in array int MyArray[10] = { 365, 245, -499, 0, 23, 8, 200, -4, -50, 25 }; int minimum = 0; // Will hold minimum value int maximum = 0; // Will hold maximum value // Call Function to obtain Min and Max values from array min_max(MyArray, numItems, &minimum, &maximum); // Copy min result to str sprintf (str, "%d", minimum); // Display on LCD LCD_GLASS_DisplayString(str); // Pause for 5 seconds Delay(delay_time); // Clear LCD LCD_GLASS_Clear(); // Copy max result to str sprintf (str, "%d", maximum); // Display on LCD LCD_GLASS_DisplayString(str); // Pause for 5 seconds Delay(delay_time); // EECE 337 Code -- End return(0); }