1 /* (CC-BY-NC-SA) ROBIN KRENS - ROBIN @ ROBINKRENS.NL
4 * 2019/7/20 - ROBIN KRENS
6 * Display some system information, calculate
7 * the amount of SRAM available
15 #include <sys/robsys.h>
18 #include <lib/tinyprintf.h>
19 #include <lib/regfunc.h>
22 uint32_t get_msp(void);
26 uint32_t tmp = *MCU_ID;
27 printf("# DEVICE ID: ");
30 printf("HIGH DENSITY\n");
36 printf("# REVISION: ");
39 printf("REVISION A\n");
42 printf("REVISION Z\n");
45 printf("REVISION 1/2/3/X/Y\n");
51 extern char _endofbss;
53 uint32_t current_stack = get_msp();
54 uint32_t stack_usage = (SRAM_OFFSET + SRAM_SIZE) - current_stack;
55 uint32_t data_bss = (uint32_t) &_endofbss - SRAM_OFFSET;
56 uint32_t mem_free = SRAM_SIZE - stack_usage - data_bss;
58 printf("# TOTAL MEMORY: %#x\n", SRAM_SIZE);
59 printf("# FREE MEMORY: %#x\n", mem_free);
60 printf("# STACK USAGE: %#x\n", stack_usage);
64 /* Get the master stack pointer's position
65 * Here we use a so-called naked function,
66 * that doesn't automatically push and pop */
68 uint32_t get_msp(void) __attribute__( ( naked ) );
69 uint32_t get_msp(void)
72 __asm__ volatile ("mrs %0, msp\n\t"
74 "bx lr \n\t" : "=r" (msp) );