diff --git a/common/main.c b/common/main.c index d807f17101..0feefee7e9 100644 --- a/common/main.c +++ b/common/main.c @@ -6,6 +6,7 @@ */ #include "clock.h" +#include "cpu.h" #include "config.h" #include "eeprom.h" #include "eoption.h" @@ -65,6 +66,7 @@ int main(void) timer_init(); /* Main initialization stage. Modules may enable interrupts here. */ + cpu_init(); /* Initialize UART. uart_printf(), etc. may now be used. */ uart_init(); diff --git a/core/cortex-m/build.mk b/core/cortex-m/build.mk index 65d3b06551..7a2f16e4e9 100644 --- a/core/cortex-m/build.mk +++ b/core/cortex-m/build.mk @@ -13,6 +13,6 @@ CFLAGS_FPU-$(CONFIG_FPU)=-mfpu=fpv4-sp-d16 -mfloat-abi=hard CFLAGS_CPU=-mcpu=cortex-m4 -mthumb -Os -mno-sched-prolog CFLAGS_CPU+=$(CFLAGS_FPU-y) -core-y=init.o panic.o switch.o task.o timer.o +core-y=cpu.o init.o panic.o switch.o task.o timer.o core-$(CONFIG_FPU)+=fpu.o core-$(CONFIG_TASK_WATCHDOG)+=watchdog.o diff --git a/core/cortex-m/cpu.c b/core/cortex-m/cpu.c new file mode 100644 index 0000000000..cae74b2cd4 --- /dev/null +++ b/core/cortex-m/cpu.c @@ -0,0 +1,15 @@ +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Set up the Cortex-M core + */ + +#include "cpu.h" + + +void cpu_init(void) +{ + /* Catch divide by 0 and unaligned access */ + CPU_NVIC_CCR |= CPU_NVIC_CCR_DIV_0_TRAP | CPU_NVIC_CCR_UNALIGN_TRAP; +} diff --git a/core/cortex-m/cpu.h b/core/cortex-m/cpu.h index 2e75d6c1c5..f84a1fdfb0 100644 --- a/core/cortex-m/cpu.h +++ b/core/cortex-m/cpu.h @@ -43,4 +43,7 @@ enum { CPU_NVIC_HFSR_VECTTBL = 1 << 1, }; +/* Set up the cpu to detect faults */ +void cpu_init(void); + #endif /* __CPU_H */