Skip to content

Commit 95da622

Browse files
bama-nordiccarlescufi
authored andcommitted
samples: wi-fi: Enhance shutdown sample
Enhance shutdown sample to enable functionality without a need for buttons. Enabled both one-shot and continuous modes. Jira: SHEL-3697 Signed-off-by: Bansidhar Mangalwedhekar <[email protected]>
1 parent 0eb8596 commit 95da622

File tree

3 files changed

+196
-34
lines changed

3 files changed

+196
-34
lines changed

samples/wifi/shutdown/Kconfig

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,39 @@
77
source "Kconfig.zephyr"
88

99
config WIFI_MAC_ADDRESS
10-
string "WiFi MAC address"
10+
string "Wi-Fi MAC address"
1111
default "F6:CE:36:00:00:01"
1212
help
13-
WiFi MAC address to be used by the sample. If not set, the sample will
14-
use the default MAC address (locally administrative). This is only used
15-
when the nRF7002 OTP is not programmed with a MAC address.
13+
Wi-Fi MAC address to be used by the sample. If not set, the sample will
14+
use the default MAC address (locally administrative). This is only used
15+
when the nRF7002 OTP is not programmed with a MAC address.
16+
17+
choice SHUTDOWN_OPERATION_MODE
18+
prompt "Sample operation mode"
19+
default OPERATION_MODE_CONTINUOUS
20+
help
21+
Select the operation mode for the sample.
22+
23+
config OPERATION_MODE_CONTINUOUS
24+
bool "Continuous mode"
25+
help
26+
In this mode, the sample will continue to run alternating between
27+
Wi-Fi shutdown and startup.
28+
29+
config OPERATION_MODE_ONE_SHOT
30+
bool "One-shot mode"
31+
help
32+
In this mode, the sample will shutdown Wi-Fi only once and then exit.
33+
34+
config OPERATION_MODE_BUTTONS
35+
bool "Enable button interaction"
36+
help
37+
Enable button interaction in the sample. If enabled, the sample will
38+
enable use of buttons to toggle the Wi-Fi shutdown or startup.
39+
endchoice
40+
41+
config SHUTDOWN_TIMEOUT_S
42+
int "Wi-Fi shutdown timeout"
43+
default 5
44+
help
45+
Timeout in seconds after the Wi-Fi shutdown operation.

samples/wifi/shutdown/README.rst

Lines changed: 143 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ For more information, see the `nRF70 Series power states`_ page.
1212

1313
This also demonstrates how to achieve the lowest possible power consumption in the Host SoC (nRF53, nRF52 or nRF91 Series) when Wi-Fi is enabled but not being used.
1414

15+
The sample supports the following three modes of operation:
16+
17+
* Continuous mode (default): Continuously cycles between Wi-Fi startup and shutdown with a configurable timeout.
18+
* One-shot mode: Performs Wi-Fi startup followed by shutdown once, then remains in shutdown mode.
19+
* Buttons mode: Manual control of Wi-Fi startup and shutdown using buttons.
20+
1521
Requirements
1622
************
1723

@@ -23,17 +29,28 @@ Overview
2329
********
2430

2531
The sample can demonstrate Wi-Fi shutdown and achieve the lowest possible power consumption in the Host SoC.
26-
The sample:
32+
It operates in one of the following three modes, based on the selected configuration:
2733

28-
1. Initializes the Wi-Fi driver.
34+
* In Continuous mode(default), the sample performs the following steps:
35+
36+
1. Initializes the Wi-Fi driver and powers up the nRF70 device.
2937
#. Scans for available Wi-Fi networks to verify that the Wi-Fi driver is operational.
3038
#. Brings down the Wi-Fi network interface, which automatically directs the Wi-Fi driver to power down the nRF70 device.
3139
#. Puts the Host SoC in the lowest possible power consumption mode.
40+
#. Waits for the configured timeout period (``SHUTDOWN_TIMEOUT_S``).
41+
#. Repeats the cycle from step 1.
42+
43+
* In One-shot mode, the sample performs steps 1-4 once, then remains in shutdown mode permanently.
3244

45+
* In Buttons mode, the Wi-Fi state is controlled manually based on user button interactions.
3346

3447
User Interface
3548
**************
3649

50+
The user interface depends on the selected mode of operation:
51+
52+
Buttons mode only:
53+
3754
Button 1:
3855
Wakes up the Host SoC, brings up the Wi-Fi network interface, which automatically directs the Wi-Fi driver to power on the nRF70 device.
3956
The sample then scans for available Wi-Fi networks to verify that the Wi-Fi driver is operational.
@@ -42,6 +59,10 @@ Button 2:
4259
Brings down the Wi-Fi network interface, which automatically directs the Wi-Fi driver to power down the nRF70 device.
4360
The Host SoC is put into the lowest possible power consumption mode.
4461

62+
Continuous and One-shot modes:
63+
64+
User interaction required.
65+
The sample operates automatically according to the selected mode.
4566

4667
Building and running
4768
********************
@@ -50,25 +71,78 @@ Building and running
5071

5172
.. include:: /includes/build_and_run_ns.txt
5273

53-
To build for the nRF7000 EK, use the ``nrf5340dk/nrf5340/cpuapp`` board target.
54-
The following is an example of the CLI command to demonstrate Wi-Fi shutdown:
74+
Modes of Operation
75+
==================
5576

56-
.. code-block:: console
77+
To build for the nRF7002 DK and nRF7000 EK with nRF5340 DK in different modes of operation, see the following examples:
78+
79+
Continuous mode (Default)
80+
-------------------------
81+
82+
* For nRF7002 DK:
83+
84+
.. code-block:: console
85+
86+
west build -p -b nrf7002dk/nrf5340/cpuapp
87+
88+
* For nRF7000 EK with nRF5340 DK:
89+
90+
.. code-block:: console
91+
92+
west build -p -b nrf5340dk/nrf5340/cpuapp -- -DSHIELD=nrf7002ek_nrf7000
93+
94+
One-shot mode
95+
-------------
96+
97+
* For nRF7002 DK:
98+
99+
.. code-block:: console
100+
101+
west build -p -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_OPERATION_MODE_ONE_SHOT=y -DCONFIG_NRF_WIFI_IF_AUTO_START=n
102+
103+
* For nRF7000 EK with nRF5340 DK:
104+
105+
.. code-block:: console
106+
107+
west build -p -b nrf5340dk/nrf5340/cpuapp -- -DSHIELD=nrf7002ek_nrf7000 -DCONFIG_OPERATION_MODE_ONE_SHOT=y -DCONFIG_NRF_WIFI_IF_AUTO_START=n
108+
109+
Buttons mode
110+
------------
111+
112+
* For nRF7002 DK:
113+
114+
.. code-block:: console
115+
116+
west build -p -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_OPERATION_MODE_BUTTONS=y
117+
118+
* For nRF7000 EK with nRF5340 DK:
57119

58-
west build -b nrf5340dk/nrf5340/cpuapp -- -DSHIELD=nrf7002ek_nrf7000
120+
.. code-block:: console
121+
122+
west build -p -b nrf5340dk/nrf5340/cpuapp -- -DSHIELD=nrf7002ek_nrf7000 -DCONFIG_OPERATION_MODE_BUTTONS=y
123+
124+
Configuration options
125+
=====================
59126

60127
Disable auto-start of the Wi-Fi driver
61128
--------------------------------------
62129

63130
The Wi-Fi network interface is automatically brought up when the Wi-Fi driver is initialized by default.
64131
You can disable it by setting the :kconfig:option:`CONFIG_NRF_WIFI_IF_AUTO_START` Kconfig option to ``n``.
132+
This is automatically set for One-shot mode.
65133

66134
.. code-block:: console
67135
68-
west build -b nrf5340dk/nrf5340/cpuapp -- -DSHIELD=nrf7002ek_nrf7000 -DCONFIG_NRF_WIFI_IF_AUTO_START=n
136+
west build -p -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_NRF_WIFI_IF_AUTO_START=n
69137
70-
With this configuration, the Wi-Fi network interface is not automatically brought up by the Zephyr networking stack.
71-
You must press **Button 1** to bring up the Wi-Fi network interface.
138+
Adjust shutdown timeout
139+
-----------------------
140+
141+
In Continuous mode, you can configure the timeout period between shutdown and restart cycles using the ``SHUTDOWN_TIMEOUT_S`` option (in seconds):
142+
143+
.. code-block:: console
144+
145+
west build -p -b nrf7002dk/nrf5340/cpuapp -- -DCONFIG_SHUTDOWN_TIMEOUT_S=10
72146
73147
Testing
74148
=======
@@ -78,46 +152,89 @@ Testing
78152
#. |connect_kit|
79153
#. |connect_terminal|
80154

81-
The sample shows the following output:
155+
Testing in Continuous mode
156+
--------------------------
82157

83-
.. code-block:: console
158+
The sample shows the following output in Continuous mode:
84159

85-
*** Booting Zephyr OS build v3.3.99-ncs1-26-ge405279d2134 ***
86-
[00:00:00.440,460] <inf> wifi_nrf: Firmware (v1.2.8.1) booted successfully
160+
.. code-block:: console
87161
88-
[00:00:00.638,397] <inf> scan: Starting nrf5340dk/nrf5340/cpuapp with CPU frequency: 64 MHz
162+
*** Booting nRF Connect SDK v3.0.99-7c4f8113c3e4 ***
163+
*** Using Zephyr OS v4.1.99-eb12c854d528 ***
164+
[00:00:00.428,253] <inf> shutdown: Starting nrf7002dk with CPU frequency: 64 MHz
89165
90-
[00:00:00.642,608] <inf> scan: Scan requested
166+
[00:00:00.431,640] <inf> shutdown: Scan requested
91167
92-
Num | SSID (len) | Chan | RSSI | Security | BSSID
93-
1 | abcdef 6 | 1 | -37 | WPA/WPA2 | aa:aa:aa:aa:aa:aa
94-
2 | pqrst 5 | 1 | -65 | WPA/WPA2 | xx:xx:xx:xx:xx:xx
95-
3 | AZBYCXD 7 | 1 | -41 | WPA/WPA2 | yy:yy:yy:yy:yy:yy
96-
[00:00:05.445,739] <inf> scan: Scan request done
168+
Num | SSID (len) | Chan | RSSI | Security | BSSID
169+
1 | abcdef 6 | 1 | -37 | WPA/WPA2 | aa:aa:aa:aa:aa:aa
170+
2 | pqrst 5 | 1 | -65 | WPA/WPA2 | xx:xx:xx:xx:xx:xx
171+
3 | AZBYCXD 7 | 1 | -41 | WPA/WPA2 | yy:yy:yy:yy:yy:yy
172+
[00:00:05.116,943] <inf> shutdown: Scan request done
173+
174+
[00:00:05.130,706] <inf> shutdown: Interface down
175+
[00:00:05.297,180] <inf> shutdown: Interface up
176+
[00:00:05.299,194] <inf> shutdown: Scan requested
177+
178+
Num | SSID (len) | Chan | RSSI | Security | BSSID
179+
1 | abcdef 6 | 1 | -37 | WPA/WPA2 | aa:aa:aa:aa:aa:aa
180+
2 | pqrst 5 | 1 | -65 | WPA/WPA2 | xx:xx:xx:xx:xx:xx
181+
3 | AZBYCXD 7 | 1 | -41 | WPA/WPA2 | yy:yy:yy:yy:yy:yy
182+
[00:00:10.009,399] <inf> shutdown: Scan request done
183+
184+
[00:00:10.022,735] <inf> shutdown: Interface down
185+
[00:00:15.189,270] <inf> shutdown: Interface up
186+
[00:00:15.191,284] <inf> shutdown: Scan requested
187+
188+
Testing in One-shot mode
189+
------------------------
190+
191+
The sample shows the following output in One-shot mode:
192+
193+
.. code-block:: console
194+
195+
*** Booting nRF Connect SDK v3.0.99-7c4f8113c3e4 ***
196+
*** Using Zephyr OS v4.1.99-eb12c854d528 ***
197+
[00:00:00.261,718] <inf> shutdown: Starting nrf7002dk with CPU frequency: 64 MHz
198+
199+
[00:00:00.428,802] <inf> shutdown: OTP not programmed, proceeding with local MAC: F6:CE:36:00:00:01
200+
[00:00:00.430,877] <inf> shutdown: Scan requested
201+
202+
Num | SSID (len) | Chan | RSSI | Security | BSSID
203+
1 | abcdef 6 | 1 | -37 | WPA/WPA2 | aa:aa:aa:aa:aa:aa
204+
2 | pqrst 5 | 1 | -65 | WPA/WPA2 | xx:xx:xx:xx:xx:xx
205+
3 | AZBYCXD 7 | 1 | -41 | WPA/WPA2 | yy:yy:yy:yy:yy:yy
206+
[00:00:05.144,104] <inf> shutdown: Scan request done
207+
208+
[00:00:05.157,714] <inf> shutdown: Interface down
209+
210+
Testing in Buttons mode
211+
-----------------------
212+
213+
Complete the following steps to test the sample in Buttons mode (nRF5340 host boards only):
97214

