Sleep mode in K70

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sleep mode in K70

Jump to solution
1,807 Views
ameybhopi
Contributor II

Hi I have a board with a k70 microcontroller , I want to configure it to sleep mode as well as exit from sleep mode. How can do this and manage power?

Labels (1)
0 Kudos
1 Solution
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Amey,

which sleep modes do you want? The following is the sample code to enter the sleep mode.

#define STOP_MODE  0x0 #define VLPS_MODE  0x2 #define LLS_MODE  0x3 #define VLLSx_MODE 0x4 #define VLLS0_MODE 0x0 #define VLLS1_MODE 0x1 #define VLLS2_MODE 0x2 #define VLLS3_MODE 0x3

#define LOW_PWR_MODE  "choose each of VLPS_MODE, LLS_MODE or VLLSx_MODE" #define LOW_PWR_SMODE "if LOW_PWR_MODE is VLLSx_MODE then choose each of VLLS0_MODE, VLLS1_MODE, VLLS2_MODE or VLLS3_MODE"

void stop (void) { /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */ SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK; /* WFI instruction will start entry into STOP mode */ asm("WFI"); }

void STOP_Mode(void) {   /* Write to PMPROT to allow AVLP/LLS/AVLLS power modes this write-once     bit allows the MCU to enter the AVLP/LLS/AVLLS low power mode*/   SMC_PMPROT = SMC_PMPROT_AVLP_MASK             | SMC_PMPROT_ALLS_MASK             | SMC_PMPROT_AVLLS_MASK;    /* Set the STOPM field to 0b011 for LLS mode  */   SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;   SMC_PMCTRL |=  (SMC_PMCTRL_STOPM(LOW_PWR_MODE)|SMC_PMCTRL_LPWUI_MASK); #if (LOW_PWR_MODE == VLLSx_MODE)   SMC_STOPCTRL &= ~SMC_STOPCTRL_VLLSM_MASK;   SMC_STOPCTRL |= LOW_PWR_SMODE; #endif   /*wait for write to complete to SMC before stopping core */    while((SMC_PMCTRL & SMC_PMCTRL_STOPM_MASK) != LOW_PWR_MODE);   /* Now execute the stop instruction (deep sleep) to go into LLS */   stop(); }

To exit the sleep mode, you can choose one of

  LPTMR (Low Power Timer),
  CMP0 (Comparator0),
  CMP1 (Comparator1),
  CMP2 (Comparator2)
  TSI (Touch sense input),
  RTC (Real Time Clock) or
  external imnterrupts

as the wake-up factor.

Which do you want? According to the wake-up method, the procedure varies.

Best regards,

Yasuhiko Koumoto.

View solution in original post

0 Kudos
15 Replies
1,186 Views
ameybhopi
Contributor II

Hi Yasuhiko and Mark your discussion really helpful for me because I am new to keneties microcontroller.  I got lot many information regarding sleep mode. Thank you.  :smileyhappy:

Regards

Amey Bhopi

0 Kudos
1,187 Views
yasuhikokoumoto
Senior Contributor I

Hi Amey,

which sleep modes do you want? The following is the sample code to enter the sleep mode.

#define STOP_MODE  0x0 #define VLPS_MODE  0x2 #define LLS_MODE  0x3 #define VLLSx_MODE 0x4 #define VLLS0_MODE 0x0 #define VLLS1_MODE 0x1 #define VLLS2_MODE 0x2 #define VLLS3_MODE 0x3

#define LOW_PWR_MODE  "choose each of VLPS_MODE, LLS_MODE or VLLSx_MODE" #define LOW_PWR_SMODE "if LOW_PWR_MODE is VLLSx_MODE then choose each of VLLS0_MODE, VLLS1_MODE, VLLS2_MODE or VLLS3_MODE"

void stop (void) { /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */ SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK; /* WFI instruction will start entry into STOP mode */ asm("WFI"); }

void STOP_Mode(void) {   /* Write to PMPROT to allow AVLP/LLS/AVLLS power modes this write-once     bit allows the MCU to enter the AVLP/LLS/AVLLS low power mode*/   SMC_PMPROT = SMC_PMPROT_AVLP_MASK             | SMC_PMPROT_ALLS_MASK             | SMC_PMPROT_AVLLS_MASK;    /* Set the STOPM field to 0b011 for LLS mode  */   SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;   SMC_PMCTRL |=  (SMC_PMCTRL_STOPM(LOW_PWR_MODE)|SMC_PMCTRL_LPWUI_MASK); #if (LOW_PWR_MODE == VLLSx_MODE)   SMC_STOPCTRL &= ~SMC_STOPCTRL_VLLSM_MASK;   SMC_STOPCTRL |= LOW_PWR_SMODE; #endif   /*wait for write to complete to SMC before stopping core */    while((SMC_PMCTRL & SMC_PMCTRL_STOPM_MASK) != LOW_PWR_MODE);   /* Now execute the stop instruction (deep sleep) to go into LLS */   stop(); }

To exit the sleep mode, you can choose one of

  LPTMR (Low Power Timer),
  CMP0 (Comparator0),
  CMP1 (Comparator1),
  CMP2 (Comparator2)
  TSI (Touch sense input),
  RTC (Real Time Clock) or
  external imnterrupts

as the wake-up factor.

Which do you want? According to the wake-up method, the procedure varies.

Best regards,

Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi

Beware of the K70 errate since there are some things that can't always be used in combination with WAIT and SLEEP modes - eg. USB (see e7166 for mask 3N96B).

Regards

Mark

1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

I have read the Errata e7166. I don't think it would be fatal to apply the software workaround to ensure that all operations on SDHC, NFC, USBOTG, and Cache controller modules were completed before entering the low power mode. Do you know the other errata?

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi Yasuhiko

1. e7166 is the most serious errata that I know for the device which concerns (general) low power modes. There are various others like e3794 which doesn't allow NMI to wake from STOP or VLPS but these are much more specific. It is best to read through the errata for the device being used to be sure that nothing affects the modes that need to be used.

2. I don't think that it is possible to work around the problem when using USB-OTG as device because it is the host that determines when messages are sent and so the device must always be in a state allowing it to receive

Generally my system automatically uses WAIT and/or STOP modes when there is no activity and so the USB part would always fail - therefore I disable low power operation whenever the device has the errata and the system is using USB to avoid it:

#if !(defined ERRATA_ID_7166 && defined USB_INTERFACE) // don't use low power mode due to errata e7166 and USB device

    #define SUPPORT_LOW_POWER // a low power task supervises power reduction when possible

#endif

Regards

Mark

µTasker Kinetis support

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

I have a question. In the VLLSx mode, USB, NFC and SDHC enter OFF state which is equivalent to the reset. Therefore, to wake-up form the VLLSx mode initiates the reset and system resources would be reset. I think even MASK 3N96B will go successfully in the case. How do you think?

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi Yasuhiko

In low power modes in whih the peripherals can't work in anyway the errata is not an issue.

Regards

Mark

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

I know the peripherals can't work in the low power modes. So I think it is a reasonable restriction to ensure no outstanding transaction on the bus-matrix. Then, I wonder what the errata e7166 want to claim. Can you explain why the errata exists? In the errata, the target devices are limited to Kinetis K series. Is the errata not applied to Kinetis L series?

Best regards,

Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi Yasuhiko

Each device mask has its own errata so you need to look at the mask of our chip (written on the housing) and check which errata set it needs to resepct. I have only encountered this particular errata with the K70 and no other K, Kl or KEs but you need to check in each case to be sure.

In WAIT and STOP modes most peripherals are still operational and so these modes are the ones that are greatly affected - the USB stops, meaning that it fails when it shouldn't. The other low power modes, without fully operational peripherals in many cases, are not affected since it is known that the peripherals can't operate anyway.

Regards

Mark

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

I understand well your comments. However, what I would like to know was the meaning of the errata. You seems not to have an answer. OK, I will make a new post to hear the meaning from Freescale.

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi Yasuhiko

When I read the errata it seems to give all information so I don't know what I can add to it.

- As long as you use the recommended workaround you will have no problem with RAM and cache

- I see no real problem with SDHC and NFC because the SW can wait until all transactions have been completed before moving to a low power mode-

- In the case of USB there is no problem as long as the USB is not connected

- In the case of connected USB I see no way to use WAIT or STOP without first disconnecting the USB because its operation will otherwise fail.

Regards

Mark

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

according to the reference manual, USB, NFC and SDHC can work only in VLPR and VLPW modes. In STOP, VLPS and LLS modes, they are at the static mode. In VLLSx modes, they are at the OFF state. From these facts, Kinetis MCU must not enter the low power modes on condition outstanding transaction remains other than VLPR and VLPW modes. So USB cannot be used with STOP, VLPS, LLS and VLLSx modes. Also this limitation would not at all errata. I guess the errata says only about VLPW mode (as VLPR mode does not use WFI instruction). However, I'm not sure.

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,186 Views
mjbcswitzerland
Specialist V

Hi Yasuhiko

It is correct that the errata is a "restriction" and doesn't affect all low power modes (in many the operation is already not possible).

It is the WAIT mode that is the one that is in fact most affected because, as the errata states, the modules themselves are still clocked and operational but their bus masters can't perform the necessary transfers. In devices without the errata their bus master can still continue to operate ad so full functionality during the WAIT mode is supported.

Regards

Mark

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

thank you for your patient discussion with me. I agree with you.

Best regards,
Yasuhiko Koumoto.

0 Kudos
1,186 Views
yasuhikokoumoto
Senior Contributor I

Hi Mark,

thank you for your explanations. It is a sad information. I understood well. Unless the low power mode was used, a half of the Kinetis advantages would die.

Best regards,
Yasuhiko Koumoto.

0 Kudos