Skip to content

Commit f751343

Browse files
committed
Issue #1028 - Removed STM32 platforms system wake up time calibration
1 parent f6282aa commit f751343

File tree

17 files changed

+8
-766
lines changed

17 files changed

+8
-766
lines changed

src/boards/B-L072Z-LRWAN1/board.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,11 @@ static void BoardUnusedIoInit( void );
6565
*/
6666
static void SystemClockConfig( void );
6767

68-
/*!
69-
* Used to measure and calibrate the system wake-up time from STOP mode
70-
*/
71-
static void CalibrateSystemWakeupTime( void );
72-
7368
/*!
7469
* System Clock Re-Configuration when waking up from STOP mode
7570
*/
7671
static void SystemClockReConfig( void );
7772

78-
/*!
79-
* Timer used at first boot to calibrate the SystemWakeupTime
80-
*/
81-
static TimerEvent_t CalibrateSystemWakeupTimeTimer;
82-
8373
/*!
8474
* Flag to indicate if the MCU is Initialized
8575
*/
@@ -99,20 +89,6 @@ static bool UsbIsConnected = false;
9989
uint8_t Uart2TxBuffer[UART2_FIFO_TX_SIZE];
10090
uint8_t Uart2RxBuffer[UART2_FIFO_RX_SIZE];
10191

102-
/*!
103-
* Flag to indicate if the SystemWakeupTime is Calibrated
104-
*/
105-
static volatile bool SystemWakeupTimeCalibrated = false;
106-
107-
/*!
108-
* Callback indicating the end of the system wake-up time calibration
109-
*/
110-
static void OnCalibrateSystemWakeupTimeTimerEvent( void* context )
111-
{
112-
RtcSetMcuWakeUpTime( );
113-
SystemWakeupTimeCalibrated = true;
114-
}
115-
11692
void BoardCriticalSectionBegin( uint32_t *mask )
11793
{
11894
*mask = __get_PRIMASK( );
@@ -178,10 +154,6 @@ void BoardInitMcu( void )
178154
McuInitialized = true;
179155
SX1276IoDbgInit( );
180156
SX1276IoTcxoInit( );
181-
if( GetBoardPowerSource( ) == BATTERY_POWER )
182-
{
183-
CalibrateSystemWakeupTime( );
184-
}
185157
}
186158
}
187159

@@ -287,20 +259,6 @@ void SystemClockConfig( void )
287259
HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 );
288260
}
289261

290-
void CalibrateSystemWakeupTime( void )
291-
{
292-
if( SystemWakeupTimeCalibrated == false )
293-
{
294-
TimerInit( &CalibrateSystemWakeupTimeTimer, OnCalibrateSystemWakeupTimeTimerEvent );
295-
TimerSetValue( &CalibrateSystemWakeupTimeTimer, 1000 );
296-
TimerStart( &CalibrateSystemWakeupTimeTimer );
297-
while( SystemWakeupTimeCalibrated == false )
298-
{
299-
300-
}
301-
}
302-
}
303-
304262
void SystemClockReConfig( void )
305263
{
306264
__HAL_RCC_PWR_CLK_ENABLE( );

src/boards/B-L072Z-LRWAN1/rtc-board.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ typedef struct
9595
*/
9696
static bool RtcInitialized = false;
9797

98-
/*!
99-
* \brief Indicates if the RTC Wake Up Time is calibrated or not
100-
*/
101-
static bool McuWakeUpTimeInitialized = false;
102-
103-
/*!
104-
* \brief Compensates MCU wakeup time
105-
*/
106-
static int16_t McuWakeUpTimeCal = 0;
107-
10898
/*!
10999
* Number of days in each month on a normal year
110100
*/
@@ -291,7 +281,7 @@ void RtcDelayMs( uint32_t delay )
291281
void RtcSetAlarm( uint32_t timeout )
292282
{
293283
// We don't go in Low Power mode for timeout below MIN_ALARM_DELAY
294-
if( ( int64_t )( MIN_ALARM_DELAY + McuWakeUpTimeCal ) < ( int64_t )( timeout - RtcGetTimerElapsedTime( ) ) )
284+
if( ( int64_t )MIN_ALARM_DELAY < ( int64_t )( timeout - RtcGetTimerElapsedTime( ) ) )
295285
{
296286
LpmSetStopMode( LPM_RTC_ID, LPM_ENABLE );
297287
}
@@ -300,12 +290,6 @@ void RtcSetAlarm( uint32_t timeout )
300290
LpmSetStopMode( LPM_RTC_ID, LPM_DISABLE );
301291
}
302292

303-
// In case stop mode is required
304-
if( LpmGetMode( ) == LPM_STOP_MODE )
305-
{
306-
timeout = timeout - McuWakeUpTimeCal;
307-
}
308-
309293
RtcStartAlarm( timeout );
310294
}
311295

