]> git.gag.com Git - fw/stlink/commitdiff
Support arm core cpuid register decoding
authorKarl Palsson <karlp@tweak.net.au>
Wed, 12 Oct 2011 20:40:24 +0000 (20:40 +0000)
committerKarl Palsson <karlp@tweak.net.au>
Wed, 12 Oct 2011 20:40:24 +0000 (20:40 +0000)
src/stlink-common.c
src/stlink-common.h
src/stlink-usb.c
src/test_usb.c

index 0aadb3d4891c7de73b76058398c6ebad0b938b46..707316cc988051daf4bd4085a486870f0084db65 100644 (file)
@@ -258,7 +258,6 @@ static void disable_flash_read_protection(stlink_t *sl) {
 void stlink_close(stlink_t *sl) {
     D(sl, "\n*** stlink_close ***\n");
     sl->backend->close(sl);
-
     free(sl);
 }
 
@@ -299,10 +298,24 @@ uint16_t stlink_chip_id(stlink_t *sl) {
     return chip_id;
 }
 
+/**
+ * Cortex m3 tech ref manual, CPUID register description
+ * @param sl stlink context
+ * @param cpuid pointer to the result object
+ */
+void stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid) {
+    stlink_read_mem32(sl, CM3_REG_CPUID, 4);
+    uint32_t raw = read_uint32(sl->q_buf, 0);
+    cpuid->implementer_id = (raw >> 24) & 0x7f;
+    cpuid->variant = (raw >> 20) & 0xf;
+    cpuid->part = (raw >> 4) & 0xfff;
+    cpuid->revision = raw & 0xf;
+    return;
+}
+
 void stlink_reset(stlink_t *sl) {
     D(sl, "\n*** stlink_reset ***\n");
     sl->backend->reset(sl);
-
 }
 
 void stlink_run(stlink_t *sl) {
index 7c3c0cbe32694169c59eb4cacf85876cd4642591..b357c7a52a533438aa68f61b2a4d2ab1a049295d 100644 (file)
@@ -71,6 +71,9 @@ extern "C" {
 #define STLINK_SWD_ENTER 0x30
 #define STLINK_SWD_READCOREID 0x32  // TBD
 
+// cortex m3 technical reference manual
+#define CM3_REG_CPUID 0xE000ED00
+
     typedef struct {
         uint32_t r[16];
         uint32_t xpsr;
@@ -81,6 +84,13 @@ extern "C" {
     } reg;
 
     typedef uint32_t stm32_addr_t;
+    
+    typedef struct _cortex_m3_cpuid_ {
+        uint16_t implementer_id;
+        uint16_t variant;
+        uint16_t part;
+        uint8_t revision;
+    } cortex_m3_cpuid_t;
 
     typedef struct stlink_version_ {
         uint32_t stlink_v;
@@ -197,6 +207,7 @@ extern "C" {
     
     // PUBLIC
     uint16_t stlink_chip_id(stlink_t *sl);
+    void stlink_cpu_id(stlink_t *sl, cortex_m3_cpuid_t *cpuid);
 
     // privates, publics, the rest....
     // TODO sort what is private, and what is not
index 16f934304027f9a90ef1fb71dbf12e7aeb6e9d67..895b368fa512c432d44802e972adeccbcd932f6a 100644 (file)
@@ -528,4 +528,5 @@ on_error:
     if (sl != NULL) free(sl);
     if (slu != NULL) free(slu);
     return 0;
-}
\ No newline at end of file
+}
+
index 0c4232f8477c7098abf051a93059a33a78a597df..3d31453969a4df1bb464319172bb2dd914ac0beb 100644 (file)
@@ -23,8 +23,12 @@ int main(int ac, char** av) {
         printf("-- mode after entering swd mode: %d\n", stlink_current_mode(sl));
 
         printf("-- chip id: %#x\n", stlink_chip_id(sl));
-        printf("-- core_id\n");
-        stlink_core_id(sl);
+        printf("-- core_id: %#x\n", stlink_core_id(sl));
+
+        cortex_m3_cpuid_t cpuid;
+        stlink_cpu_id(sl, &cpuid);
+        printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant);
+        printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision);
 
         printf("-- read_sram\n");
         static const uint32_t sram_base = 0x8000000;