You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,14 +17,14 @@ Take Arduino low power projects for the SAM D21 to the next level.
17
17
18
18
## Motivation
19
19
20
-
There are already several libraries available for the SAM D21 MCU that support low power features:
20
+
There are already several libraries available for the SAM D21 MCU that support low power features, e.g.:
21
21
22
22
-[Arduino Low Power library](https://github.com/arduino-libraries/ArduinoLowPower)
23
23
-[RTCZero Library for Arduino](https://github.com/arduino-libraries/RTCZero)
24
24
25
25
They provide solutions for specific use cases but fall short of making full use of the potential of the SAM D21 MCU. E.g. none of them tries to disable the USB module at runtime, the most power hungry function of the MCU, although typically not required for low power usage.
26
26
27
-
Another part of the problem is the rigid way the Arduino Core for SAM D21 bootstraps the MCU for 48 MHz with most MCU features enabled and configured for maximum performance. In contrast to classic Arduino MCUs like the Atmel ATmega 328 the SAM D21 MCU supports up to 9 clock sources at the same time, that may run in parallel at different frequencies. Using the generic clock controller (GCLK) the clocks can be selectively assigned to different MCU modules and can be stopped in standby mode. Combined with the power manager (PM) this allows disabling unused MCU modules and running the required MCU modules with clock frequencies that are optimized for the use case.
27
+
Another part of the problem is the rigid way the Arduino Core for SAM D21 bootstraps the MCU for 48 MHz with most MCU features enabled and configured for maximum performance. In contrast to classic Arduino MCUs like the Atmel ATmega 328 the SAM D21 MCU supports up to 9 clock generators at the same time, that may run in parallel at different frequencies. Using the generic clock controller (GCLK) the clocks can be selectively assigned to different MCU modules and can be stopped in standby mode. Combined with the power manager (PM) this allows disabling unused MCU modules and running the required MCU modules with clock frequencies that are optimized for the use case.
28
28
29
29
Although the main key, the power saving options of the SAM D21 are not exhausted by controlling clocks on the module level. The SAM D21 MCU has an ARM Cortex M0+ CPU core that knows an operation mode called [sleep-on-exit](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors). This mode is useful if the application does not need a main loop but runs completely event/interrupt driven. This saves the CPU overhead for the double context switch between main loop, ISR and back, saving power and reducing ISR latency.
30
30
@@ -36,6 +36,7 @@ There are also individual hardware aspects of each board to consider that may ad
36
36
37
37
Note that this library was designed and tested for the SAM D21 but will probably work with other SAM D variants with little or no adjustment, especially with the SAM DA1 variant.
38
38
39
+
39
40
## MCU Power Management
40
41
41
42
Well known from other CPUs and MCUs effective power management can be achieved by the combination of several aspects:
@@ -56,6 +57,7 @@ The [System](src/System.h) class supports the following operations:
56
57
- configure/enter sleep mode (idle 0-2 or standby)
57
58
- enable/disable sleep-on-exit ISR mode
58
59
- disable all non essential modules incl. *USB*
60
+
- cache the ISR vector table in SRAM
59
61
- read the MCU serial number
60
62
61
63
In this list the **reduction of the main clock** is not included. Changing this clock at any time is possible but in combination with the Arduino framework this is typically not a good choice as several Arduino libraries assume that the main clock frequency *F_CPU* is fixed at compile time. Changing it at runtime to a different value will result in the loss of various functions, especially everything that is timing related (e.g. millis() will no longer be real milliseconds). As the Arduino Core for SAM D21 only supports F_CPU fixed to 48 MHz, a patch if provided for [startup.c](patches/Seeduino-hardware-samd-1.8.3/startup.c) and [boards.txt](patches/Seeduino-hardware-samd-1.8.3/boards.txt) to support alternative values of 32, 24, 16, 12, 8, 6, 3 and 1.5 MHz. The provided patch is for the Seed Studio XIAO SAM D21, but this patch can also applied to any other SAM D21 MCU with no or little changes.
@@ -69,15 +71,15 @@ Using these functions, especially combined, can reduce the average runtime power
69
71
70
72
Compared to the extensions included in the Arduino core for the ESP8266 the Arduino core for the SAM D21 is rather sparse. Three more classes are included in this library to provide several missing features:
| Analog2DigitalConverter | Selectable Gain, Hardware Averaging, Temperature Sensor, Supply, Core and Bandgap Voltage, Callback |
75
-
| RealTimeClock | Counter Mode, Callback |
76
-
| TimerCounter | Callback|
77
+
| RealTimeClock | Counter Mode, Callback |
78
+
| TimerCounter | Callback, delay() replacement|
77
79
78
80
The *RealTimeClock* class of this library provides RTC counter mode as an alternative to the calendar mode of the RTCZero library. The *Analog2DigitalConverter* class and the *TimerCounter* can be used alternatively or combined with Arduino framework functions if the documented conditions are observed.
79
81
80
-
The external interrupt controller (EIC) is one of the MCU modules where Arduino framework functions like attachInterrupt() can be used in the familiar way and the low power optimization can be achieved by a call to the *System* class.
82
+
The external interrupt controller (EIC) is one of the MCU modules where Arduino framework functions like *attachInterrupt()* can be used in the familiar way and the low power optimization can be achieved by a call to the *System* class.
81
83
82
84
On the other hand the SPI implementation of the Arduino Core for SAM D21 does not use *F_CPU* or *SystemCoreClock* for determining the SPI baud rate divider but a hardcoded value of 48000000 (*SERCOM_SPI_FREQ_REF*), preventing correct baud settings at alternative main clock frequencies. To work around this without changing the Arduino Core source it is necessary to scale the baud rate with the following formula:
0 commit comments