@@ -444,41 +428,6 @@ uint32_t RtcGetTimerElapsedTime( void )
444428
return( ( uint32_t )( calendarValue - RtcTimerContext.Time ) );
445429
}
446430

447-
void RtcSetMcuWakeUpTime( void )
448-
{
449-
RTC_TimeTypeDef time;
450-
RTC_DateTypeDef date;
451-
452-
uint32_t now, hit;
453-
int16_t mcuWakeUpTime;
454-
455-
if( ( McuWakeUpTimeInitialized == false ) &&
456-
( HAL_NVIC_GetPendingIRQ( RTC_IRQn ) == 1 ) )
457-
{
458-
/* WARNING: Works ok if now is below 30 days
459-
* it is ok since it's done once at first alarm wake-up
460-
*/
461-
McuWakeUpTimeInitialized = true;
462-
now = ( uint32_t )RtcGetCalendarValue( &date, &time );
463-
464-
HAL_RTC_GetAlarm( &RtcHandle, &RtcAlarm, RTC_ALARM_A, RTC_FORMAT_BIN );
465-
hit = RtcAlarm.AlarmTime.Seconds +
466-
60 * ( RtcAlarm.AlarmTime.Minutes +
467-
60 * ( RtcAlarm.AlarmTime.Hours +
468-
24 * ( RtcAlarm.AlarmDateWeekDay - 1 ) ) );
469-
hit = ( hit << N_PREDIV_S ) + ( PREDIV_S - RtcAlarm.AlarmTime.SubSeconds );
470-
471-
mcuWakeUpTime = ( int16_t )( ( now - hit ) );
472-
McuWakeUpTimeCal += mcuWakeUpTime;
473-
//PRINTF( 3, "Cal=%d, %d\n", McuWakeUpTimeCal, mcuWakeUpTime);
474-
}
475-
}
476-
477-
int16_t RtcGetMcuWakeUpTime( void )
478-
{
479-
return McuWakeUpTimeCal;
480-
}
481-
482431
static uint64_t RtcGetCalendarValue( RTC_DateTypeDef* date, RTC_TimeTypeDef* time )
483432
{
484433
uint64_t calendarValue = 0;

src/boards/NAMote72/board.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,11 @@ static void BoardUnusedIoInit( void );
7979
*/
8080
static void SystemClockConfig( void );
8181

82-
/*!
83-
* Used to measure and calibrate the system wake-up time from STOP mode
84-
*/
85-
static void CalibrateSystemWakeupTime( void );
86-
8782
/*!
8883
* System Clock Re-Configuration when waking up from STOP mode
8984
*/
9085
static void SystemClockReConfig( void );
9186

92-
/*!
93-
* Timer used at first boot to calibrate the SystemWakeupTime
94-
*/
95-
static TimerEvent_t CalibrateSystemWakeupTimeTimer;
96-
9787
/*!
9888
* Flag to indicate if the MCU is Initialized
9989
*/
@@ -113,20 +103,6 @@ static bool UsbIsConnected = false;
113103
uint8_t Uart2TxBuffer[UART2_FIFO_TX_SIZE];
114104
uint8_t Uart2RxBuffer[UART2_FIFO_RX_SIZE];
115105

116-
/*!
117-
* Flag to indicate if the SystemWakeupTime is Calibrated
118-
*/
119-
static volatile bool SystemWakeupTimeCalibrated = false;
120-
121-
/*!
122-
* Callback indicating the end of the system wake-up time calibration
123-
*/
124-
static void OnCalibrateSystemWakeupTimeTimerEvent( void* context )
125-
{
126-
RtcSetMcuWakeUpTime( );
127-
SystemWakeupTimeCalibrated = true;
128-
}
129-
130106
/*!
131107
* Holds the bord version.
132108
*/
@@ -241,10 +217,6 @@ void BoardInitMcu( void )
241217
McuInitialized = true;
242218
SX1272IoDbgInit( );
243219
SX1272IoTcxoInit( );
244-
if( GetBoardPowerSource( ) == BATTERY_POWER )
245-
{
246-
CalibrateSystemWakeupTime( );
247-
}
248220
}
249221
}
250222

