/**
  * @brief  This function configures the system to enter Standby mode with RTC 
  *         clocked by LSE or LSI for current consumption measurement purpose.
  *         STANDBY Mode with RTC clocked by LSE/LSI
  *         ========================================
  *           - RTC Clocked by LSE/LSI
  *           - IWDG OFF
  *           - Backup SRAM OFF
  *           - Automatic Wakeup using RTC clocked by LSE/LSI (after ~20s)
  * @param  None
  * @retval None
  */
void StandbyRTCMode_Measure(void)
{
  RTCHandle.Instance = RTC;  
  /* Configure RTC prescaler and RTC data registers as follow:
  - Hour Format = Format 24
  - Asynch Prediv = Value according to source clock
  - Synch Prediv = Value according to source clock
  - OutPut = Output Disable
  - OutPutPolarity = High Polarity
  - OutPutType = Open Drain */ 
  RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  
  if(HAL_RTC_Init(&RTCHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
  
  /*## Configure the Wake up timer ###########################################*/
  /*  RTC Wakeup Interrupt Generation:
      Wakeup Time Base = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI))
      Wakeup Time = Wakeup Time Base * WakeUpCounter 
                  = (RTC_WAKEUPCLOCK_RTCCLK_DIV /(LSI)) * WakeUpCounter
      ==> WakeUpCounter = Wakeup Time / Wakeup Time Base

      To configure the wake up timer to 20s the WakeUpCounter is set to 0xA017:
        RTC_WAKEUPCLOCK_RTCCLK_DIV = RTCCLK_Div16 = 16 
        Wakeup Time Base = 16 /(~32.768KHz) = ~0,488 ms
        Wakeup Time = ~20s = 0,488ms  * WakeUpCounter
        ==> WakeUpCounter = ~20s/0,488ms = 40983 = 0xA017 */
  /* Disable Wake-up timer */
  if(HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
  
  /*#### Disable all used wakeup sources: Wake up Timer ######################*/
  HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
  
  /*#### Clear all related wakeup flags ######################################*/
  /* Clear PWR wake up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
  /* Clear RTC Wake Up timer Flag */
  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&RTCHandle, RTC_FLAG_WUTF);
  
  /*#### Setting the Wake up time ############################################*/
  HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, 0xA017, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
  
  /*#### Enter the Standby mode ##############################################*/
  /* Request to enter STANDBY mode  */
  HAL_PWR_EnterSTANDBYMode();
  
}
示例#2
0
/**
  * @brief  EXTI line detection callbacks
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == KEY_BUTTON_PIN)
  {  
    HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN);
    HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN);
    
    /* Set the alarm to current time + 5s */
    RTC_AlarmStructure.Alarm  = RTC_ALARM_A;
    RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat;
    RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours;
    RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes;
    RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 0x05) % 60;
    RTC_AlarmStructure.AlarmDateWeekDay = 0x31;
    RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
    RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES;
    RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
    
    /* The Following Wakeup sequence is highly recommended prior to each Standby
       mode entry mainly  when using more than one wakeup source this is to not 
       miss any wakeup event:
       - Disable all used wakeup sources,
       - Clear all related wakeup flags,
       - Re-enable all used wakeup sources,
       - Enter the Standby mode.
    */

    /*## Disable all used wakeup sources #####################################*/
    /* Disable Wake-up timer */
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
    
    /* Disable RTC Alarm */
    HAL_RTC_DeactivateAlarm(&RTCHandle, RTC_ALARM_A);

    /*## Clear all related wakeup flags ######################################*/
    /* Clear PWR wake up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
    /* Clear the Alarm Flag */
    __HAL_RTC_ALARM_CLEAR_FLAG(&RTCHandle, RTC_FLAG_ALRAF);

    /*## Re-enable all used wakeup sources ###################################*/
    /* Set RTC alarm */
    if(HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) 
    {
      /* Initialization Error */
      Error_Handler();
    }

    /* Enable WKUP pin */
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

    /* Turn LED1 off */
    BSP_LED_Off(LED1);

    /*## Enter Standby Mode ##################################################*/
    HAL_PWR_EnterSTANDBYMode();
  }
}
示例#3
0
/**
 * @brief Low Power standby mode
 * NOTE: This is Low power standby mode with wakeup button(PA0)
 *       After WAKEUP button interrupt the system will reset
 */
