check ThisThread::sleep_for() + json MBED_TICKLESS function for CPU IDD reduction
/users/kenjiArai/notebook/standby-mode-current-consumption-on-nucleo-f446re/
IDD Jumper(JP6) | ||||
Mode | Mbed-OS | Board | IDD Current(sleep) | IDD Current(Normal(*1)) |
DeepSleep | 0s5.15.1 | Nucleo-L152RE | 4.23uA | 5mA to 8mA |
^ | 0s6.6.0 | ^ | 4.22uA | 4mA to 7mA |
StandBy | 0s5.15.1 | ^ | 3.90uA | 4mA to 7mA |
^ | 0s6.6.0 | ^ | 3.90uA | 4mA to 7mA |
DeepSleep | 0s5.15.1 | Nucleo-L476RG | 2.13uA | 7mA to 10mA |
^ | 0s6.6.0 | ^ | 2.23uA | 7mA to 10mA |
StandBy | 0s5.15.1 | ^ | -uA(*2) | -mA(*2) |
^ | 0s6.6.0 | ^ | -uA(*2) | -mA(*2) |
DeepSleep | 0s5.15.1 | Nucleo-F411RE | 1.91mA(*3) | 7mA to 10mA |
^ | 0s6.6.0 | ^ | 1.65mA(*3) | 7mA to 10mA |
StandBy | 0s5.15.1 | ^ | 3.35uA | 7mA to 10mA |
^ | 0s6.6.0 | ^ | 3.40uA | 7mA to 9mA |
DeepSleep | 0s5.15.1 | Nucleo-F446RE | 1.67mA(*3) | 14mA to 17mA |
^ | 0s6.6.0 | ^ | 1.76mA(*3) | 14mA to 16mA |
StandBy | 0s5.15.1 | ^ | 3.42uA | 14mA to 17mA |
^ | 0s6.6.0 | ^ | 3.42uA | 14mA to 16mA |
(*1)-> LED1 Blinky every 1sec and change LED1 current
(*2)-> Could NOT make proper program and could NOT measure
(*3)-> NOT uA but mA
All Nucleo boards are stand alone condition(not additional circuit).
Equipment: DMM6500
/users/kenjiArai/code/Check_DeepSleep_os5/
/users/kenjiArai/code/Check_DeepSleep_os6/
/users/kenjiArai/code/Check_StandBy_os5/
/users/kenjiArai/code/Check_StandBy_os6/
Revision 1:d6abda61923b, committed 2021-01-15
- Comitter:
- kenjiArai
- Date:
- Fri Jan 15 07:28:31 2021 +0000
- Parent:
- 0:f8c5c7d19d9a
- Commit message:
- added L476RG board and set 3 modes
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed_app.json | Show annotated file Show diff for this revision Revisions of this file |
diff -r f8c5c7d19d9a -r d6abda61923b main.cpp --- a/main.cpp Thu Mar 12 09:19:48 2020 +0000 +++ b/main.cpp Fri Jan 15 07:28:31 2021 +0000 @@ -2,11 +2,11 @@ * Mbed Application program * Check Deep Sleep Mode * - * Copyright (c) 2020 Kenji Arai / JH1PJL + * Copyright (c) 2020,'21 Kenji Arai / JH1PJL * http://www7b.biglobe.ne.jp/~kenjia/ * https://os.mbed.com/users/kenjiArai/ * Revised: March 12th, 2020 - * Revised: March 12th, 2020 + * Revised: January 15th, 2021 */ /* @@ -14,16 +14,19 @@ https://forums.mbed.com/t/how-to-deep-sleep/7551 Tested on - Nucleo-L152RE -> less than 20uA - Nucleo-F446RE -> 1.5mA + Nucleo-L152RE -> 4.23uA (Normal run = 5mA to 8mA) + Nucleo-L476RG -> 2.13uA (Normal run = 7mA to 10mA) + Nucleo-F411RE -> 1.91mA (not uA)(Normal run = 7mA to 10mA) + Nucleo-F446RE -> 1.67mA (not uA)(Normal run = 14mA to 17mA) + + ---> same results within MODE1,2 and 3 */ // Include -------------------------------------------------------------------- #include "mbed.h" // Definition ----------------------------------------------------------------- -// https://keisan.casio.jp/exec/system/1526003938 -#define DATE_20200222_222222 1582377742 // 2020/2/22 22:22:22 +#define MODE 1 // Constructor ---------------------------------------------------------------- DigitalIn my_sw(USER_BUTTON); @@ -42,7 +45,7 @@ void time_enter_mode(void); void chk_and_set_time(char *ptr); int32_t xatoi (char **str, int32_t *res); -void get_line (char *buff, int len); +void get_line (char *buff, int32_t len); void print_revision(void); //------------------------------------------------------------------------------ @@ -58,25 +61,35 @@ printf("\r\nCheck current consumption at Deep-sleep mode.\r\n"); print_revision(); +#if MODE == 1 + printf("-->MODE=1 --> Use ThisThread::sleep_for() function.\r\n"); +#elif MODE == 2 + printf("-->MODE=2 --> Use thread_sleep_for() function.\r\n"); +#elif MODE == 3 + printf("-->MODE=3 --> Use wait_ms() function.\r\n"); +#endif seconds = time(NULL); - if (seconds < DATE_20200222_222222) { - strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); - pc.printf("[Time] %s\r\n", buf); - time_enter_mode(); - } while (my_sw == 0) {;} - ThisThread::sleep_for(10); + //ThisThread::sleep_for(10); // without "bare-metal" in mbed_app.json + thread_sleep_for(10); // with "bare-metal" while (true) { t.reset(); t.start(); - if ((my_sw == 0) || (loop_count > 20)) { + if ((my_sw == 0) || (loop_count > 10)) { LowPowerConfiguration(); InterruptIn my_irq(USER_BUTTON); while (my_irq.read() == 0) {;} - ThisThread::sleep_for(100); + //ThisThread::sleep_for(100); + thread_sleep_for(100); my_irq.fall(sw_irq); t.stop(); +#if MODE == 1 ThisThread::sleep_for(10000); +#elif MODE == 2 + thread_sleep_for(10000); +#elif MODE == 3 + wait_ms(10000); +#endif system_reset(); } ain = a_in.read(); @@ -89,7 +102,13 @@ ain, t_pass, loop_count++ ); t_pass = t.read_ms(); - ThisThread::sleep_for(1000 - t_pass); + //ThisThread::sleep_for(1000 - t_pass); + thread_sleep_for(1000 - t_pass); + if (pc.readable()) { + strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); + pc.printf("[Time] %s\r\n", buf); + time_enter_mode(); + } } } @@ -105,6 +124,8 @@ RCC->AHBENR |= (RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN | RCC_AHBENR_GPIOCEN | RCC_AHBENR_GPIODEN | RCC_AHBENR_GPIOHEN); +#elif defined(TARGET_NUCLEO_L476RG) + #elif defined(TARGET_NUCLEO_F446RE) RCC->AHB1ENR |= (RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | @@ -126,18 +147,22 @@ RCC->AHBENR &= ~(RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN |RCC_AHBENR_GPIOCEN | RCC_AHBENR_GPIODEN | RCC_AHBENR_GPIOHEN); +#elif defined(TARGET_NUCLEO_L476RG) + RCC->AHB1ENR = 0; + RCC->AHB2ENR = 0; + RCC->AHB3ENR = 0; + RCC->APB1ENR2 = 0; + RCC->APB2ENR = 0; #elif defined(TARGET_NUCLEO_F446RE) - RCC->AHB1ENR &= - ~(RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | - RCC_AHB1ENR_GPIODEN | RCC_AHB1ENR_GPIOHEN); - __HAL_RCC_TIM1_CLK_DISABLE(); - __HAL_RCC_USART1_CLK_DISABLE(); - __HAL_RCC_USART6_CLK_DISABLE(); - __HAL_RCC_ADC1_CLK_DISABLE(); - __HAL_RCC_SPI1_CLK_DISABLE(); - __HAL_RCC_SYSCFG_CLK_DISABLE(); - __HAL_RCC_TIM9_CLK_DISABLE(); - __HAL_RCC_TIM11_CLK_DISABLE(); + RCC->AHB1ENR = 0; + RCC->AHB2ENR = 0; + RCC->AHB3ENR = 0; + RCC->APB1ENR = 0x8; // alive TIM5 + RCC->APB2ENR = 0; + RCC->AHB1LPENR = 0; + RCC->AHB2LPENR = 0; + RCC->APB1LPENR = 0x8; // alive TIM5 + RCC->APB2LPENR = 0; #endif } @@ -146,8 +171,11 @@ char *ptr; char linebuf[64]; + if (pc.readable()) { + pc.getc(); // dummy read + } pc.printf("\r\nSet time into RTC\r\n"); - pc.printf(" e.g. >20 2 22 22 22 22 -> February 22,'20, 22:22:22\r\n"); + pc.printf(" e.g. >21 1 12 13 14 15 -> January 12,'21, 13:14:14\r\n"); pc.putc('>'); ptr = linebuf; get_line(ptr, sizeof(linebuf));
diff -r f8c5c7d19d9a -r d6abda61923b mbed_app.json --- a/mbed_app.json Thu Mar 12 09:19:48 2020 +0000 +++ b/mbed_app.json Fri Jan 15 07:28:31 2021 +0000 @@ -1,6 +1,7 @@ { "target_overrides": { "*": { + "target.printf_lib": "std", "target.macros_add": ["MBED_TICKLESS"] } }