@@ -492,20 +464,6 @@ void SystemClockConfig( void )
492464
HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 );
493465
}
494466

495-
void CalibrateSystemWakeupTime( void )
496-
{
497-
if( SystemWakeupTimeCalibrated == false )
498-
{
499-
TimerInit( &CalibrateSystemWakeupTimeTimer, OnCalibrateSystemWakeupTimeTimerEvent );
500-
TimerSetValue( &CalibrateSystemWakeupTimeTimer, 1000 );
501-
TimerStart( &CalibrateSystemWakeupTimeTimer );
502-
while( SystemWakeupTimeCalibrated == false )
503-
{
504-
505-
}
506-
}
507-
}
508-
509467
void SystemClockReConfig( void )
510468
{
511469
__HAL_RCC_PWR_CLK_ENABLE( );

src/boards/NAMote72/rtc-board.c

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ typedef struct
9595
*/
9696
static bool RtcInitialized = false;
9797

98-
/*!
99-
* \brief Indicates if the RTC Wake Up Time is calibrated or not
100-
*/
101-
static bool McuWakeUpTimeInitialized = false;
102-
103-
/*!
104-
* \brief Compensates MCU wakeup time
105-
*/
106-
static int16_t McuWakeUpTimeCal = 0;
107-
10898
/*!
10999
* Number of days in each month on a normal year
110100
*/
@@ -290,7 +280,7 @@ void RtcDelayMs( uint32_t delay )
290280
void RtcSetAlarm( uint32_t timeout )
291281
{
292282
// We don't go in Low Power mode for timeout below MIN_ALARM_DELAY
293-
if( ( int64_t )( MIN_ALARM_DELAY + McuWakeUpTimeCal ) < ( int64_t )( timeout - RtcGetTimerElapsedTime( ) ) )
283+
if( ( int64_t )MIN_ALARM_DELAY < ( int64_t )( timeout - RtcGetTimerElapsedTime( ) ) )
294284
{
295285
LpmSetStopMode( LPM_RTC_ID, LPM_ENABLE );
296286
}
@@ -299,12 +289,6 @@ void RtcSetAlarm( uint32_t timeout )
299289
LpmSetStopMode( LPM_RTC_ID, LPM_DISABLE );
300290
}
301291

302-
// In case stop mode is required
303-
if( LpmGetMode( ) == LPM_STOP_MODE )
304-
{
305-
timeout = timeout - McuWakeUpTimeCal;
306-
}
307-
308292
RtcStartAlarm( timeout );
309293
}
310294

@@ -443,41 +427,6 @@ uint32_t RtcGetTimerElapsedTime( void )
443427
return( ( uint32_t )( calendarValue - RtcTimerContext.Time ) );
444428
}
445429

