mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Add delay to let clock stabilize when out of deep sleep
Tests have shown that there is hich-up on MSI clock during the setup phase. If this stabilization phase happens when application has restarted again this can have side effects, like grambled UART characters typically. So we're adding a delay before hading-over back to application. With this modification, on NCULEO_L476RG, the wake-up time is increased from 2ms to 2,5ms. If possible this should be improved in the future to save 500 microseconds of wak-up time. See TODOpull/6561/head
							parent
							
								
									8007b1df7c
								
							
						
					
					
						commit
						3d92af50ce
					
				| 
						 | 
				
			
			@ -35,6 +35,18 @@
 | 
			
		|||
extern void HAL_SuspendTick(void);
 | 
			
		||||
extern void HAL_ResumeTick(void);
 | 
			
		||||
 | 
			
		||||
/*  Wait loop - assuming tick is 1 us */
 | 
			
		||||
static void wait_loop(uint32_t timeout)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t t1, t2, elapsed = 0;
 | 
			
		||||
    t1 = us_ticker_read();
 | 
			
		||||
    do {
 | 
			
		||||
        t2 = us_ticker_read();
 | 
			
		||||
        elapsed = (t2 > t1) ? (t2 - t1) : ((uint64_t)t2 + 0xFFFFFFFF - t1 + 1);
 | 
			
		||||
    } while (elapsed < timeout);
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// On L4 platforms we've seen unstable PLL CLK configuraiton
 | 
			
		||||
// when DEEP SLEEP exits just few µs after being entered
 | 
			
		||||
// So we need to force MSI usage before setting clocks again
 | 
			
		||||
| 
						 | 
				
			
			@ -174,6 +186,12 @@ void hal_deepsleep(void)
 | 
			
		|||
    // After wake-up from STOP reconfigure the PLL
 | 
			
		||||
    SetSysClock();
 | 
			
		||||
 | 
			
		||||
    /*  Wait for clock to be stabilized.
 | 
			
		||||
     *  TO DO: a better way of doing this, would be to rely on
 | 
			
		||||
     *  HW Flag. At least this ensures proper operation out of
 | 
			
		||||
     *  deep sleep */
 | 
			
		||||
    wait_loop(500);
 | 
			
		||||
 | 
			
		||||
    TIM_HandleTypeDef TimMasterHandle;
 | 
			
		||||
    TimMasterHandle.Instance = TIM_MST;
 | 
			
		||||
    __HAL_TIM_SET_COUNTER(&TimMasterHandle, EnterTimeUS);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue