Skip to content

Commit d9a06f3

Browse files
committed
modules: power: Don't enable/disable UART on VBUS events
Don't enable/disable UART on VBUS events due to a regression in NCS where the UART hangs after re-enabling. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 7f7e030 commit d9a06f3

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

app/src/modules/power/Kconfig.power

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ config APP_POWER_SHELL
2121

2222
config APP_POWER_DISABLE_UART_ON_VBUS_REMOVED
2323
bool "Disable UART when VBUS is removed"
24-
default y
24+
help
25+
Disable UART when VBUS is removed to save power.
26+
The UART is re-enabled when VBUS is connected again.
27+
This option is disabled by default due to UART hanging when being re-enabled.
2528

2629
config APP_POWER_THREAD_STACK_SIZE
2730
int "Thread stack size"

app/src/modules/power/power.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,11 @@ static void state_running_entry(void *obj)
123123
return;
124124
}
125125

126-
if (IS_ENABLED(CONFIG_APP_POWER_DISABLE_UART_ON_VBUS_REMOVED)) {
127-
err = subscribe_to_vsbus_events(pmic, &event_cb);
128-
if (err) {
129-
LOG_ERR("subscribe_to_vsbus_events, error: %d", err);
130-
SEND_FATAL_ERROR();
131-
return;
132-
}
126+
err = subscribe_to_vsbus_events(pmic, &event_cb);
127+
if (err) {
128+
LOG_ERR("subscribe_to_vsbus_events, error: %d", err);
129+
SEND_FATAL_ERROR();
130+
return;
133131
}
134132

135133
err = charger_read_sensors(&parameters.v0, &parameters.i0, &parameters.t0, &chg_status);
@@ -256,22 +254,26 @@ static void event_callback(const struct device *dev, struct gpio_callback *cb, u
256254
if (pins & BIT(NPM13XX_EVENT_VBUS_DETECTED)) {
257255
LOG_DBG("VBUS detected");
258256

259-
err = uart_enable();
260-
if (err) {
261-
LOG_ERR("uart_enable, error: %d", err);
262-
SEND_FATAL_ERROR();
263-
return;
257+
if (IS_ENABLED(CONFIG_APP_POWER_DISABLE_UART_ON_VBUS_REMOVED)) {
258+
err = uart_enable();
259+
if (err) {
260+
LOG_ERR("uart_enable, error: %d", err);
261+
SEND_FATAL_ERROR();
262+
return;
263+
}
264264
}
265265
}
266266

267267
if (pins & BIT(NPM13XX_EVENT_VBUS_REMOVED)) {
268268
LOG_DBG("VBUS removed");
269269

270-
err = uart_disable();
271-
if (err) {
272-
LOG_ERR("uart_disable, error: %d", err);
273-
SEND_FATAL_ERROR();
274-
return;
270+
if (IS_ENABLED(CONFIG_APP_POWER_DISABLE_UART_ON_VBUS_REMOVED)) {
271+
err = uart_disable();
272+
if (err) {
273+
LOG_ERR("uart_disable, error: %d", err);
274+
SEND_FATAL_ERROR();
275+
return;
276+
}
275277
}
276278
}
277279
}

tests/module/power/src/power_module_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FAKE_VALUE_FUNC(int, task_wdt_add, uint32_t, task_wdt_callback_t, void *);
2020
FAKE_VALUE_FUNC(float, nrf_fuel_gauge_process, float, float, float, float, bool, void *);
2121
FAKE_VALUE_FUNC(int, charger_read_sensors, float *, float *, float *, int32_t *);
2222
FAKE_VALUE_FUNC(int, nrf_fuel_gauge_init, const struct nrf_fuel_gauge_init_parameters *, void *);
23-
FAKE_VALUE_FUNC(int, mfd_npm1300_add_callback, const struct device *, struct gpio_callback *);
23+
FAKE_VALUE_FUNC(int, mfd_npm13xx_add_callback, const struct device *, struct gpio_callback *);
2424
FAKE_VALUE_FUNC(int, date_time_now, int64_t *);
2525

2626
ZBUS_MSG_SUBSCRIBER_DEFINE(power_subscriber);

0 commit comments

Comments
 (0)