void BSP_StandbyMode_PB(void)
{
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Clear standby and wakeup flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB | PWR_FLAG_WU);
  HAL_PWR_EnterSTANDBYMode();
}
示例#4
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xB HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 64 MHz */
  SystemClock_Config();

  /* Configure the system Power */
  SystemPower_Config();
  
  /* Check and handle if the system was resumed from Standby mode */ 
  if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
  {
    /* Clear Standby flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
  }

  /* Insert 5 seconds delay */
  HAL_Delay(5000);

 /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry
    mainly when using more than one wakeup source this is to not miss any wakeup event.
     - Disable all used wakeup sources,
     - Clear all related wakeup flags, 
     - Re-enable all used wakeup sources,
     - Enter the Standby mode.
  */

  /* Disable all used wakeup sources: PWR_WAKEUP_PIN1 */
  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Clear all related wakeup flags*/
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
  /* Enable WakeUp Pin PWR_WAKEUP_PIN1 connected to PA.00 */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Enter the Standby mode */
  HAL_PWR_EnterSTANDBYMode();

  /* This code will never be reached! */
  while (1)
  {
  }
}
示例#5
0
/**
  * @brief EXTI line detection callbacks
  * @param GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if (GPIO_Pin == USER_BUTTON_PIN)
  {
    
        /* Wait that user release the User push-button */
    while(BSP_PB_GetState(BUTTON_USER) == GPIO_PIN_SET){}
    
    HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN);
    HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN);

    /* Set the alarm to current time + 5s */
    RTC_AlarmStructure.Alarm  = RTC_ALARM_A;
    RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat;
    RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours;
    RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes;
    RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 5) % 60;
    RTC_AlarmStructure.AlarmDateWeekDay = 31;
    RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
    RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES;
    RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
    if (HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK)
    {
      /* Initialization Error */
      Error_Handler();
    }

    /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry
       mainly  when using more than one wakeup source this is to not miss any wakeup event.
         - Disable all used wakeup sources,
         - Clear all related wakeup flags, 
         - Re-enable all used wakeup sources,
         - Enter the Standby mode.
    */
  
    /*#### Disable all used wakeup sources: WKUP pin ###########################*/
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
  
    /*#### Clear all related wakeup flags ######################################*/
    /* Clear PWR wake up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
    /* Enable WKUP pin */
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

    /* Turn LED3 off */
    BSP_LED_Off(LED3);

    /* Request to enter STANDBY mode */
    HAL_PWR_EnterSTANDBYMode();
  }
}
示例#6
0
/**
  * @brief  This function configures the system to enter Standby mode with RTC
  *         clocked by LSE or LSI and with Backup SRAM ON for current consumption
  *         measurement purpose.
  *         STANDBY Mode with RTC clocked by LSE/LSI and BKPSRAM
  *         ====================================================
  *           - RTC Clocked by LSE or LSI
  *           - Backup SRAM ON
  *           - IWDG OFF
  *           - Automatic Wakeup using RTC clocked by LSE/LSI (after ~20s)
  * @param  None
  * @retval None
  */
