Commit 55e2014d authored by Benjamin Lindqvist's avatar Benjamin Lindqvist Committed by Carles Cufi
Browse files

drivers: nrf: Trigger STOP RX event and wait before disabling UARTE



Without first triggering TASKS_STOP{RX,TX}, I observed that the UARTE
was never disabled when using device_set_power_state which resulted in
the HFCLK never being shut down and several hundred microamps in
unnecessary current consumption when idle. This seems to fix the issue.

Also added special treatment of uarte if CONFIG_UART_ASYNC_API is
selected. Note that the #ifdef isn't enough, since it's possible that
the option is set, but only one of the UARTs uses it.

Signed-off-by: default avatarBenjamin Lindqvist <benjamin.lindqvist@endian.se>
parent 75a3ee52
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1189,6 +1189,21 @@ static void uarte_nrfx_set_power_state(struct device *dev, u32_t new_state)
		assert(new_state == DEVICE_PM_LOW_POWER_STATE ||
		       new_state == DEVICE_PM_SUSPEND_STATE ||
		       new_state == DEVICE_PM_OFF_STATE);

		/* Disabling UART requires stopping RX, but stop RX event is
		 * only sent after each RX if async UART API is used.
		 */
#ifdef CONFIG_UART_ASYNC_API
		if (get_dev_data(dev)->async) {
			nrf_uarte_disable(uarte);
			return;
		}
#endif
		nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX);
		while (!nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_RXTO)) {
			/* Busy wait for event to register */
		}
		nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXTO);
		nrf_uarte_disable(uarte);
	}
}