因为需要自动适配芯片进行系统配置,所以我们有必要通过读取一些系统寄存器来获取必要信息。
我们的代码需要兼容STM32F1/GD32F1/STM32F0/STM32F4
代码如下:
#ifdef STM32F0XX void* p = (void*)0x1FFFF7AC; #else void* p = (void*)0x1FFFF7E8; #endif memcpy(ID, p, ArrayLength(ID)); CPUID = SCB->CPUID; uint MCUID = DBGMCU->IDCODE; // MCU编码。低字设备版本,高字子版本 RevID = MCUID >> 16; DevID = MCUID & 0x0FFF; _Index = 0; #ifdef STM32F0XX FlashSize = *(__IO ushort *)(0x1FFFF7CC); // 容量 #else FlashSize = *(__IO ushort *)(0x1FFFF7E0); // 容量 #endif
各常见芯片信息如下:
STM32F030C8T6
SmartOS STM32F030C8 48MHz Flash:64k RAM:8k DevID:0x0440 RevID:0x2000 CPUID:0x410CC200 ARM ARMv6-M Cortex-M0 R0p0 ChipID:55-00-3E-00-04-57-32-4D-39-35-34-20 Heap :(0x200009a0, 0x200011a0) = 0x800 Stack:(0x200011a0, 0x20002000) = 0xe60
GD32F130C8T6
SmartOS GD32F130C8 48MHz Flash:64k RAM:8k DevID:0x0410 RevID:0x1303 CPUID:0x412FC231 ARM ARMv7-M Cortex-M3 R1p2 ChipID:26-49-31-39-31-33-30-32-32-32-33-32 &I1913022232 Heap :(0x200009a0, 0x200011a0) = 0x800 Stack:(0x200011a0, 0x20002000) = 0xe60
STM32F051C8T6
SmartOS STM32F030C8 48MHz Flash:64k RAM:8k DevID:0x0440 RevID:0x2000 CPUID:0x410CC200 ARM ARMv6-M Cortex-M0 R0p0 ChipID:22-00-21-00-11-57-36-41-36-33-32-20 Heap :(0x200009a0, 0x200011a0) = 0x800 Stack:(0x200011a0, 0x20002000) = 0xe60
GD32F150C8T6
SmartOS GD32F150C8 72MHz Flash:64k RAM:8k DevID:0x0410 RevID:0x1303 CPUID:0x412FC231 ARM ARMv7-M Cortex-M3 R1p2 ChipID:8F-14-31-39-31-33-30-32-32-32-33-32 8F141913022232 Heap :(0x20000678, 0x20000e78) = 0x800 (2k) Stack:(0x20000e78, 0x20002000) = 0x1188 (4k)
STM32F103VET6
SmartOS STM32F103VE 72MHz Flash:512k RAM:64k DevID:0x0414 RevID:0x1001 CPUID:0x411FC231 ARM ARMv7-M Cortex-M3 R1p1 ChipID:38-FF-D4-FB-31-4E-36-30-36-66-01-43 Heap :(0x20000a30, 0x20004a30) = 0x4000 Stack:(0x20004a30, 0x20010000) = 0xb5d0
GD32F103VET6
SmartOS GD32F103VE 120MHz Flash:512k RAM:64k DevID:0x0414 RevID:0x1309 CPUID:0x412FC231 ARM ARMv7-M Cortex-M3 R1p2 ChipID:46-86-31-36-38-37-30-31-01-02-03-04 F�168701