forked from nrfconnect/sdk-mcuboot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nrf noup] zephyr: clean peripherals state before boot
Do some cleanup of nRF peripherals. This is necessary since Zephyr doesn't have any driver deinitialization functionality, and we'd like to leave peripherals in a more predictable state before booting the Zephyr image. This should be re-worked when the zephyr driver model allows us to deinitialize devices cleanly before jumping to the chain-loaded image. Signed-off-by: Andrzej Puzdrowski <[email protected]> Signed-off-by: Robert Lubos <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Øyvind Rønningstad <[email protected]> Signed-off-by: Martí Bolívar <[email protected]> Signed-off-by: Håkon Øye Amundsen <[email protected]> Signed-off-by: Ioannis Glaropoulos <[email protected]> Signed-off-by: Johann Fischer <[email protected]> Signed-off-by: Trond Einar Snekvik <[email protected]> Signed-off-by: Torsten Rasmussen <[email protected]> Signed-off-by: Jamie McCrae <[email protected]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 3b2a5ba)
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2020 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#ifndef H_NRF_CLEANUP_ | ||
#define H_NRF_CLEANUP_ | ||
|
||
/** | ||
* Perform cleanup on some peripheral resources used by MCUBoot prior chainload | ||
* the application. | ||
* | ||
* This function disables all RTC instances and UARTE instances. | ||
* It Disables their interrupts signals as well. | ||
*/ | ||
void nrf_cleanup_peripheral(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2020 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include <hal/nrf_clock.h> | ||
#if defined(NRF_UARTE0) || defined(NRF_UARTE1) | ||
#include <hal/nrf_uarte.h> | ||
#endif | ||
#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2) | ||
#include <hal/nrf_rtc.h> | ||
#endif | ||
#if defined(NRF_PPI) | ||
#include <hal/nrf_ppi.h> | ||
#endif | ||
#if defined(NRF_DPPIC) | ||
#include <hal/nrf_dppi.h> | ||
#endif | ||
|
||
#include <string.h> | ||
|
||
#define NRF_UARTE_SUBSCRIBE_CONF_OFFS offsetof(NRF_UARTE_Type, SUBSCRIBE_STARTRX) | ||
#define NRF_UARTE_SUBSCRIBE_CONF_SIZE (offsetof(NRF_UARTE_Type, EVENTS_CTS) -\ | ||
NRF_UARTE_SUBSCRIBE_CONF_OFFS) | ||
|
||
#define NRF_UARTE_PUBLISH_CONF_OFFS offsetof(NRF_UARTE_Type, PUBLISH_CTS) | ||
#define NRF_UARTE_PUBLISH_CONF_SIZE (offsetof(NRF_UARTE_Type, SHORTS) -\ | ||
NRF_UARTE_PUBLISH_CONF_OFFS) | ||
|
||
#if defined(NRF_RTC0) || defined(NRF_RTC1) || defined(NRF_RTC2) | ||
static inline void nrf_cleanup_rtc(NRF_RTC_Type * rtc_reg) | ||
{ | ||
nrf_rtc_task_trigger(rtc_reg, NRF_RTC_TASK_STOP); | ||
nrf_rtc_event_disable(rtc_reg, 0xFFFFFFFF); | ||
nrf_rtc_int_disable(rtc_reg, 0xFFFFFFFF); | ||
} | ||
#endif | ||
|
||
static void nrf_cleanup_clock(void) | ||
{ | ||
nrf_clock_int_disable(NRF_CLOCK, 0xFFFFFFFF); | ||
} | ||
|
||
void nrf_cleanup_peripheral(void) | ||
{ | ||
#if defined(NRF_RTC0) | ||
nrf_cleanup_rtc(NRF_RTC0); | ||
#endif | ||
#if defined(NRF_RTC1) | ||
nrf_cleanup_rtc(NRF_RTC1); | ||
#endif | ||
#if defined(NRF_RTC2) | ||
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 | ||
#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 | ||
#endif | ||
#if defined(NRF_PPI) | ||
nrf_ppi_channels_disable_all(NRF_PPI); | ||
#endif | ||
#if defined(NRF_DPPIC) | ||
nrf_dppi_channels_disable_all(NRF_DPPIC); | ||
#endif | ||
nrf_cleanup_clock(); | ||
} |