void StandbyRTCBKPSRAMMode_Measure(void)
{
//	/*rtc_init */
//  rtc_init();
//	/*wake up timer*/
//	rtc_wake_up_timer_config(0x5000);
    /* Enable BKPRAM Clock */
    __HAL_RCC_BKPSRAM_CLK_ENABLE();

    /* Enable the Backup SRAM low power Regulator */
    HAL_PWREx_EnableBkUpReg();

    /*## Enter Standby Mode ####################################################*/
    /* Request to enter STANDBY mode  */
    HAL_PWR_EnterSTANDBYMode();
}
/* State behaviour */
void behaviour_goodbye(state_ptr state)
{
  uint32_t i;
  buzzer_note_t beep;

  /* Set events to react to */

  /* Do state actions */

  /* Blink green pin before shutting down */
  HAL_GPIO_WritePin(GPIOC,UI_LED_R_Pin|UI_LED_B_Pin|UI_LED_G_Pin,GPIO_PIN_RESET);
  for (i = 0; i < 6; i++)
  {
    HAL_GPIO_TogglePin(GPIOC,UI_LED_G_Pin);
    osDelay(200);
  }

  /* Beep */
  beep.note = A4;
  beep.ms = 100;
  while(osMailPut(queue_periph_buzzerHandle, (void *) &beep) != osOK)
  {
    osDelay(1);
  }
  osDelay(105);

  beep.note = D4;
  beep.ms = 80;
  while(osMailPut(queue_periph_buzzerHandle, (void *) &beep) != osOK)
  {
    osDelay(1);
  }
  osDelay(80);

  // Sleep well little prince
  /* Turn off LED */
  HAL_GPIO_WritePin(GPIOC,UI_LED_R_Pin|UI_LED_B_Pin|UI_LED_G_Pin,GPIO_PIN_RESET);

  /* Disable RTC alarms to avoid waking the system up */
  __HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc);
  __HAL_RTC_ALARMA_DISABLE(&hrtc);

  /* Enable wakeup pin and go to sleep */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  HAL_PWR_EnterSTANDBYMode();
}
示例#8
0
void StandbyMode(void) {
  MX_GPIO_Deinit();

  /* This procedure come from the STM32F030 Errata sheet*/
  __HAL_RCC_PWR_CLK_ENABLE();

  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Clear PWR wake up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

  /* Enable WKUP pin */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

  /* Enter STANDBY mode */
  HAL_PWR_EnterSTANDBYMode();
}
示例#9
0
/**
  * @brief  Run the Lowpower Standby mode RTC Alarm
  * @param  None.
  * @note   run and display information about the lowpower feature.  
  * @retval None.
  */
void LowPowerStandbyRTCAlarm(void)
{
  kWindow_Popup("STANDBY Alarm", LCD_COLOR_WHITE, LCD_COLOR_BLUE,\
                "\nset delay time\n",                            \
                LCD_COLOR_BLUE, LCD_COLOR_WHITE );
  
  /* Set the alarm */
  LowPowerHandleAlarm();
  
  kWindow_Popup("", LCD_COLOR_WHITE, LCD_COLOR_WHITE, \
                "\n\nstandby mode\nstarted\nwait alarm\nto exit\nand reset\n", \
                LCD_COLOR_BLUE, LCD_COLOR_WHITE );  
  
  BSP_JOY_Init(JOY_MODE_GPIO);

  /*#### Enter StandBy mode ####*/
  HAL_PWR_EnterSTANDBYMode();
}
示例#10
0
/**
  * @brief EXTI line detection callbacks
  * @param GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if (GPIO_Pin == TAMPER_BUTTON_PIN)
  {
    HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN);
    HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN);

    /* Set the alarm to current time + 5s */
    RTC_AlarmStructure.Alarm  = RTC_ALARM_A;
    RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat;
    RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours;
    RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes;
    RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 5) % 60;
    RTC_AlarmStructure.AlarmDateWeekDay = 31;
    RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
    RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES;
    RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
    if (HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK)
    {
      /* Initialization Error */
      Error_Handler();
    }
    
    /* Wait that user release the Tamper push-button */
    while(BSP_PB_GetState(BUTTON_TAMPER) == GPIO_PIN_SET){}

    /* Disable all used wakeup sources: WKUP pin */
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
    
    /* Clear all related wakeup flags */
    /* Clear PWR wake up Flag */
    __HAL_PWR_CLEAR_WAKEUP_FLAG(PWR_WAKEUP_PIN_FLAG4);
    
    /* Enable WKUP pin */
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4);
    
    /* Turn on LED1 */
    BSP_LED_Off(LED1);
    
    /* Request to enter STANDBY mode */
    HAL_PWR_EnterSTANDBYMode();
  }
}
示例#11
0
/**
 * @brief Low Power standby mode
 * @param WakeUptime_ms provide time in 1 to 10 millisecond
 *                      and 1 second to  60 seconds (in msec unit)
 * NOTE: Auto-wake-up (AWU) from low-power mode using RTC wakeup timer
 *       After RTC wakeup timer interrupt the system will reset
 */
