arm: refactor clearing of exception faults to common code

A number of SoCs clear out the Mem/Bus/Usage and Hard Fault exceptions
during init.  Lets refactor that into a common function so we don't have
to keep duplicating it over and over.

Change-Id: Ida908a9092db37447abcf3c9872f36937982f729
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2017-01-25 09:12:00 -06:00
commit f16cefea9f
8 changed files with 36 additions and 43 deletions

View file

@ -90,6 +90,28 @@ static ALWAYS_INLINE void _ExcSetup(void)
#endif
}
/**
* @brief Clear Fault exceptions
*
* Clear out exceptions for Mem, Bus, Usage and Hard Faults
*
* @return N/A
*/
static ALWAYS_INLINE void _ClearFaults(void)
{
#if defined(CONFIG_ARMV6_M)
#elif defined(CONFIG_ARMV7_M)
/* Reset all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
#else
#error Unknown ARM architecture
#endif /* CONFIG_ARMV6_M */
}
#endif /* _ASMLANGUAGE */
#ifdef __cplusplus

View file

@ -19,6 +19,7 @@
#include <soc.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
/**
* @brief Setup various clock on SoC.
@ -162,12 +163,7 @@ static int atmel_sam3_init(struct device *arg)
__EEFC0->fmr = 0x00000400;
__EEFC1->fmr = 0x00000400;
/* Clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Setup master clock */
clock_init();

View file

@ -16,6 +16,7 @@
#include <device.h>
#include <init.h>
#include <soc.h>
#include <cortex_m/exc.h>
#ifdef CONFIG_RUNTIME_NMI
extern void _NmiInit(void);
@ -377,12 +378,7 @@ static int nordicsemi_nrf52_init(struct device *arg)
}
#endif
/* Reset all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Setup master clock */
clock_init();

View file

@ -22,6 +22,7 @@
#include <fsl_common.h>
#include <fsl_clock.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
#define PLLFLLSEL_MCGFLLCLK (0)
#define PLLFLLSEL_MCGPLLCLK (1)
@ -171,13 +172,7 @@ static int fsl_frdm_k64f_init(struct device *arg)
temp_reg |= MPU_CESR_SPERR_MASK;
MPU->CESR = temp_reg;
/* clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Initialize PLL/system clock to 120 MHz */
clkInit();

View file

@ -14,6 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
/**
* @brief Perform basic hardware initialization at boot.
@ -31,12 +32,7 @@ static int stm32f1_init(struct device *arg)
key = irq_lock();
/* Clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Install default handler that simply resets the CPU
* if configured in the kernel, NOP otherwise

View file

@ -14,6 +14,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
/**
* @brief Perform basic hardware initialization at boot.
@ -31,12 +32,7 @@ static int stm32f3_init(struct device *arg)
key = irq_lock();
/* Clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Install default handler that simply resets the CPU
* if configured in the kernel, NOP otherwise

View file

@ -15,6 +15,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
/**
* @brief Perform basic hardware initialization at boot.
@ -32,12 +33,7 @@ static int st_stm32f4_init(struct device *arg)
key = irq_lock();
/* Clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Install default handler that simply resets the CPU
* if configured in the kernel, NOP otherwise

View file

@ -15,6 +15,7 @@
#include <init.h>
#include <soc.h>
#include <arch/cpu.h>
#include <cortex_m/exc.h>
/**
* @brief Perform basic hardware initialization at boot.
@ -32,12 +33,7 @@ static int stm32l4_init(struct device *arg)
key = irq_lock();
/* Clear all faults */
_ScbMemFaultAllFaultsReset();
_ScbBusFaultAllFaultsReset();
_ScbUsageFaultAllFaultsReset();
_ScbHardFaultAllFaultsReset();
_ClearFaults();
/* Install default handler that simply resets the CPU
* if configured in the kernel, NOP otherwise