diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2014-11-15 13:48:49 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2014-11-15 13:48:49 +0100 |
commit | 4bcb2697415009279bd481eb9d22f015846147f1 (patch) | |
tree | 0a9f911499995d305f46cd7fa4956b708d6ac52b /src/systemcmds | |
parent | 780451dd65db72aa28b75ddad2effbbba8db8626 (diff) | |
download | px4-firmware-4bcb2697415009279bd481eb9d22f015846147f1.tar.gz px4-firmware-4bcb2697415009279bd481eb9d22f015846147f1.tar.bz2 px4-firmware-4bcb2697415009279bd481eb9d22f015846147f1.zip |
Add capability to read chip ID and revision from ver command
Diffstat (limited to 'src/systemcmds')
-rw-r--r-- | src/systemcmds/ver/ver.c | 85 |
1 files changed, 84 insertions, 1 deletions
diff --git a/src/systemcmds/ver/ver.c b/src/systemcmds/ver/ver.c index 9ae080ee2..b11b593c3 100644 --- a/src/systemcmds/ver/ver.c +++ b/src/systemcmds/ver/ver.c @@ -53,13 +53,38 @@ static const char sz_ver_bdate_str[] = "bdate"; static const char sz_ver_gcc_str[] = "gcc"; static const char sz_ver_all_str[] = "all"; +#ifdef CONFIG_ARCH_CHIP_STM32 +#include <up_arch.h> + +static const char mcu_ver_str[] = "mcu"; + +#define DBGMCU_IDCODE 0xE0042000 + +#define STM32F40x_41x 0x413 +#define STM32F42x_43x 0x419 + +#define REVID_MASK 0xFFFF0000 +#define DEVID_MASK 0xFFF + +/* magic numbers from reference manual */ +enum STM32F4_REV { + STM32F4_REV_A = 0x1000, + STM32F4_REV_Z = 0x1001, + STM32F4_REV_Y = 0x1003, + STM32F4_REV_1 = 0x1007, + STM32F4_REV_3 = 0x2001 +}; +#else +#error stm32 +#endif + static void usage(const char *reason) { if (reason != NULL) { printf("%s\n", reason); } - printf("usage: ver {hw|hwcmp|git|bdate|gcc|all}\n\n"); + printf("usage: ver {hw|hwcmp|git|bdate|gcc|all|mcu}\n\n"); } __EXPORT int ver_main(int argc, char *argv[]); @@ -107,6 +132,64 @@ int ver_main(int argc, char *argv[]) printf("GCC toolchain: %s\n", __VERSION__); ret = 0; +#ifdef CONFIG_ARCH_CHIP_STM32 + } else if (!strncmp(argv[1], mcu_ver_str, sizeof(mcu_ver_str))) { + uint32_t abc = getreg32(DBGMCU_IDCODE); + + uint32_t chip_version = abc & DEVID_MASK; + enum STM32F4_REV revid = (abc & REVID_MASK) >> 16; + + printf("CHIP TYPE: "); + + switch (revid) { + case STM32F40x_41x: + printf("STM32F40x"); + break; + case STM32F42x_43x: + printf("STM32F42x"); + break; + default: + printf("STM32F???"); + break; + } + + char rev; + + switch (chip_version) { + + case STM32F4_REV_A: + rev = 'A'; + break; + case STM32F4_REV_Z: + rev = 'Z'; + break; + case STM32F4_REV_Y: + rev = 'Y'; + break; + case STM32F4_REV_1: + rev = '1'; + break; + case STM32F4_REV_3: + rev = '3'; + break; + default: + rev = '?'; + break; + } + + printf("\nHW REV: %c\n", rev); + + if (rev < STM32F4_REV_3) { + printf("\n\nWARNING WARNING WARNING!\n" + "Revision %c has a silicon errata\n" + "on USB connectivity combined with\n" + "flash bank #2. This device can only\n" + "utilize a maximum of 1MB flash safely!\n" + "http://px4.io/help/errata\n", rev); + } + ret = 0; +#endif + } else { errx(1, "unknown command.\n"); } |