void BSP_StandbyMode_AWU(uint16_t WakeUptime_ms)
{
  /* Initalize RTC */
  BSP_RTC_Init();
  /* Start RTC wakeup timer */
  BSP_RTC_WakeUpTimer_Init(WakeUptime_ms);

 /**
  *  Clear all related wakeup flags,
  *  Re-enable all used wakeup sources,
  *  Enter the Standby mode.
  */
  /* Clear RTC wakeup flag */
  __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc_bsp,RTC_FLAG_WUTF);

  /* Restart RTC wakeup timer */
  BSP_RTC_WakeUpTimer_Init(WakeUptime_ms);

  /* Enter Standby mode */
  HAL_PWR_EnterSTANDBYMode();
}
/**
* @brief This function handles TIM6 global interrupt.
*/
void TIM6_IRQHandler(void)
{
  /* USER CODE BEGIN TIM6_IRQn 0 */
  
  /* Turn off LED */
  HAL_GPIO_WritePin(GPIOC,UI_LED_R_Pin|UI_LED_B_Pin|UI_LED_G_Pin,GPIO_PIN_RESET);

  /* Disable RTC alarms because they wake the system up */
  HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);
  
  /* USER CODE END TIM6_IRQn 0 */
  HAL_TIM_IRQHandler(&htim6);
  /* USER CODE BEGIN TIM6_IRQn 1 */
  
  /* Set wake up pin and go to sleep (little prince) */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  HAL_PWR_EnterSTANDBYMode();
  
  /* USER CODE END TIM6_IRQn 1 */
}
示例#13
0
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
  int i = 1;
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
	  if ((i % 64) == 0)
	  {
		  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
		  while((PWR->CSR & (uint32_t) 0x00000001)!=0);//attesa che il WUF si azzeri (via HW)

		  HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 16384, RTC_WAKEUPCLOCK_RTCCLK_DIV16);

		  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
		  HAL_PWR_EnterSTANDBYMode();
	  }
	  HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
	  osDelay(100);
	  i++;
  }
  /* USER CODE END StartDefaultTask */
}
示例#14
0
/**
  * @brief  Run the Lowpower Standby mode Wakeup pin 
  * @param  None.
  * @note   run and display information about the lowpower feature.  
  * @retval None.
  */
