diff --git a/cpu/atmega_common/include/cpu.h b/cpu/atmega_common/include/cpu.h index 45361f2b19..b01b43daa6 100644 --- a/cpu/atmega_common/include/cpu.h +++ b/cpu/atmega_common/include/cpu.h @@ -1,6 +1,7 @@ /* * Copyright (C) 2015 Kaspar Schleiser * 2014 Freie Universität Berlin, Hinnerk van Bruinehsen + * 2018 RWTH Aachen, Josua Arndt * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -22,6 +23,8 @@ * @author Hauke Petersen * @author Hinnerk van Bruinehsen * @author Kaspar Schleiser + * @author Josua Arndt + * */ #ifndef CPU_H @@ -76,7 +79,22 @@ void cpu_init(void); */ static inline void cpu_print_last_instruction(void) { - puts("n/a"); + uint8_t hi; + uint8_t lo; + uint16_t ptr; + + __asm__ volatile( "in r0, __SP_H__; \n\t" + "mov %0, r0 \n\t" + : "=g"(hi) + : + : "r0"); + __asm__ volatile( "in r0, __SP_L__; \n\t" + "mov %0, r0 \n\t" + : "=g"(lo) + : + : "r0"); + ptr = hi<<8 | lo; + printf("Stack Pointer: 0x%04x\n", ptr); } #ifdef __cplusplus