diff --git a/drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h b/drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h --- a/drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h +++ b/drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h @@ -525,6 +525,7 @@ HAL_StatusTypeDef HAL_InitTick (uint32_t /* Peripheral Control functions ************************************************/ void HAL_IncTick(void); +void HAL_IncTickBy(uint32_t increment); // emz void HAL_Delay(__IO uint32_t Delay); uint32_t HAL_GetTick(void); void HAL_SuspendTick(void); diff --git a/drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c b/drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c --- a/drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c +++ b/drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_hal.c @@ -288,6 +288,12 @@ HAL_StatusTypeDef HAL_DeInit(void) uwTick++; } +// emz +__weak void HAL_IncTickBy(uint32_t increment) +{ + uwTick += increment; +} + /** * @brief Provides a tick value in millisecond. * @note This function is declared as __weak to be overwritten in case of other diff --git a/inc/gpio.h b/inc/gpio.h --- a/inc/gpio.h +++ b/inc/gpio.h @@ -8,7 +8,8 @@ enum _blinkrate { BLINK_FAST = 50, BLINK_MED = 250, - BLINK_SLOW = 2000 + BLINK_SLOW = 2000, + BLINK_DISABLE = 9999, }; diff --git a/inc/rtc.h b/inc/rtc.h --- a/inc/rtc.h +++ b/inc/rtc.h @@ -5,6 +5,7 @@ void rtc_init(void); +RTC_TimeTypeDef* rtc_time(void); RTC_HandleTypeDef* rtc_gethandle(void); diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -54,9 +54,9 @@ int main(void) led_blink(4); uint16_t blink_rate = BLINK_FAST; -// uint8_t state = SYSTEM_GPSACQ; + uint8_t state = SYSTEM_GPSACQ; //DEBUG: - uint8_t state = SYSTEM_IDLE; +// uint8_t state = SYSTEM_IDLE; uint32_t gps_polltimer = 0; uint32_t fix_acq_starttime = 0; @@ -72,9 +72,10 @@ int main(void) adc_stop(); HAL_Delay(1000); - __DBGMCU_CLK_ENABLE() ; // (RCC->APB2ENR |= (RCC_APB2ENR_DBGMCUEN)) - HAL_EnableDBGStopMode(); // SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); +// __DBGMCU_CLK_ENABLE() ; // (RCC->APB2ENR |= (RCC_APB2ENR_DBGMCUEN)) +// HAL_EnableDBGStopMode(); // SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); + uint32_t idle_blink_last = 0; while (1) { @@ -120,16 +121,29 @@ int main(void) // Idling: sleep and wait for RTC timeslot trigger case SYSTEM_IDLE: { - blink_rate = BLINK_SLOW; + // Don't blink normally + blink_rate = 9999; //BLINK_SLOW; - // Actually sleep for real: disable systick and sleep until RTC interrupt -// HAL_SuspendTick(); + // If we haven't blinked for a while, blink now + if(HAL_GetTick() - idle_blink_last > 10 * 1000) + { + HAL_GPIO_WritePin(LED_BLUE, 1); + HAL_Delay(20); + HAL_GPIO_WritePin(LED_BLUE, 0); + idle_blink_last = HAL_GetTick(); + } // Enter sleep mode: wait for interrupt //HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); + HAL_SuspendTick(); + HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); + // We probably stopped for a second + HAL_IncTickBy(1000); // maybe check the RTC before and after this, increment tick by the delta? + HAL_ResumeTick(); + // We have woken up! Clear wakeup flag __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); @@ -189,7 +203,7 @@ int main(void) } } break; - + // Wait for wspr timeslot and start transmitting case SYSTEM_WSPRTX: { @@ -241,13 +255,13 @@ int main(void) } #ifndef LED_DISABLE - if(HAL_GetTick() - led_timer > blink_rate) + if((blink_rate != BLINK_DISABLE) && (HAL_GetTick() - led_timer > blink_rate)) { ledpulse(); led_timer = HAL_GetTick(); } - if(statled_ontime && HAL_GetTick() - statled_ontime > 10) + if((blink_rate != BLINK_DISABLE) && (statled_ontime && HAL_GetTick() - statled_ontime > 10)) { HAL_GPIO_WritePin(LED_BLUE, 0); statled_ontime = 0; diff --git a/src/rtc.c b/src/rtc.c --- a/src/rtc.c +++ b/src/rtc.c @@ -77,7 +77,7 @@ void rtc_init(void) // Alarm will trigger on the Xth second of every minute sAlarm.AlarmMask = RTC_ALARMMASK_ALL; // Trigger every second for now - sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; + sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_SS14; //RTC_ALARMSUBSECONDMASK_ALL; sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; sAlarm.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY; sAlarm.Alarm = RTC_ALARM_A; @@ -94,6 +94,15 @@ void rtc_init(void) } +RTC_TimeTypeDef time_last = {0}; + +RTC_TimeTypeDef* rtc_time(void) +{ + HAL_RTC_GetTime(&hrtc, &time_last, RTC_FORMAT_BCD); + return &time_last; +} + + void rtc_cal(void) { // Do something with hrtc.Instance->CALR; // this has a plus and minus component, see refman