void LowPowerStandbyWakeupPin(void)
{
  kWindow_Popup("STANDBY WAKEUP", LCD_COLOR_WHITE, LCD_COLOR_BLUE,\
                "JOY sel will\nstart\nstandby mode\n",                  \
                LCD_COLOR_WHITE, LCD_COLOR_BLUE );

  HAL_Delay(100);
  user_event = JOY_UP;
  while(user_event != JOY_SEL)
  {
    user_action = 0;
  };

  kWindow_Popup("", LCD_COLOR_WHITE, LCD_COLOR_WHITE,         \
                "\n\n\n\npress JOY SEL\nto exit\nand reset\n",\
                 LCD_COLOR_BLUE, LCD_COLOR_WHITE );
  
  /* Enable WKUP pin */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  
  /*#### Enter StandBy mode ####*/
  HAL_PWR_EnterSTANDBYMode();
}
/* State behaviour */
void behaviour_goodbye(state_ptr state)
{
  /* Set events to react to */

  /* Do state actions */

  /* Set menu */
  osMutexWait(mutex_menuHandle, osWaitForever);
  menu_copy(&menu_goodbye, &current_menu);
  osMutexRelease(mutex_menuHandle);

  /* Display menu */
  uint32_t i;
  for (i = 0; i < menu_goodbye.item_num; i++)
  {
    while (osMailPut(queue_lcdHandle, (void *) &menu_goodbye.items[i]) != osOK)
    {
      osDelay(1);
    }
  }

  /* Do state actions */
  osDelay(2000);

  // Sleep well little prince
  /* Turn off LED */
  HAL_GPIO_WritePin(GPIOC,UI_LED_R_Pin|UI_LED_B_Pin|UI_LED_G_Pin,GPIO_PIN_RESET);

  /* Disable RTC alarms to avoid waking the system up */
  __HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc);
  __HAL_RTC_ALARMA_DISABLE(&hrtc);

  /* Enable wakeup pin and go to sleep */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  HAL_PWR_EnterSTANDBYMode();
}
示例#16
0
STATIC mp_obj_t machine_deepsleep(void) {
    rtc_init_finalise();

#if defined(MCU_SERIES_F7)
    printf("machine.deepsleep not supported yet\n");
#else
    // We need to clear the PWR wake-up-flag before entering standby, since
    // the flag may have been set by a previous wake-up event.  Furthermore,
    // we need to disable the wake-up sources while clearing this flag, so
    // that if a source is active it does actually wake the device.
    // See section 5.3.7 of RM0090.

    // Note: we only support RTC ALRA, ALRB, WUT and TS.
    // TODO support TAMP and WKUP (PA0 external pin).
    uint32_t irq_bits = RTC_CR_ALRAIE | RTC_CR_ALRBIE | RTC_CR_WUTIE | RTC_CR_TSIE;

    // save RTC interrupts
    uint32_t save_irq_bits = RTC->CR & irq_bits;

    // disable RTC interrupts
    RTC->CR &= ~irq_bits;

    // clear RTC wake-up flags
    RTC->ISR &= ~(RTC_ISR_ALRAF | RTC_ISR_ALRBF | RTC_ISR_WUTF | RTC_ISR_TSF);

    // clear global wake-up flag
    PWR->CR |= PWR_CR_CWUF;

    // enable previously-enabled RTC interrupts
    RTC->CR |= save_irq_bits;

    // enter standby mode
    HAL_PWR_EnterSTANDBYMode();
    // we never return; MCU is reset on exit from standby
#endif
    return mp_const_none;
}
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - Backup SRAM and RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin (PI.11)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Enable Power Clock*/
  __HAL_RCC_PWR_CLK_ENABLE();
  
  /* Allow access to Backup */
  HAL_PWR_EnableBkUpAccess();

  /* Reset RTC Domain */
  __HAL_RCC_BACKUPRESET_FORCE();
  __HAL_RCC_BACKUPRESET_RELEASE();
  
  /* Disable all used wakeup sources: Pin6(PI.11) */
  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN6);
  
  /* Clear all related wakeup flags */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
  /* Re-enable all used wakeup sources: Pin6(PI.11) */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN6);

  /* Request to enter STANDBY mode  */
  HAL_PWR_EnterSTANDBYMode();
}
示例#18
0
int main(void)
{
int i=5000;
	
uint8_t ultrasoundEnableFlag;
 uint16_t voltage; 
	/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* Configure the system clock */
  SystemClock_Config_8MHz();
  //__HAL_RCC_PWR_CLK_ENABLE();
  /* Initialize all configured peripherals */
	
	MX_GPIO_Init();
			HAL_GPIO_WritePin( DCDC_EN_GPIO_Port , DCDC_EN_Pin , 0);								//
			HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 0 );									//open drain kimenet,pch fet,
  MX_ADC_Init();
  //MX_I2C1_Init(); 
	 //MX_TIM3_Init();
	 MX_USART1_UART_Init();

		GPIO_TIM3_OFF();
	//HAL_Delay(100);
		 MX_RTC_Init(); 
 /* Enable Power Clock */
  //__HAL_RCC_PWR_CLK_ENABLE();
	
		 uartTester();
		//	GPIO_TIM3_OFF();
		

//Feszültseg ellenörzése,sippogás-----------------------------------------------------
voltage=voltage_read(ADC_CHANNEL_2,2);
if(Full<voltage)
	batteryLevel=3;

if(Medium < voltage && voltage<= Full)
	batteryLevel=2;

if(Medium >= voltage)
	batteryLevel=1;

HAL_Delay(1000);
beeps(batteryLevel,1);
PutString("Software version 2016.07.26.\n");
PutString("batteryLevel: ");
			PutNumber(batteryLevel);
			PutString("\n");

