@@ -110,48 +110,8 @@ Samba::init()
110
110
if (_debug)
111
111
printf (" chipId=%#08x\n " , cid);
112
112
113
- uint8_t eproc = (cid >> 5 ) & 0x7 ;
114
- uint8_t arch = (cid >> 20 ) & 0xff ;
115
-
116
- // Check for ARM7TDMI processor
117
- if (eproc == 2 )
118
- {
119
- // Check for SAM7 architecture
120
- if (arch >= 0x70 && arch <= 0x76 )
121
- return true ;
122
- if (_debug)
123
- printf (" Unsupported ARM7TDMI architecture\n " );
124
- }
125
- // Check for Cortex-M3 processor
126
- else if (eproc == 3 )
127
- {
128
- // Check for SAM3 architecture
129
- if (arch >= 0x80 && arch <= 0x8a )
130
- return true ;
131
- if (arch >= 0x93 && arch <= 0x9a )
132
- return true ;
133
- if (_debug)
134
- printf (" Unsupported Cortex-M3 architecture\n " );
135
- }
136
- // Check for ARM920T processor
137
- else if (eproc == 4 )
138
- {
139
- // Check for SAM9XE architecture
140
- if (arch == 0x29 )
141
- return true ;
142
- if (_debug)
143
- printf (" Unsupported ARM920T architecture\n " );
144
- }
145
- // Check for supported M0+ processor
146
- else if (cid == 0x10010000 || cid == 0x10010100 || cid == 0x10010005 )
147
- {
148
- return true ;
149
- }
150
- else
151
- {
152
- if (_debug)
153
- printf (" Unsupported processor\n " );
154
- }
113
+ if (getChipArchitecture (cid) != Unsupported)
114
+ return true ;
155
115
156
116
return false ;
157
117
}
@@ -600,26 +560,34 @@ Samba::chipId()
600
560
void
601
561
Samba::reset (void )
602
562
{
563
+ uint32_t chipId;
564
+
603
565
printf (" CPU reset.\n " );
604
566
605
- uint32_t chipId = Samba::chipId ();
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
+ }
606
577
607
- switch (chipId)
578
+ switch (getChipArchitecture ( chipId) )
608
579
{
609
- // SAMD21G18 or SAMD21J18
610
- case 0x10010000 :
611
- case 0x10010100 :
612
- case 0x10010005 :
580
+ case SAMD20:
581
+ case SAMD21:
613
582
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0484c/index.html
614
583
writeWord (0xE000ED0C , 0x05FA0004 );
615
584
break ;
616
585
617
- // SAM3X8E
618
- case 0x285e0a60 :
586
+ case SAM3X:
619
587
writeWord (0x400E1A00 , 0xA500000D );
620
588
break ;
621
-
622
- default :
589
+
590
+ default :
623
591
printf (" Reset not supported for this CPU.\n " );
624
592
return ;
625
593
}
@@ -630,3 +598,86 @@ Samba::reset(void)
630
598
// sort out things before closing the port.
631
599
usleep (100000 );
632
600
}
601
+
602
+
603
+ Samba::ChipArchitecture
604
+ Samba::getChipArchitecture (uint32_t cid)
605
+ {
606
+ uint8_t eproc = (cid >> 5 ) & 0x7 ;
607
+ uint8_t arch = (cid >> 20 ) & 0xff ;
608
+
609
+ // Check for ARM7TDMI processor
610
+ if (eproc == 2 )
611
+ {
612
+ // Check for SAM7 architecture
613
+ if (arch == 0x70 )
614
+ return SAM7S;
615
+ else if (arch == 0x71 )
616
+ return SAM7XC;
617
+ else if (arch == 0x72 )
618
+ return SAM7SE;
619
+ else if (arch == 0x73 )
620
+ return SAM7L;
621
+ else if (arch == 0x75 )
622
+ return SAM7X;
623
+ else if (arch == 0x76 )
624
+ return SAM7SL;
625
+
626
+ if (_debug)
627
+ printf (" Unsupported ARM7TDMI architecture\n " );
628
+ }
629
+ // Check for Cortex-M3 processor
630
+ else if (eproc == 3 )
631
+ {
632
+ // Check for SAM3 architecture
633
+ if (arch >= 0x80 && arch <= 0x81 )
634
+ return SAM3U;
635
+ else if (arch == 0x83 )
636
+ return SAM3A;
637
+ else if (arch >= 0x84 && arch <= 0x86 )
638
+ return SAM3X;
639
+ else if (arch >= 0x88 && arch <= 0x8A )
640
+ return SAM3S;
641
+ else if (arch >= 0x93 && arch <= 0x95 )
642
+ return SAM3N;
643
+ else if (arch >= 0x98 && arch <= 0x9A )
644
+ return SAM3SD;
645
+
646
+ if (_debug)
647
+ printf (" Unsupported Cortex-M3 architecture\n " );
648
+ }
649
+ // Check for ARM920T processor
650
+ else if (eproc == 4 )
651
+ {
652
+ // Check for SAM9XE architecture
653
+ if (arch == 0x29 )
654
+ return SAM9XE;
655
+
656
+ if (_debug)
657
+ printf (" Unsupported ARM920T architecture\n " );
658
+ }
659
+ // Check for SAMD Cortex-M0+ processor
660
+ else if ((cid & 0xff800000 ) == 0x10000000 )
661
+ {
662
+ uint8_t series = (cid >> 16 ) & 0x3f ;
663
+
664
+ if (series == 0x00 )
665
+ {
666
+ return SAMD20;
667
+ }
668
+ else if (series == 0x01 )
669
+ {
670
+ return SAMD21;
671
+ }
672
+
673
+ if (_debug)
674
+ printf (" Unsupported Cortex-M0+ architecture\n " );
675
+ }
676
+ else
677
+ {
678
+ if (_debug)
679
+ printf (" Unsupported processor\n " );
680
+ }
681
+
682
+ return Unsupported;
683
+ }
0 commit comments