Browse Source

Add call to access the mcu unique id. Expose via the 'ver' command.

This is prep for verifying calibration parameters against the hardware they were gathered on.
sbg
hauptmech 10 years ago committed by Lorenz Meier
parent
commit
5444972347
  1. 11
      src/modules/systemlib/mcu_version.c
  2. 11
      src/modules/systemlib/mcu_version.h
  3. 14
      src/systemcmds/ver/ver.c

11
src/modules/systemlib/mcu_version.c

@ -47,7 +47,8 @@ @@ -47,7 +47,8 @@
#ifdef CONFIG_ARCH_CHIP_STM32
#include <up_arch.h>
#define DBGMCU_IDCODE 0xE0042000
#define DBGMCU_IDCODE 0xE0042000 //STM DocID018909 Rev 8 Sect 38.18 (MCU device ID code)
#define UNIQUE_ID 0x1FFF7A10 //STM DocID018909 Rev 8 Sect 39.1 (Unique device ID Register)
#define STM32F40x_41x 0x413
#define STM32F42x_43x 0x419
@ -57,7 +58,13 @@ @@ -57,7 +58,13 @@
#endif
/** Copy the 96bit MCU Unique ID into the provided pointer */
void mcu_unique_id(uint32_t *uid_96_bit)
{
uid_96_bit[0] = getreg32(UNIQUE_ID);
uid_96_bit[1] = getreg32(UNIQUE_ID+4);
uid_96_bit[2] = getreg32(UNIQUE_ID+8);
}
int mcu_version(char* rev, char** revstr)
{

11
src/modules/systemlib/mcu_version.h

@ -33,6 +33,8 @@ @@ -33,6 +33,8 @@
#pragma once
#include <stdint.h>
/* magic numbers from reference manual */
enum MCU_REV {
MCU_REV_STM32F4_REV_A = 0x1000,
@ -42,6 +44,15 @@ enum MCU_REV { @@ -42,6 +44,15 @@ enum MCU_REV {
MCU_REV_STM32F4_REV_3 = 0x2001
};
/**
* Reports the microcontroller unique id.
*
* This ID is guaranteed to be unique for every mcu.
* @param uid_96_bit A uint32_t[3] array to copy the data to.
*/
__EXPORT void mcu_unique_id(uint32_t *uid_96_bit);
/**
* Reports the microcontroller version of the main CPU.
*

14
src/systemcmds/ver/ver.c

@ -54,6 +54,7 @@ static const char sz_ver_bdate_str[] = "bdate"; @@ -54,6 +54,7 @@ static const char sz_ver_bdate_str[] = "bdate";
static const char sz_ver_gcc_str[] = "gcc";
static const char sz_ver_all_str[] = "all";
static const char mcu_ver_str[] = "mcu";
static const char mcu_uid_str[] = "uid";
static void usage(const char *reason)
{
@ -61,7 +62,7 @@ static void usage(const char *reason) @@ -61,7 +62,7 @@ static void usage(const char *reason)
printf("%s\n", reason);
}
printf("usage: ver {hw|hwcmp|git|bdate|gcc|all|mcu}\n\n");
printf("usage: ver {hw|hwcmp|git|bdate|gcc|all|mcu|uid}\n\n");
}
__EXPORT int ver_main(int argc, char *argv[]);
@ -141,6 +142,17 @@ int ver_main(int argc, char *argv[]) @@ -141,6 +142,17 @@ int ver_main(int argc, char *argv[])
ret = 0;
}
if (show_all || !strncmp(argv[1], mcu_uid_str, sizeof(mcu_uid_str))) {
uint32_t uid[3];
mcu_unique_id(uid);
printf("UID: %X:%X:%X \n",uid[0],uid[1],uid[2]);
ret = 0;
}
if (ret == 1) {
errx(1, "unknown command.\n");
}

Loading…
Cancel
Save