while(1){
	//Feszültseg ellenörzése, paraméterek beállítása,fesz fvében------------------------
	voltage=voltage_read(ADC_CHANNEL_2,2);
	if(Low > voltage){
			if(UltraLow > voltage){
				voltage=voltage_read(ADC_CHANNEL_2,2);
				if(UltraLow > voltage){
					HAL_GPIO_WritePin( DCDC_PWR_GPIO_Port , DCDC_PWR_Pin , 1 );									//open drain kimenet,pch fet,
				HAL_PWR_EnterSTANDBYMode();
				}
			}
			ultrasoundEnableFlag=0;
			sleepNum=LowVoltSleep;
	}else{
			ultrasoundEnableFlag=1;
			sleepNum= linear(sleepNumMax,sleepNumMin, voltageMin,voltageMax,voltage);											
			soundNum=	linear(soundNumMin,soundNumMax,voltageMin,voltageMax,voltage);
			sounDelay=sDelay;
	}
			PutString("sleepNum");
			PutNumber(sleepNum);
			PutString("\n");
				PutString("soundNum");
			PutNumber(soundNum);
			PutString("\n");
	
	//Ultrahang generálás---------------------------------------------------------------
	
	if(ultrasoundEnableFlag){
		
		PutString("ultrasound(1)\n ");
			ultrasound(1);		
		
	}

	//Sleep-----------------------------------------------------------------------------
		
		//	HAL_ADC_MspDeInit(&hadc);
	HAL_Delay(10);
PutString("sleep!\n");


	
	HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
				HAL_NVIC_EnableIRQ(RTC_IRQn);
	

	
	for(uint8_t e=0 ; e < sleepNum ; e++){

			
			HAL_RTC_GetTime(&hrtc,&sTim,RTC_FORMAT_BIN); 
		  HAL_RTC_GetDate(&hrtc, &sDat, RTC_FORMAT_BIN);
		
		HAL_RTC_GetTime(&hrtc,&sTim,RTC_FORMAT_BIN); 
		  HAL_RTC_GetDate(&hrtc, &sDat, RTC_FORMAT_BIN);

		PutNumber((uint32_t)sTim.Hours);
		
		PutString(":");
		PutNumber((uint32_t)sTim.Minutes);
	
		PutString(":");
		PutNumber((uint32_t)sTim.Seconds);
			PutString("\n");
		
				if(sTim.Minutes==59){
						sAlarm.AlarmTime.Minutes=0;
					if(sTim.Hours==23){
							sAlarm.AlarmTime.Hours=0;
						}else{
							sAlarm.AlarmTime.Hours=sTim.Hours+1;
						}
					}else{
						sAlarm.AlarmTime.Minutes=sTim.Minutes+1;
						sAlarm.AlarmTime.Hours=sTim.Hours;
					}
					HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN);		

				
					PutString("alarm: ");
		PutNumber((uint32_t)sAlarm.AlarmTime.Hours);		
		PutString(":");
		PutNumber((uint32_t)sAlarm.AlarmTime.Minutes);
							PutString(":");
		PutNumber((uint32_t)sAlarm.AlarmTime.Seconds);
		PutString("\n");
					
		SleepMode();
	}
					HAL_NVIC_DisableIRQ(RTC_IRQn);

	
	}			

}
/**
* @brief  This routine puts the MCU in standby mode
* @param  None
* @retval None
*/
void MCU_Enter_StandbyMode(void)
{
  HAL_PWR_EnterSTANDBYMode();  /* Infinite loop */
}
示例#20
0
/// \function standby()
STATIC mp_obj_t pyb_standby(void) {
    HAL_PWR_EnterSTANDBYMode();
    return mp_const_none;
}
示例#21
0
/**
  * @brief  EXTI line detection callbacks
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == TAMPER_BUTTON_PIN)
  {  
    HAL_RTC_GetTime(&RTCHandle, &RTC_TimeStructure, RTC_FORMAT_BIN);
    HAL_RTC_GetDate(&RTCHandle, &RTC_DateStructure, RTC_FORMAT_BIN);
    
    /* Set the alarm to current time + 5s */
    RTC_AlarmStructure.Alarm  = RTC_ALARM_A;
    RTC_AlarmStructure.AlarmTime.TimeFormat = RTC_TimeStructure.TimeFormat;
    RTC_AlarmStructure.AlarmTime.Hours = RTC_TimeStructure.Hours;
    RTC_AlarmStructure.AlarmTime.Minutes = RTC_TimeStructure.Minutes;
    RTC_AlarmStructure.AlarmTime.Seconds = (RTC_TimeStructure.Seconds + 0x05) % 60;
    RTC_AlarmStructure.AlarmDateWeekDay = 0x31;
    RTC_AlarmStructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
    RTC_AlarmStructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS | RTC_ALARMMASK_MINUTES;
    RTC_AlarmStructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
    
    /* The Following Wakeup sequence is highly recommended prior to each Standby
       mode entry mainly  when using more than one wakeup source this is to not 
       miss any wakeup event:
       - Disable all used wakeup sources,
       - Clear all related wakeup flags,
       - Re-enable all used wakeup sources,
       - Enter the Standby mode.
    */

    /*## Disable all used wakeup sources #####################################*/
    /* Disable Wake-up timer */
    HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
    
    /* Disable RTC Alarm */
    HAL_RTC_DeactivateAlarm(&RTCHandle, RTC_ALARM_A);

    /*## Clear all related wakeup flags ######################################*/
    /* Clear PWR wake up Flag */
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    
    /* Clear the Alarm Flag */
    __HAL_RTC_ALARM_CLEAR_FLAG(&RTCHandle, RTC_FLAG_ALRAF);

    /*## Re-enable all used wakeup sources ###################################*/
    /* Set RTC alarm */
    if(HAL_RTC_SetAlarm_IT(&RTCHandle, &RTC_AlarmStructure, RTC_FORMAT_BIN) != HAL_OK) 
    {
      /* Initialization Error */
      Error_Handler();
    }

    /* Enable WKUP pin */
    HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);

    /* Turn LED1 off */
    BSP_LED_Off(LED1);

    /*## Enter Standby Mode ##################################################*/
    HAL_PWR_EnterSTANDBYMode();
  }

  if(GPIO_Pin == MFX_IRQOUT_PIN)
  {
    /* The different functionalities of MFX (TS, Joystick, SD detection, etc. )  
    can be configured in exti mode to generate an IRQ on given events.
    The MFX IRQ_OUT pin is unique and common to all functionalities, so if several 
    functionalities are configured in exit mode, the MCU has to enquire MFX about  
    the IRQ source (see BSP_IO_ITGetStatus). Communication with Mfx is done by I2C. 
    Often the sw requires ISRs (irq service routines) to be quick while communication 
    with I2C can be considered relatively long (hundreds of usec depending on I2C clk). 
    Considering that the features for human interaction like TS, Joystick, SD detection 
    don’t need immediate reaction, it is suggested to use POLLING instead of EXTI mode, 
    in order to avoid "blocking I2C communication" on interrupt service routines */

    /* Here an example of implementation is proposed: mix between pooling and exit:
    On ISR a flag is set (MfxIrqReceived), the main loop polls on the flag;
    Mcu communicates with Mfx only when the flag has been set. This is just an example: 
    the users should choose they strategy depending on their application needs.*/    
    MfxExtiReceived = 1;
  }
}
示例#22
-1
/**
  * @brief  This function configures the system to enter Standby mode for
  *         current consumption measurement purpose.
  *         STANDBY Mode
  *         ============
  *           - RTC OFF
  *           - IWDG and LSI OFF
  *           - Wakeup using WakeUp Pin (PA.00)
  * @param  None
  * @retval None
  */
void StandbyMode_Measure(void)
{
  /* Enable Power Clock*/
  __PWR_CLK_ENABLE();

  /* Allow access to Backup */
  HAL_PWR_EnableBkUpAccess();

  /* Reset RTC Domain */
  __HAL_RCC_BACKUPRESET_FORCE();
  __HAL_RCC_BACKUPRESET_RELEASE();
  
  /* The Following Wakeup sequence is highly recommended prior to each Standby mode entry
     mainly  when using more than one wakeup source this is to not miss any wakeup event.
       - Disable all used wakeup sources,
       - Clear all related wakeup flags, 
       - Re-enable all used wakeup sources,
       - Enter the Standby mode.
  */
  
  /*#### Disable all used wakeup sources: WKUP pin ###########################*/
  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
  
  /*#### Clear all related wakeup flags ######################################*/
  /* Clear PWR wake up Flag */
  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  
  /* Enable WKUP pin */
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
  
  /* a 200 ms-delay is needed between enabling WKUP pin and
     actually entering standby mode.
  */
  HAL_Delay(200);

  /* Request to enter STANDBY mode */
  HAL_PWR_EnterSTANDBYMode();
}