@@ -51,7 +51,7 @@ using namespace std;
51
51
52
52
#define min (a, b ) ((a) < (b) ? (a) : (b))
53
53
54
- Samba::Samba () : _debug(false ), _isUsb(false )
54
+ Samba::Samba () : _chipId( 0 ), _debug(false ), _isUsb(false )
55
55
{
56
56
}
57
57
63
63
Samba::init ()
64
64
{
65
65
uint8_t cmd[3 ];
66
- uint32_t cid;
67
66
68
67
_port->timeout (TIMEOUT_QUICK);
69
68
@@ -98,7 +97,7 @@ Samba::init()
98
97
// Read the chip ID
99
98
try
100
99
{
101
- cid = chipId ();
100
+ chipId ();
102
101
}
103
102
catch (SambaError)
104
103
{
@@ -108,9 +107,9 @@ Samba::init()
108
107
_port->timeout (TIMEOUT_NORMAL);
109
108
110
109
if (_debug)
111
- printf (" chipId=%#08x\n " , cid );
110
+ printf (" chipId=%#08x\n " , _chipId );
112
111
113
- if (getChipArchitecture (cid ) != Unsupported)
112
+ if (getChipArchitecture (_chipId ) != Unsupported)
114
113
return true ;
115
114
116
115
return false ;
@@ -530,13 +529,18 @@ Samba::version()
530
529
uint32_t
531
530
Samba::chipId ()
532
531
{
532
+ // use cached value if present
533
+ if (_chipId != 0 )
534
+ return _chipId;
535
+
533
536
// Read the ARM reset vector
534
537
uint32_t vector = readWord (0x0 );
535
538
536
539
// If the vector is a ARM7TDMI branch, then assume Atmel SAM7 registers
537
540
if ((vector & 0xff000000 ) == 0xea000000 )
538
541
{
539
- return readWord (0xfffff240 );
542
+ _chipId = readWord (0xfffff240 );
543
+ return _chipId;
540
544
}
541
545
542
546
// Else use the Atmel SAM3 or SAM4 or M0+ registers
@@ -547,35 +551,23 @@ Samba::chipId()
547
551
// Check if it is Cortex M0+
548
552
if (part_no == 0xC600 )
549
553
{
550
- return readWord (0x41002018 ); // DSU_DID register
554
+ _chipId = readWord (0x41002018 ); // DSU_DID register
555
+ return _chipId;
551
556
}
552
557
553
558
// Else assume M3 or M4
554
- uint32_t cid = readWord (0x400e0740 );
555
- if (cid == 0 )
556
- cid = readWord (0x400e0940 );
557
- return cid ;
559
+ _chipId = readWord (0x400e0740 );
560
+ if (_chipId == 0 )
561
+ _chipId = readWord (0x400e0940 );
562
+ return _chipId ;
558
563
}
559
564
560
565
void
561
566
Samba::reset (void )
562
567
{
563
- uint32_t chipId;
564
-
565
568
printf (" CPU reset.\n " );
566
569
567
- // Read the chip ID
568
- try
569
- {
570
- chipId = Samba::chipId ();
571
- }
572
- catch (SambaError)
573
- {
574
- printf (" Reset failed.\n " );
575
- return ;
576
- }
577
-
578
- switch (getChipArchitecture (chipId))
570
+ switch (getChipArchitecture (_chipId))
579
571
{
580
572
case SAMD20:
581
573
case SAMD21:
0 commit comments