1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
4 * 2019/7/20 - ROBIN KRENS
13 #include <sys/robsys.h>
16 #include <lib/stdio.h>
17 #include <lib/regfunc.h>
20 uint32_t get_msp(void);
24 uint32_t tmp = *MCU_ID;
25 cputs("# DEVICE ID: ");
28 cputs("HIGH DENSITY\n");
34 cputs("# REVISION: ");
37 cputs("REVISION A\n");
40 cputs("REVISION Z\n");
43 cputs("REVISION 1/2/3/X/Y\n");
49 extern char _endofbss;
51 uint32_t current_stack = get_msp();
52 uint32_t stack_usage = (SRAM_OFFSET + SRAM_SIZE) - current_stack;
53 uint32_t data_bss = &_endofbss - SRAM_OFFSET;
54 uint32_t mem_free = SRAM_SIZE - stack_usage - data_bss;
56 cputs("# TOTAL MEMORY: ");
57 cputs(regtohex(SRAM_SIZE));
59 cputs("# FREE MEMORY: ");
60 cputs(regtohex(mem_free));
62 cputs("# STACK USAGE: ");
63 cputs(regtohex(stack_usage));
68 /* Get the master stack pointer's position
69 * Here we use a so-called naked function,
70 * that doesn't automatically push and pop */
72 uint32_t get_msp(void) __attribute__( ( naked ) );
73 uint32_t get_msp(void)
76 __asm__ volatile ("mrs %0, msp\n\t"
78 "bx lr \n\t" : "=r" (msp) );