446-
void RtcSetMcuWakeUpTime( void )
447-
{
448-
RTC_TimeTypeDef time;
449-
RTC_DateTypeDef date;
450-
451-
uint32_t now, hit;
452-
int16_t mcuWakeUpTime;
453-
454-
if( ( McuWakeUpTimeInitialized == false ) &&
455-
( HAL_NVIC_GetPendingIRQ( RTC_Alarm_IRQn ) == 1 ) )
456-
{
457-
/* WARNING: Works ok if now is below 30 days
458-
* it is ok since it's done once at first alarm wake-up
459-
*/
460-
McuWakeUpTimeInitialized = true;
461-
now = ( uint32_t )RtcGetCalendarValue( &date, &time );
462-
463-
HAL_RTC_GetAlarm( &RtcHandle, &RtcAlarm, RTC_ALARM_A, RTC_FORMAT_BIN );
464-
hit = RtcAlarm.AlarmTime.Seconds +
465-
60 * ( RtcAlarm.AlarmTime.Minutes +
466-
60 * ( RtcAlarm.AlarmTime.Hours +
467-
24 * ( RtcAlarm.AlarmDateWeekDay - 1 ) ) );
468-
hit = ( hit << N_PREDIV_S ) + ( PREDIV_S - RtcAlarm.AlarmTime.SubSeconds );
469-
470-
mcuWakeUpTime = ( int16_t )( ( now - hit ) );
471-
McuWakeUpTimeCal += mcuWakeUpTime;
472-
//PRINTF( 3, "Cal=%d, %d\n", McuWakeUpTimeCal, mcuWakeUpTime);
473-
}
474-
}
475-
476-
int16_t RtcGetMcuWakeUpTime( void )
477-
{
478-
return McuWakeUpTimeCal;
479-
}
480-
481430
static uint64_t RtcGetCalendarValue( RTC_DateTypeDef* date, RTC_TimeTypeDef* time )
482431
{
483432
uint64_t calendarValue = 0;

src/boards/NucleoL073/board.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,11 @@ static void BoardUnusedIoInit( void );
7676
*/
7777
static void SystemClockConfig( void );
7878

79-
/*!
80-
* Used to measure and calibrate the system wake-up time from STOP mode
81-
*/
82-
static void CalibrateSystemWakeupTime( void );
83-
8479
/*!
8580
* System Clock Re-Configuration when waking up from STOP mode
8681
*/
8782
static void SystemClockReConfig( void );
8883

89-
/*!
90-
* Timer used at first boot to calibrate the SystemWakeupTime
91-
*/
92-
static TimerEvent_t CalibrateSystemWakeupTimeTimer;
93-
9484
/*!
9585
* Flag to indicate if the MCU is Initialized
9686
*/
@@ -110,20 +100,6 @@ static bool UsbIsConnected = false;
110100
uint8_t Uart2TxBuffer[UART2_FIFO_TX_SIZE];
111101
uint8_t Uart2RxBuffer[UART2_FIFO_RX_SIZE];
112102

113-
/*!
114-
* Flag to indicate if the SystemWakeupTime is Calibrated
115-
*/
116-
static volatile bool SystemWakeupTimeCalibrated = false;
117-
118-
/*!
119-
* Callback indicating the end of the system wake-up time calibration
120-
*/
121-
static void OnCalibrateSystemWakeupTimeTimerEvent( void* context )
122-
{
123-
RtcSetMcuWakeUpTime( );
124-
SystemWakeupTimeCalibrated = true;
125-
}
126-
127103
void BoardCriticalSectionBegin( uint32_t *mask )
128104
{
129105
*mask = __get_PRIMASK( );
@@ -204,10 +180,6 @@ void BoardInitMcu( void )
204180
SX1276IoDbgInit( );
205181
SX1276IoTcxoInit( );
206182
#endif
207-
if( GetBoardPowerSource( ) == BATTERY_POWER )
208-
{
209-
CalibrateSystemWakeupTime( );
210-
}
211183
}
212184
}
213185

@@ -324,20 +296,6 @@ void SystemClockConfig( void )
324296
HAL_NVIC_SetPriority( SysTick_IRQn, 0, 0 );
325297
}
326298

327-
void CalibrateSystemWakeupTime( void )
328-
{
329-
if( SystemWakeupTimeCalibrated == false )
330-
{
331-
TimerInit( &CalibrateSystemWakeupTimeTimer, OnCalibrateSystemWakeupTimeTimerEvent );
332-
TimerSetValue( &CalibrateSystemWakeupTimeTimer, 1000 );
333-
TimerStart( &CalibrateSystemWakeupTimeTimer );
334-
while( SystemWakeupTimeCalibrated == false )
335-
{
336-
337-
}
338-
}
339-
}
340-
341299
void SystemClockReConfig( void )
342300
{
343301
__HAL_RCC_PWR_CLK_ENABLE( );

0 commit comments

Comments
 (0)