SAMD21 - cannot setup sleep or deep sleep

Thread Starter

alxlabs

Joined Jan 12, 2023
12
Sorry for dummy question - I have an SAMD21G17D Microchip curiosity nano board, I've installed MPLAB X IDE, want to re-do on the ARM an old design based on very old PIC microcontroller. To the moment all went fine except I cannot put ARM into the sleep nor by timer nor by external interrupt. Tried to google but have not find anything. Is there any good example on how to do that?
 

Papabravo

Joined Feb 24, 2006
22,070
Sorry for dummy question - I have an SAMD21G17D Microchip curiosity nano board, I've installed MPLAB X IDE, want to re-do on the ARM an old design based on very old PIC microcontroller. To the moment all went fine except I cannot put ARM into the sleep nor by timer nor by external interrupt. Tried to google but have not find anything. Is there any good example on how to do that?
This is from the datasheet. Do you have one of those?

The SAM D21/DA1 have two software-selectable sleep modes, Idle and Stand-by. In Idle mode, the CPU is stopped while all other functions can be kept running. In Stand-by mode, all clocks and functions are stopped, expect those selected to continue running. The device supports SleepWalking. This feature allows the peripheral to wake up from sleep based on predefined conditions, and thus allows the CPU to wake up only when needed, for example, when a threshold is crossed or a result is ready. The Event System supports synchronous and asynchronous events, allowing peripherals to receive, react to and send events even in Stand-by mode.
This is from §16.1 Power Manager

Before entering the Stand-by Sleep mode the user must make sure that a significant amount of clocks and peripherals are disabled, so that the voltage regulator is not overloaded. This is because during Stand-by Sleep mode the internal voltage regulator will be in Low-Power mode.
This is from §16.6.2.8 Sleep Mode Controller

Sleep mode is activated by the Wait For Interrupt instruction (WFI). The Idle bits in the Sleep Mode register (SLEEP.IDLE) and the SLEEPDEEP bit of the System Control register of the CPU should be used as argument to select the level of the sleep mode. There are two main types of sleep mode: • IDLE mode: The CPU is stopped. Optionally, some synchronous clock domains are stopped, depending on the IDLE argument. Regulator operates in normal mode. SAM D21/DA1 Family PM – Power Manager © 2021 Microchip Technology Inc. and its subsidiaries Complete Datasheet DS40001882H-page 136 • STANDBY mode: All clock sources are stopped, except those where the RUNSTDBY bit is set. Regulator operates in low-power mode. Before entering standby mode the user must make sure that a significant amount of clocks and peripherals are disabled, so that the voltage regulator is not overloaded.

First time I've looked at the datasheet – took all of 5 minutes to run this down.
SAM D21/DA1 Family Data Sheet (microchip.com)
 

Thread Starter

alxlabs

Joined Jan 12, 2023
12
This is from the datasheet. Do you have one of those?

The SAM D21/DA1 have two software-selectable sleep modes, Idle and Stand-by. In Idle mode, the CPU is stopped while all other functions can be kept running. In Stand-by mode, all clocks and functions are stopped, expect those selected to continue running. The device supports SleepWalking. This feature allows the peripheral to wake up from sleep based on predefined conditions, and thus allows the CPU to wake up only when needed, for example, when a threshold is crossed or a result is ready. The Event System supports synchronous and asynchronous events, allowing peripherals to receive, react to and send events even in Stand-by mode.
This is from §16.1 Power Manager

Before entering the Stand-by Sleep mode the user must make sure that a significant amount of clocks and peripherals are disabled, so that the voltage regulator is not overloaded. This is because during Stand-by Sleep mode the internal voltage regulator will be in Low-Power mode.
This is from §16.6.2.8 Sleep Mode Controller

Sleep mode is activated by the Wait For Interrupt instruction (WFI). The Idle bits in the Sleep Mode register (SLEEP.IDLE) and the SLEEPDEEP bit of the System Control register of the CPU should be used as argument to select the level of the sleep mode. There are two main types of sleep mode: • IDLE mode: The CPU is stopped. Optionally, some synchronous clock domains are stopped, depending on the IDLE argument. Regulator operates in normal mode. SAM D21/DA1 Family PM – Power Manager © 2021 Microchip Technology Inc. and its subsidiaries Complete Datasheet DS40001882H-page 136 • STANDBY mode: All clock sources are stopped, except those where the RUNSTDBY bit is set. Regulator operates in low-power mode. Before entering standby mode the user must make sure that a significant amount of clocks and peripherals are disabled, so that the voltage regulator is not overloaded.

First time I've looked at the datasheet – took all of 5 minutes to run this down.
SAM D21/DA1 Family Data Sheet (microchip.com)
Thanks. I looked at the datasheet and saw all of this but did not figure out how to actually do that, i.e. which bits to flip, may be I will look again thru it.
 

Papabravo

Joined Feb 24, 2006
22,070
All you need to know is in §16 on power management. The key to it all is the WFI instruction, which waits for an interrupt. Look at the code sequences in Table 16-3 which show the setting of the bits followed by a WFI instruction. Can you explain your difficulty in understanding what is going on so I can be more helpful?

ETA: I think I see the difficulty. You are flipping through the datasheet. This is manifestly the WRONG approach. You must read each section and paragraph slowly and carefully so that you become part of the machine. It is the only way.
 

Thread Starter

alxlabs

Joined Jan 12, 2023
12
All you need to know is in §16 on power management. The key to it all is the WFI instruction, which waits for an interrupt. Look at the code sequences in Table 16-3 which show the setting of the bits followed by a WFI instruction. Can you explain your difficulty in understanding what is going on so I can be more helpful?

ETA: I think I see the difficulty. You are flipping through the datasheet. This is manifestly the WRONG approach. You must read each section and paragraph slowly and carefully so that you become part of the machine. It is the only way.
I saw the datasheet and I saw this paragraph. On the other hand I have MPLAB X IDE and writing on C using existing wizards in a process of project creation and I don't see how to issue WFI instruction in C. Shall something like "_asm WFI" be used?
 
Last edited:

Papabravo

Joined Feb 24, 2006
22,070
I saw the datasheet and I saw this paragraph. On the other hand I have MPLAB X IDE and writing on C using existing wizards in a process of project creation and I don't see how to issue WFI instruction in C. Shall something like "_asm WFI" be used?
I would suggest a #define macro to make WFI expand into whatever you need it to be.
 

Thread Starter

alxlabs

Joined Jan 12, 2023
12
Interesting. I asked this question to AI on FB and got what I need - exact examples. I was not able to find it with google. Key point - everything is defined within the header file and that is what I was missing and could not find with google nor in datasheet - usage of particulat include functions naming of which is not obvious. Again, I understood everything in datasheet but on the other hand I have MPLAB X suite and need to figure out how to do it from there. Still this reply has to be validated but at least as this is something to start with
 
Top