98-
[00:00:05.452,423] <inf> scan: Interface down
215+
#. The sample starts with Wi-Fi initialization and shutdown.
99216

100217
#. Press **Button 1** to wake up the nRF5340 SoC, initialize the Wi-Fi chipset, and scan for available Wi-Fi networks:
101218

102219
The sample shows the following output:
103220

104221
.. code-block:: console
105222
106-
[00:00:29.141,357] <inf> wifi_nrf: Firmware (v1.2.8.1) booted successfully
223+
[00:00:29.141,357] <inf> shutdown: Firmware (v1.2.8.1) booted successfully
107224
108-
[00:00:29.269,165] <inf> scan: Interface up
109-
[00:00:29.272,521] <inf> scan: Scan requested
225+
[00:00:29.269,165] <inf> shutdown: Interface up
226+
[00:00:29.272,521] <inf> shutdown: Scan requested
110227
111228
Num | SSID (len) | Chan | RSSI | Security | BSSID
112229
1 | abcdef 6 | 1 | -37 | WPA/WPA2 | aa:aa:aa:aa:aa:aa
113230
2 | pqrst 5 | 1 | -65 | WPA/WPA2 | xx:xx:xx:xx:xx:xx
114231
3 | AZBYCXD 7 | 1 | -41 | WPA/WPA2 | yy:yy:yy:yy:yy:yy
115-
[00:00:34.092,285] <inf> scan: Scan request done
232+
[00:00:34.092,285] <inf> shutdown: Scan request done
116233
117234
#. Press **Button 2** to shut down the Wi-Fi driver and put the nRF5340 SoC in lowest possible power consumption mode:
118235

119236
The sample shows the following output:
120237

121238
.. code-block:: console
122239
123-
[00:00:48.313,354] <inf> scan : Interface down
240+
[00:00:48.313,354] <inf> shutdown : Interface down

samples/wifi/shutdown/src/main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static bool is_mac_addr_set(struct net_if *iface)
131131
return net_eth_is_addr_valid(&wifi_addr);
132132
}
133133

134+
#ifdef CONFIG_OPERATION_MODE_BUTTONS
134135
static void button_handler_cb(uint32_t button_state, uint32_t has_changed)
135136
{
136137
if ((has_changed & DK_BTN1_MSK) && (button_state & DK_BTN1_MSK)) {
@@ -151,6 +152,8 @@ static void buttons_init(void)
151152
}
152153
}
153154

155+
#endif /* CONFIG_OPERATION_MODE_BUTTONS */
156+
154157
int shutdown_wifi(struct net_if *iface)
155158
{
156159
int ret;
@@ -237,8 +240,7 @@ int main(void)
237240
return ret;
238241
}
239242

240-
net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface,
241-
&params, sizeof(params));
243+
net_mgmt(NET_REQUEST_ETHERNET_SET_MAC_ADDRESS, iface, &params, sizeof(params));
242244

243245
ret = net_if_up(iface);
244246
if (ret) {
@@ -251,15 +253,28 @@ int main(void)
251253
net_if_get_link_addr(iface)->len));
252254
}
253255

256+
#ifdef CONFIG_OPERATION_MODE_BUTTONS
254257
buttons_init();
258+
#endif /* CONFIG_OPERATION_MODE_BUTTONS */
255259

256260
#ifdef CONFIG_NRF_WIFI_IF_AUTO_START
257261
exit_shutdown_mode();
258-
259262
enter_shutdown_mode();
260263
#endif
261264

265+
#if defined(CONFIG_OPERATION_MODE_BUTTONS) || defined(CONFIG_OPERATION_MODE_ONE_SHOT)
266+
exit_shutdown_mode();
267+
enter_shutdown_mode();
262268
k_sleep(K_FOREVER);
263-
269+
#else
270+
/* Will continuously alternate between shutdown and startup modes
271+
* with a defined timeout after shutdown.
272+
*/
273+
while (1) {
274+
exit_shutdown_mode();
275+
enter_shutdown_mode();
276+
k_sleep(K_SECONDS(CONFIG_SHUTDOWN_TIMEOUT_S));
277+
}
278+
#endif /* CONFIG_OPERATION_MODE_BUTTONS */
264279
return 0;
265280
}

0 commit comments

Comments
 (0)