summaryrefslogtreecommitdiff
path: root/atmel-samd/main.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@chickadee.tech>2016-10-04 16:13:33 -0700
committerScott Shawcroft <scott@chickadee.tech>2016-10-04 16:13:33 -0700
commit1fa4c20c27264e55b3442fe49bee2078a4516fa6 (patch)
treef18b1c2681f4e325e4009329d17a01a7a7275c7e /atmel-samd/main.c
parent98458c56cc8801dce62866199541bcfcdb6ae26a (diff)
atmel-samd: Add Micro Trace Buffer support to the debug build.
The Micro Trace Buffer records the history of the pc and can be used to debug hard faults even when the stack trace is useless.
Diffstat (limited to 'atmel-samd/main.c')
-rw-r--r--atmel-samd/main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/atmel-samd/main.c b/atmel-samd/main.c
index b28b70668..42dddb8d3 100644
--- a/atmel-samd/main.c
+++ b/atmel-samd/main.c
@@ -270,7 +270,19 @@ void MP_WEAK __assert_func(const char *file, int line, const char *func, const c
struct usart_module usart_instance;
+#ifdef ENABLE_MICRO_TRACE_BUFFER
+#define TRACE_BUFFER_SIZE 256
+__attribute__((__aligned__(TRACE_BUFFER_SIZE * sizeof(uint32_t)))) uint32_t mtb[TRACE_BUFFER_SIZE];
+#endif
+
void samd21_init(void) {
+#ifdef ENABLE_MICRO_TRACE_BUFFER
+ memset(mtb, 0, sizeof(mtb));
+ // AWIDTH is 15.
+ REG_MTB_POSITION = ((uint32_t) (mtb - REG_MTB_BASE)) & 0xFFFFFFF8;
+ REG_MTB_FLOW = ((uint32_t) mtb + TRACE_BUFFER_SIZE * sizeof(uint32_t)) & 0xFFFFFFF8;
+ REG_MTB_MASTER = 0x80000000 + 6;
+#endif
irq_initialize_vectors();
cpu_irq_enable();