Skip to content

Commit f703173

Browse files
committed
Add support for Nicla Vision
1 parent b215570 commit f703173

File tree

6 files changed

+96
-11
lines changed

6 files changed

+96
-11
lines changed

examples/Standby_WakeFromPin/Standby_WakeFromPin.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Board board;
4848

4949
void setup() {
5050
// When uploading this sketch to the M4 core, it just goes to standby mode.
51-
#if defined(ARDUINO_GENERIC_STM32H747_M4)
51+
#if defined(CORE_CM4)
5252
board.standByUntilWakeupEvent();
5353
return;
5454
#endif
@@ -69,7 +69,7 @@ void setup() {
6969
// On Portenta C33, you can specify which pin to use to wake up the device from sleep mode
7070
// Please read the documentation to understand which pins can be used to wake up the device.
7171
board.enableWakeupFromPin(PORTENTA_C33_WAKEUP_PIN, FALLING);
72-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4) || defined(ARDUINO_NICLA_VISION)
72+
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4)
7373
// On Portenta only pin GPIO0 can be used to wake up the device from sleep mode
7474
board.enableWakeupFromPin();
7575
#endif

examples/Standby_WakeFromRTC_H7/Standby_WakeFromRTC_H7.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void blinkLed(int ledPin, int delayTime = 1000){
3333

3434
void setup() {
3535
// When uploading this sketch to the M4 core, it just goes to standby mode.
36-
#if defined(ARDUINO_GENERIC_STM32H747_M4)
36+
#if defined(CORE_CM4)
3737
board.standByUntilWakeupEvent();
3838
return;
3939
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
Standby Wake from RTC Demo for Nicla Vision
3+
This example demonstrates how to wake up the Nicla Vision from standby mode using the included RTC (Real Time Clock).
4+
The device will stay awake for ~5 seconds, then go to sleep for 10 second. When the device is awake you will see the board's blue LED turned on.
5+
Effectively, you will get the same effect as with blink.
6+
7+
The example also turns off the peripherals before going to sleep and turns them back on after waking up.
8+
Usage:
9+
- Make sure you are running the latest version of the Nicla Vision core.
10+
- Select the Nicla Vision board from the Tools menu
11+
- Select the Nicla Vision USB port from the Tools menu
12+
- Upload the code to your Nicla Vision
13+
14+
Note: You need to upload this sketch to both cores, the M7 and the M4 for it to work.
15+
You can do so by selecting the M7 core and then the M4 core from the Tools menu in the "Target core" section.
16+
17+
Initial authors:
18+
Sebastian Romero ([email protected])
19+
*/
20+
21+
#include "Arduino_PowerManagement.h"
22+
23+
Board board;
24+
25+
void blinkLed(int ledPin, int delayTime = 1000){
26+
digitalWrite(ledPin, LOW);
27+
delay(delayTime);
28+
digitalWrite(ledPin, HIGH);
29+
delay(delayTime);
30+
}
31+
32+
void setup() {
33+
// When uploading this sketch to the M4 core, it just goes to standby mode.
34+
#if defined(CORE_CM4)
35+
board.standByUntilWakeupEvent();
36+
return;
37+
#endif
38+
39+
pinMode(LEDR, OUTPUT); // Used to indicate errors
40+
digitalWrite(LEDR, HIGH); // Turn off the red LED
41+
pinMode(LED_BUILTIN, OUTPUT);
42+
digitalWrite(LED_BUILTIN, LOW); // Turn on the built-in LED to show that the board is awake
43+
44+
if(!board.begin()){
45+
// If the board fails to initialize, it will blink the red LED
46+
while (true){
47+
blinkLed(LEDR);
48+
}
49+
}
50+
51+
delay(10000); // keep the board awake for 10 seconds, so we can se it working
52+
board.shutDownFuelGauge();
53+
54+
// The LED should go off when the board goes to sleep
55+
board.setAllPeripheralsPower(false);
56+
57+
board.enableWakeupFromRTC(0, 0, 10); // Go to standby for 10 seconds
58+
board.standByUntilWakeupEvent();
59+
}
60+
61+
void loop() {}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Device Control
88
url=https://github.com/arduino-libraries/Arduino_PowerManagement
99
architectures=renesas_portenta, mbed_portenta, mbed_nicla
1010
includes=Arduino_PowerManagement.h
11-
depends=Arduino_PF1550,Arduino_LowPowerPortentaC33,Arduino_LowPowerPortentaH7
11+
depends=Arduino_PF1550,Arduino_LowPowerPortentaC33,Arduino_LowPowerPortentaH7,Arduino_LowPowerNiclaVision

src/Board.cpp

+26-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Board::~Board() {
5858
}
5959

6060
bool Board::begin() {
61-
#if defined(ARDUINO_PORTENTA_H7_M7)
61+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_NICLA_VISION)
6262
if (CM7_CPUID == HAL_GetCurrentCPUID()){
6363
if (LowPowerReturnCode::success != LowPower.checkOptionBytes()){
6464
LowPower.prepareOptionBytes();
@@ -146,7 +146,7 @@ bool Board::enableWakeupFromRTC(uint32_t hours, uint32_t minutes, uint32_t secon
146146

147147
#endif
148148

149-
#if defined(ARDUINO_PORTENTA_H7)
149+
#if defined(ARDUINO_PORTENTA_H7) || defined(ARDUINO_NICLA_VISION)
150150
bool Board::enableWakeupFromRTC(uint32_t hours, uint32_t minutes, uint32_t seconds){
151151
standbyType |= StandbyType::untilTimeElapsed;
152152
wakeupDelayHours = hours;
@@ -165,16 +165,19 @@ void Board::sleepUntilWakeupEvent(){
165165
void Board::standByUntilWakeupEvent(){
166166
#if defined(ARDUINO_PORTENTA_C33)
167167
lowPower -> deepSleep();
168-
#elif defined(ARDUINO_GENERIC_STM32H747_M4)
168+
#elif defined(CORE_CM4)
169169
LowPower.standbyM4();
170-
#elif defined(ARDUINO_PORTENTA_H7_M7)
170+
#elif defined(ARDUINO_PORTENTA_H7_M7)
171171
RTCWakeupDelay rtcWakeupDelay = RTCWakeupDelay(wakeupDelayHours, wakeupDelayMinutes, wakeupDelaySeconds);
172172
if(standbyType == StandbyType::untilEither)
173173
LowPower.standbyM7(LowPowerStandbyType::untilPinActivity | LowPowerStandbyType::untilTimeElapsed, rtcWakeupDelay);
174174
else if (standbyType == StandbyType::untilPinActivity)
175175
LowPower.standbyM7(LowPowerStandbyType::untilPinActivity);
176176
else if (standbyType == StandbyType::untilTimeElapsed)
177177
LowPower.standbyM7(LowPowerStandbyType::untilTimeElapsed, rtcWakeupDelay);
178+
#elif defined(ARDUINO_NICLA_VISION) && defined(CORE_CM7)
179+
RTCWakeupDelay rtcWakeupDelay = RTCWakeupDelay(wakeupDelayHours, wakeupDelayMinutes, wakeupDelaySeconds);
180+
LowPower.standbyM7(rtcWakeupDelay);
178181
#endif
179182
}
180183

@@ -185,7 +188,7 @@ void Board::setAllPeripheralsPower(bool on){
185188
this -> setCommunicationPeripheralsPower(on);
186189
this -> setExternalPowerEnabled(on);
187190
this -> setAnalogDigitalConverterPower(on);
188-
#else if defined(ARDUINO_PORTENTA_H7)
191+
#elif defined(ARDUINO_PORTENTA_H7)
189192
// On the H7 several chips need different voltages, so we cannot turn the lanes that are dependent on each other separately.
190193
// This should only be used when going into standby mode, as turning off the USB-C PHY, Ethernet or Video bridge might cause undefined behaviour.
191194
if(on){
@@ -199,6 +202,23 @@ void Board::setAllPeripheralsPower(bool on){
199202
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal);
200203
PMIC.getControl() -> turnSw1Off(Sw1Mode::Normal);
201204
}
205+
206+
#elif defined(ARDUINO_NICLA_VISION)
207+
if(on){
208+
PMIC.getControl() -> turnLDO2On(Ldo2Mode::Normal); // Camera
209+
PMIC.getControl() -> turnLDO1On(Ldo1Mode::Normal); // ToF sensor / Camera
210+
PMIC.getControl() -> turnLDO3On(Ldo3Mode::Normal); // VDDA - Analog components, e.g. ADC
211+
PMIC.getControl() -> turnSw2On(Sw2Mode::Normal); // USB, 25 MHz crystal, 32 kHz crystal
212+
// TODO: Not supported yet by PMIC library
213+
// PMIC.getControl() -> turnSw3On(Sw3Mode::Normal); // External power VDDIO_EXT
214+
} else {
215+
PMIC.getControl() -> turnLDO2Off(Ldo2Mode::Normal); // Camera
216+
PMIC.getControl() -> turnLDO1Off(Ldo1Mode::Normal); // ToF sensor / Camera
217+
PMIC.getControl() -> turnLDO3Off(Ldo3Mode::Normal); // VDDA - Analog components, e.g. ADC
218+
PMIC.getControl() -> turnSw2Off(Sw2Mode::Normal); // USB, 25 MHz crystal, 32 kHz crystal
219+
// TODO: Not supported yet by PMIC library
220+
// PMIC.getControl() -> turnSw3Off(Sw3Mode::Normal); // External power VDDIO_EXT
221+
}
202222
#endif
203223
}
204224
//
@@ -270,7 +290,7 @@ bool Board::setReferenceVoltage(float voltage) {
270290
void Board::shutDownFuelGauge() {
271291
#if defined(ARDUINO_PORTENTA_C33)
272292
MAX1726Driver fuelGauge(&Wire3);
273-
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GENERIC_STM32H747_M4)
293+
#elif defined(ARDUINO_PORTENTA_H7)
274294
MAX1726Driver fuelGauge(&Wire1);
275295
#elif defined(ARDUINO_NICLA_VISION)
276296
MAX1726Driver fuelGauge(&Wire1);

src/Board.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// but in this library we can turn of the Ethernet interface using the PMIC, so we set the NO_ETHERNET_TURN_OFF flag to avoid turning off the Ethernet interface from both sides.
1818
#define NO_ETHERNET_TURN_OFF
1919
#include "Arduino_LowPowerPortentaH7.h"
20+
#elif defined(ARDUINO_NICLA_VISION)
21+
#include "Arduino_LowPowerNiclaVision.h"
2022
#endif
2123

2224
#define CONTEXT_LDO2 2 // LDO regulator: 1.8 V to 3.3 V, 400 mA
@@ -110,7 +112,9 @@ class Board {
110112
* The pin is only accessible via high-density connectors.
111113
*/
112114
void enableWakeupFromPin();
115+
#endif
113116

117+
#if defined(ARDUINO_PORTENTA_H7) || defined(ARDUINO_NICLA_VISION)
114118
/**
115119
* Enables sleep mode when the board is idle.
116120
*/
@@ -153,7 +157,7 @@ class Board {
153157
bool enableWakeupFromRTC(uint32_t hours, uint32_t minutes, uint32_t seconds, RTClock * rtc = &RTC);
154158
#endif
155159

156-
#if defined(ARDUINO_PORTENTA_H7)
160+
#if defined(ARDUINO_PORTENTA_H7) || defined(ARDUINO_NICLA_VISION)
157161
/**
158162
* Enables wake-up of the device from the RTC.
159163
* @param hours The number of hours to sleep.

0 commit comments

Comments
 (0)