forked from mean00/DSO_STM32Duino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuID.cpp
124 lines (117 loc) · 2.27 KB
/
cpuID.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "Arduino.h"
#include "MapleFreeRTOS1000_pp.h"
#include "cpuID.h"
#include "scb.h"
static uint32_t family , designer;
uint32_t _cpuId=0;
static int _flashSize=0;
static int _ramSize=0;
static MCU_IDENTIFICATION _chipId;
/**
*
*/
void cpuID::identify()
{
struct scb_reg_map *scb=SCB_BASE;
_cpuId=scb->CPUID;
// GD32: 41 2 f c23 1
// Implementer 41 : ARM
// VARIANT 2
// Architecture C -> ARM V6
// Partno : 0xC23 => Cortex M3
// Rev=1
// GD32F3
// 0x41 0 f c24 1
// ARM
// variant 0
// C24 cortex m4
// Rev 1
// STM32F1 : 0x41 1 f c23 1
// Variant 1
// Architecture C -> ARM V6
// Partno : C23 => Cortex M3
// Rev=1
// 2nd part ram & flash size
uint32_t density=*(uint32_t *)0x1FFFF7E0;
int ramSize=density>>16;
_flashSize=density & 0xffff;
if(ramSize!=0xffff) // GD
{
switch(_flashSize)
{
case 128: _chipId=MCU_GD32_128K;break;
case 64: _chipId=MCU_GD32_64K;break;
case 256 : _chipId=MCU_GD32F3_256K;break;
default:
xAssert(0);
break;
}
_ramSize=ramSize;
}else // STM32
{
if(_flashSize==128)
_chipId=MCU_STM32_128K;
else if(_flashSize == 64)
_chipId=MCU_STM32_64K;
else
xAssert(0);
_ramSize=20;
}
}
/**
*
* @return
*/
uint32_t cpuID::getFamily()
{
return family;
}
/**
*
* @return
*/
uint32_t cpuID::getDesigner()
{
return designer;
}
/**
*
* @return
*/
int cpuID::getFlashSize()
{
return _flashSize;
}
/**
*
* @return
*/
int cpuID::getRamSize()
{
return _ramSize;
}
/**
*
* @return
*/
MCU_IDENTIFICATION cpuID::getId()
{
return _chipId;
}
/**
*
* @return
*/
const char *cpuID::getIdAsString()
{
switch(_chipId)
{
case MCU_STM32_64K: return "STM32F1/64kB"; break;
case MCU_STM32_128K:return "STM32F1/128kB";break;
case MCU_GD32_64K:return "GD32F1/64kB";break;
case MCU_GD32_128K:return "GD32F1/128kB";break;
case MCU_GD32F3_256K: return "GD32F3/256kB";break;
default:break;
}
xAssert(0);
}