mbed lib with startup delay fixed for Nucleo401RE

Fork of mbed-src by mbed official

Revision:
499:d0e9408fd176
Parent:
489:119543c9f674
--- a/targets/hal/TARGET_Freescale/TARGET_K20XX/sleep.c	Fri Mar 27 16:00:09 2015 +0000
+++ b/targets/hal/TARGET_Freescale/TARGET_K20XX/sleep.c	Sat Mar 28 08:15:07 2015 +0000
@@ -29,6 +29,15 @@
 //Very low-power stop mode
 void deepsleep(void)
 {
+    //Check if ADC is enabled and HS mode is set, if yes disable it (lowers power consumption by 60uA)
+    uint8_t ADC_HSC = 0;
+    if (SIM->SCGC6 & SIM_SCGC6_ADC0_MASK) {
+        if (ADC0->CFG2 & ADC_CFG2_ADHSC_MASK) {
+            ADC_HSC = 1;
+            ADC0->CFG2 &= ~(ADC_CFG2_ADHSC_MASK);
+        }
+    }
+    
     //Check if PLL/FLL is enabled:
     uint32_t PLL_FLL_en = (MCG->C1 & MCG_C1_CLKS_MASK) == MCG_C1_CLKS(0);
     
@@ -67,4 +76,8 @@
         while((MCG->S & MCG_S_LOCK0_MASK) == 0u) { }    // Wait until locked             
 #endif
     }
+    
+    if (ADC_HSC) {
+        ADC0->CFG2 |= (ADC_CFG2_ADHSC_MASK);
+    }
 }