application: remove all MCU model info. this has moved to the dedicated identifier firmware

This commit is contained in:
King Kévin 2020-06-24 11:54:33 +02:00
parent 5a028c23c4
commit 629500e4bd
1 changed files with 1 additions and 267 deletions

View File

@ -188,273 +188,7 @@ static void command_version(void* argument)
{
(void)argument; // we won't use the argument
printf("firmware date: %04u-%02u-%02u\n", BUILD_YEAR, BUILD_MONTH, BUILD_DAY); // show firmware build date
// show flash size
puts("MCU advertised flash size: ");
if (0xffff == DESIG_FLASH_SIZE) {
puts("unknown (probably a counterfeit/defective micro-controller\n");
} else {
printf("%u KB\n", DESIG_FLASH_SIZE);
}
if ((uint32_t)&__flash_end >= FLASH_BASE) {
printf("linker advertised flash size: %u KB\n", ((uint32_t)&__flash_end - FLASH_BASE) / 1024);
}
uint32_t flash_size = flash_internal_probe_read_size();
printf("readable flash size: %u bytes (%u KB)\n", flash_size, flash_size / 1024);
flash_size = flash_internal_probe_write_size();
printf("writable flash size: %u bytes (%u KB)\n", flash_size, flash_size / 1024);
const uint16_t dev_id = DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK;
const uint16_t rev_id = DBGMCU_IDCODE >> 16;
char* unreadable;
if (0 == DBGMCU_IDCODE && 0 == (SCS_DHCSR & SCS_DHCSR_C_DEBUGEN)) {
unreadable = " (not readable, retry with debug attached)";
} else if (0x307 == DBGMCU_IDCODE && (SCS_DHCSR & SCS_DHCSR_C_DEBUGEN)) {
unreadable = " (erroneous reading, read over debug first)";
} else {
unreadable = "";
}
printf("MCU id code: %+08x (DEV_ID=0x%03x REV_ID=0x%04x)%s\n", DBGMCU_IDCODE, dev_id, rev_id, unreadable); // see below for details
printf("device id: %08x%08x%04x%04x\n", DESIG_UNIQUE_ID2, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID0 & 0xffff, DESIG_UNIQUE_ID0 >> 16); // not that the half-works are reversed in the first word
//printf("SCS_DHCSR: %+08x, DEBUGEN: %u\n", SCS_DHCSR, SCS_DHCSR & SCS_DHCSR_C_DEBUGEN);
// SCS_DHCSR: 0x03010000, DEBUGEN: 0 debug not attached
// SCS_DHCSR: 0x01010001, DEBUGEN: 1 debug attached
#if DEBUG
bool fake = false; // if details indicate it's not an STM32
puts("chip family: ");
switch (dev_id) {
case 0: // DBGMCU_IDCODE is only accessible in debug mode (this is a known issue documented in STM32F10xx8/B and STM32F10xxC/D/E Errata sheet, without workaround) (CKS32F103 is not affected by this issue)
puts("not readable, retry with debug attached");
break;
// from RM0008 STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx and STM32F107xx
case 0x307: // this is completely undocumented (even in the errata), but even with debug attached, DBGMCU_IDCODE = 0x00000307, until the DBGMCU_IDCODE is read over SWJ, only then it's correct. but the JEP106 ID part number is always right (with same meaning). this has been seen on a genuine STM32F103C8T6 (AFAICS)
puts("erroneous reading, read over debug first");
break;
case 0x412:
puts("STM32F10x low-density");
break;
case 0x410:
puts("STM32F10x medium-density");
break;
case 0x414:
puts("STM32F10x high-density");
break;
case 0x430:
puts("STM32F10x XL-density");
break;
case 0x418:
puts("STM32F10x connectivity");
break;
// from RM0091 STM32F0x8
case 0x444:
puts("STM32F03x");
break;
case 0x445:
puts("STM32F04x");
break;
case 0x440:
puts("STM32F05x");
break;
case 0x448:
puts("STM32F07x");
break;
case 0x442:
puts("STM32F09x");
break;
// from RM0444 STM32G0x1
case 0x460:
puts("STM32G071xx/STM32G081xx");
break;
case 0x466:
puts("STM32G031xx/STM32G041xx");
break;
// from RM0090 STM32F4x5/STM32F4x7
case 0x413:
puts("STM32F405/STM32F407/STM32F415/STM32F417");
break;
case 0x419:
puts("STM32F42x/STM32F43x");
break;
// from RM0368
case 0x423:
puts("STM32F401xB/C");
break;
case 0x433:
puts("STM32F401xD/E");
break;
// from RM0383
case 0x431:
puts("STM32F411xC/E");
break;
default:
puts("unknown");
fake = true;
break;
}
putc('\n');
puts("chip revision: ");
switch (DBGMCU_IDCODE & DBGMCU_IDCODE_DEV_ID_MASK) {
case 0x412:
if (0x1000 == rev_id) {
putc('A');
} else {
puts("unknown");
}
break;
case 0x410:
if (0x0000 == rev_id) {
putc('A');
} else if (0x2000 == rev_id) {
putc('B');
} else if (0x2001 == rev_id) {
putc('Z');
} else if (0x2003 == rev_id) {
puts("1/2/3/X/Y");
} else {
puts("unknown");
}
break;
case 0x414:
if (0x1000 == rev_id) {
puts("A/1");
} else if (0x1001 == rev_id) {
putc('Z');
} else if (0x1003 == rev_id) {
puts("1/2/3/X/Y");
} else {
puts("unknown");
}
break;
case 0x430:
if (0x1003 == rev_id) {
puts("A/1");
} else {
puts("unknown");
}
break;
case 0x418:
if (0x1000 == rev_id) {
putc('A');
} else if (0x1001 == rev_id) {
putc('Z');
} else {
puts("unknown");
}
break;
default:
printf("unknown");
break;
}
putc('\n');
// from RM0091 STM32F0x8 reference manual (not sure if it applies to F1)
puts("manufacturing information (STM32F0x8 schema):\n");
printf("- X,Y wafer coordinate: %08x\n", DESIG_UNIQUE_ID0);
printf("- lot number: %c%c%c%c%c%c%c\n", DESIG_UNIQUE_ID2 >> 24, DESIG_UNIQUE_ID2 >> 16, DESIG_UNIQUE_ID2 >> 8, DESIG_UNIQUE_ID2 >> 0, DESIG_UNIQUE_ID1 >> 24, DESIG_UNIQUE_ID1 >> 16, DESIG_UNIQUE_ID1 >> 8);
printf("- wafer number: %u\n", DESIG_UNIQUE_ID1 & 0xff);
// from ARMv7-M and Cortex-M3 TRM
// ARMv7-M B3.2.3
printf("CPUID: 0x%08x\n", SCB_CPUID);
const uint8_t cpuid_implementer = (SCB_CPUID & SCB_CPUID_IMPLEMENTER) >> SCB_CPUID_IMPLEMENTER_LSB;
printf("- implementer: %s (0x%02x)\n", 0x41 == cpuid_implementer ? "ARM" : "unknown", cpuid_implementer);
const uint8_t cpuid_architecture = (SCB_CPUID & SCB_CPUID_CONSTANT) >> SCB_CPUID_CONSTANT_LSB;
puts("- architecture: ");
switch (cpuid_architecture) {
case 0xc:
puts("ARMv6-M");
break;
case 0xf:
puts("ARMv7-M");
break;
default:
fake = true;
puts("unknown");
}
printf(" (0x%x)\n", cpuid_architecture);
const uint16_t cpuid_partno = (SCB_CPUID & SCB_CPUID_PARTNO) >> SCB_CPUID_PARTNO_LSB;
puts("- part number: ");
switch (cpuid_partno) {
case 0xC60:
puts("Cortex-M0+");
break;
case 0xC20:
puts("Cortex-M0");
break;
case 0xC23: // the ARM spec actually mentions 0xC24
puts("Cortex-M3");
break;
case 0xC24:
puts("Cortex-M4");
break;
case 0xC27:
puts("Cortex-M7");
break;
default:
fake = true;
puts("unknown");
}
printf(" (0x%03x)\n", cpuid_partno);
const uint8_t cpuid_variant = (SCB_CPUID & SCB_CPUID_VARIANT) >> SCB_CPUID_VARIANT_LSB;
printf("- variant: %u\n", cpuid_variant);
const uint8_t cpuid_revision = (SCB_CPUID & SCB_CPUID_REVISION) >> SCB_CPUID_REVISION_LSB;
printf("- revision: %u\n", cpuid_revision);
// ARM CoreSight B2.2.2
const uint8_t jep106_continuation = *(uint32_t*)0xE00FFFD0 & 0x0f; // DES_2, PIDR4 bits[3:0]
const uint8_t jep106_identification = ((*(uint32_t*)0xE00FFFE8 & 0x7) << 4) + ((*(uint32_t*)0xE00FFFE4 >> 4) & 0xf); // DES_0, PIDR1 bits[7:4] JEP106 identification code bits[3:0], DES_1, PIDR2 bits[2:0] JEP106 identification code bits[6:4]
const uint16_t pidr_partno = ((*(uint32_t*)0xE00FFFE4 & 0xf) << 8) + (*(uint32_t*)0xE00FFFE0 & 0xff); // PART_0, PIDR0 bits[7:0] Part number bits[7:0], PART_1, PIDR1 bits[3:0] Part number bits[11:8]
puts("JEP106 ID: ");
if (0 == jep106_continuation && 0x20 == jep106_identification) {
puts("STM");
} else if (7 == jep106_continuation && 0x51 == jep106_identification) {
puts("GigaDevice");
} else if (4 == jep106_continuation && 0x3b == jep106_identification) {
puts("ARM");
} else {
puts("unknown");
}
printf(" (cont.=%u, ID=0x%02x), part=0x%03x\n", jep106_continuation, jep106_identification, pidr_partno);
// guess the micro-controller
char* mcu = "STM32"; // which MCU is identified
puts("MCU: ");
if (1 == cpuid_variant && 1 == cpuid_revision && 0 == jep106_continuation && 0x20 == jep106_identification) { // STM32 uses Cortex-M3 r1p1 and the right JEP106 ID
mcu = "STM32";
} else if (2 == cpuid_variant && 1 == cpuid_revision && 7 == jep106_continuation && 0x51 == jep106_identification) { // GD32 uses Cortex-M3 r2p1 and the right JEP106 ID
mcu = "GD32";
fake = true;
} else if (2 == cpuid_variant && 1 == cpuid_revision && 4 == jep106_continuation && 0x3b == jep106_identification) { // GD32 uses Cortex-M3 r2p1 and ARM JEP106 ID
mcu = "CKS32";
fake = true;
} else {
mcu = "unknown";
fake = true;
}
puts(mcu);
putc('\n');
// detect fake STM32
if (0x412 == dev_id || 0x410 == dev_id || 0x414 == dev_id || 0x430 == dev_id || 0x418 == dev_id) { // STM32F10x
// STM32F10x uses a Cortex-M3 r1p1
if (0xC23 != cpuid_partno) { // Cortex-M3
fake = true;
}
if (1 != cpuid_variant) { // r1
fake = true;
}
if (1 != cpuid_revision) { // p1
fake = true;
}
}
if (0 != DBGMCU_IDCODE && 0 == (SCS_DHCSR & SCS_DHCSR_C_DEBUGEN)) { // STM32 can't read the MCU ID without debug attached (see errata). CKS32 is not affected by this issue
fake = true;
}
if (0 == strcmp(mcu, "STM32")) {
printf("this %s to be a genuine STM32\n", fake ? "does not seem" : "seems");
}
#endif
}
static void command_uptime(void* argument)
{
(void)argument; // we won't use the argument
const uint32_t uptime = (rtc_get_counter_val() - time_start) / RTC_TICKS_SECOND; // get time from internal RTC
printf("uptime: %u.%02u:%02u:%02u\n", uptime / (24 * 60 * 60), (uptime / (60 * 60)) % 24, (uptime / 60) % 60, uptime % 60);
printf("device serial: %08x%08x%04x%04x\n", DESIG_UNIQUE_ID2, DESIG_UNIQUE_ID1, DESIG_UNIQUE_ID0 & 0xffff, DESIG_UNIQUE_ID0 >> 16); // not that the half-works are reversed in the first word
}
#if RTC_DATE_TIME