ChiaYen Kan / Mbed 2 deprecated Nucleo_L053R8_NTShell

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kcy
Date:
Tue Apr 14 08:38:12 2015 +0000
Parent:
2:438e2649030d
Commit message:
add show CPU information

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Apr 13 15:12:57 2015 +0000
+++ b/main.cpp	Tue Apr 14 08:38:12 2015 +0000
@@ -3,6 +3,16 @@
 #include "ntlibc.h"
 #include "VT100CtrlCode.h"
 
+#define CPUID_ADDR (0xe000ed00)
+typedef struct
+{
+  uint32_t Revision:4;
+  uint32_t Partno:12;
+  uint32_t Constant:4;
+  uint32_t Variant:4;
+  uint32_t Implementer:8;
+} CPUID;
+
 Serial pc(SERIAL_TX, SERIAL_RX);
 DigitalOut gpio(LED1);
 
@@ -53,8 +63,19 @@
                        "\r\n";
 
     pc.printf(Mark);
+    pc.printf("\r\n");    
+    
+    uint32_t regValue = *((uint32_t *)CPUID_ADDR);
+    volatile CPUID cpuid = *((CPUID *)&regValue);
+    pc.printf("CPU Information\r\n");
+    pc.printf("Implementer : 0x%02x\r\n", cpuid.Implementer);
+    pc.printf("Variant     : 0x%1x\r\n", cpuid.Variant);
+    pc.printf("Constant    : 0x%1x\r\n", cpuid.Constant);
+    pc.printf("Partno      : 0x%3x\r\n", cpuid.Partno);
+    pc.printf("Revision    : r%dp%d\r\n", (cpuid.Revision & 0x3 >> 2), (cpuid.Revision & 0x3));
+    pc.printf("SysClock    : %d\r\n", SystemCoreClock);
+    pc.printf("\r\n");
 
-    pc.printf("\r\n");
     pc.printf("Type <" Foreground256(193) Background256(1) "LED" ResetAll "> to toggle led");
     pc.printf("\r\n");
     ntshell_init(&ntshell, func_read, func_write, func_callback, 0);