diff --git a/boot/zephyr/nrf_cleanup.c b/boot/zephyr/nrf_cleanup.c index 2165159ea..9aec4bd53 100644 --- a/boot/zephyr/nrf_cleanup.c +++ b/boot/zephyr/nrf_cleanup.c @@ -7,6 +7,7 @@ #include #if defined(NRF_UARTE0) || defined(NRF_UARTE1) #include + #include #endif #if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2) #include @@ -46,6 +47,33 @@ static void nrf_cleanup_clock(void) nrf_clock_int_disable(NRF_CLOCK, 0xFFFFFFFF); } +#if defined(NRF_UARTE0) || defined(NRF_UARTE1) +static void uninit_used_uarte(NRF_UARTE_Type *p_reg) +{ + uint32_t pin[4]; + + nrf_uarte_disable(p_reg); + + pin[0] = nrf_uarte_tx_pin_get(p_reg); + pin[1] = nrf_uarte_rx_pin_get(p_reg); + pin[2] = nrf_uarte_rts_pin_get(p_reg); + pin[3] = nrf_uarte_cts_pin_get(p_reg); + + for (int i = 0; i < 4; i++) { + if (pin[i] != NRF_UARTE_PSEL_DISCONNECTED) { + nrf_gpio_cfg_default(pin[i]); + } + } + + #if defined(NRF_DPPIC) + /* Clear all SUBSCRIBE configurations. */ + memset((uint8_t *)p_reg + NRF_UARTE_SUBSCRIBE_CONF_OFFS, 0, NRF_UARTE_SUBSCRIBE_CONF_SIZE); + /* Clear all PUBLISH configurations. */ + memset((uint8_t *)p_reg + NRF_UARTE_PUBLISH_CONF_OFFS, 0, NRF_UARTE_PUBLISH_CONF_SIZE); + #endif +} +#endif + void nrf_cleanup_peripheral(void) { #if defined(NRF_RTC0) @@ -58,24 +86,10 @@ void nrf_cleanup_peripheral(void) nrf_cleanup_rtc(NRF_RTC2); #endif #if defined(NRF_UARTE0) - nrf_uarte_disable(NRF_UARTE0); - nrf_uarte_int_disable(NRF_UARTE0, 0xFFFFFFFF); -#if defined(NRF_DPPIC) - /* Clear all SUBSCRIBE configurations. */ - memset((uint8_t *)NRF_UARTE0 + NRF_UARTE_SUBSCRIBE_CONF_OFFS, 0, NRF_UARTE_SUBSCRIBE_CONF_SIZE); - /* Clear all PUBLISH configurations. */ - memset((uint8_t *)NRF_UARTE0 + NRF_UARTE_PUBLISH_CONF_OFFS, 0, NRF_UARTE_PUBLISH_CONF_SIZE); -#endif + uninit_used_uarte(NRF_UARTE0); #endif #if defined(NRF_UARTE1) - nrf_uarte_disable(NRF_UARTE1); - nrf_uarte_int_disable(NRF_UARTE1, 0xFFFFFFFF); -#if defined(NRF_DPPIC) - /* Clear all SUBSCRIBE configurations. */ - memset((uint8_t *)NRF_UARTE1 + NRF_UARTE_SUBSCRIBE_CONF_OFFS, 0, NRF_UARTE_SUBSCRIBE_CONF_SIZE); - /* Clear all PUBLISH configurations. */ - memset((uint8_t *)NRF_UARTE1 + NRF_UARTE_PUBLISH_CONF_OFFS, 0, NRF_UARTE_PUBLISH_CONF_SIZE); -#endif + uninit_used_uarte(NRF_UARTE1); #endif #if defined(NRF_PPI) nrf_ppi_channels_disable_all(NRF_PPI);