Skip to content

Commit ed8802c

Browse files
committed
Removed ChipInfo structure
1 parent 82fa4c3 commit ed8802c

File tree

7 files changed

+38
-96
lines changed

7 files changed

+38
-96
lines changed

src/BossaWindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ BossaWindow::CreateFlash()
262262
Samba& samba = wxGetApp().samba;
263263
Flash::Ptr& flash = wxGetApp().flash;
264264
FlashFactory flashFactory;
265-
ChipInfo info;
265+
uint32_t chipId;
266266

267267
try
268268
{
269-
info = samba.chipInfo();
269+
chipId = samba.chipId();
270270
}
271271
catch (exception& e)
272272
{
@@ -275,11 +275,11 @@ BossaWindow::CreateFlash()
275275
return;
276276
}
277277

278-
flash = flashFactory.create(samba, info);
278+
flash = flashFactory.create(samba, chipId);
279279
if (flash.get() == NULL)
280280
{
281281
Disconnected();
282-
Error(wxString::Format(wxT("Chip ID 0x%08x is not supported"), info.chipId));
282+
Error(wxString::Format(wxT("Chip ID 0x%08x is not supported"), chipId));
283283
return;
284284
}
285285

src/Command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ Command::flashable()
162162
bool
163163
Command::createFlash()
164164
{
165-
ChipInfo info = _samba.chipInfo();
165+
uint32_t chipId = _samba.chipId();
166166

167-
_flash = _flashFactory.create(_samba, info);
167+
_flash = _flashFactory.create(_samba, chipId);
168168
if (_flash.get() == NULL)
169169
{
170-
printf("Flash for chip ID %08x is not supported\n", info.chipId);
170+
printf("Flash for chip ID %08x is not supported\n", chipId);
171171
return false;
172172
}
173173

src/FlashFactory.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,24 @@ FlashFactory::~FlashFactory()
4141
}
4242

4343
Flash::Ptr
44-
FlashFactory::create(Samba& samba, ChipInfo info)
44+
FlashFactory::create(Samba& samba, uint32_t chipId)
4545
{
4646
Flash* flash;
47-
uint32_t chipId = info.chipId;
4847

49-
///CORTEX M0+
50-
if(info.arch == M0_PLUS)
48+
switch (chipId)
5149
{
52-
switch(chipId)
53-
{
54-
55-
//SAMD21J18A
56-
case 0x10010000:
57-
flash = new NvmFlash(samba, "ATSAMD21J18A", 0x000000, 4096, 64, 1, 16, 0x804000, 0x20008000, 0x41004000 /*Base address for the NVMCTRL module */, true);
50+
//
51+
// SAMD21
52+
//
53+
case 0x10010000:
54+
flash = new NvmFlash(samba, "ATSAMD21J18A", 0x000000, 4096, 64, 1, 16, 0x804000, 0x20008000, 0x41004000, true);
55+
// 0x41004000 == Base address for the NVMCTRL module
5856
break;
5957

60-
case 0x10010005:
61-
flash = new NvmFlash(samba, "ATSAMD21G18A", 0x000000, 4096, 64, 1, 16, 0x804000, 0x20008000, 0x41004000, true);
58+
case 0x10010005:
59+
flash = new NvmFlash(samba, "ATSAMD21G18A", 0x000000, 4096, 64, 1, 16, 0x804000, 0x20008000, 0x41004000, true);
6260
break;
63-
}
6461

65-
return Flash::Ptr(flash);
66-
}
67-
68-
switch (chipId & 0x7fffffe0)
69-
{
7062
//
7163
// SAM7SE
7264
//

src/FlashFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FlashFactory
4040
FlashFactory();
4141
virtual ~FlashFactory();
4242

43-
Flash::Ptr create(Samba& samba, ChipInfo info);
43+
Flash::Ptr create(Samba& samba, uint32_t chipId);
4444
};
4545

4646
#endif // _FLASHFACTORY_H

src/Samba.cpp

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ Samba::init()
9696
_port->read(cmd, 2);
9797

9898
// Read the chip ID
99-
ChipInfo info;
10099
try
101100
{
102-
info = chipInfo();
103-
cid = info.chipId;
101+
cid = chipId();
104102
}
105103
catch (SambaError)
106104
{
@@ -112,18 +110,6 @@ Samba::init()
112110
if (_debug)
113111
printf("chipId=%#08x\n", cid);
114112

115-
//Check for M0+ processors.
116-
if(info.arch == M0_PLUS)
117-
{
118-
int arch = -1;
119-
arch = cid >> ((sizeof(int)*8) - 4); //see the 4 bits from MSB
120-
if(arch == 1)
121-
return true;
122-
if(_debug)
123-
printf("Unsupported M0+ architecture\n");
124-
}
125-
126-
127113
uint8_t eproc = (cid >> 5) & 0x7;
128114
uint8_t arch = (cid >> 20) & 0xff;
129115

@@ -579,50 +565,35 @@ Samba::version()
579565
uint32_t
580566
Samba::chipId()
581567
{
582-
ChipInfo info = chipInfo();
583-
return info.chipId;
584-
}
585-
586-
ChipInfo
587-
Samba::chipInfo()
588-
{
589-
uint32_t cid;
590568
uint32_t vector;
591-
ChipInfo info;
569+
uint32_t cid;
592570

593571
// Read the ARM reset vector
594572
vector = readWord(0x0);
595573

596574
// If the vector is a ARM7TDMI branch, then assume Atmel SAM7 registers
597575
if ((vector & 0xff000000) == 0xea000000)
598576
{
599-
info.chipId = readWord(0xfffff240);
600-
info.arch = ARM7TDMI;
577+
cid = readWord(0xfffff240);
601578
}
602579
// Else use the Atmel SAM3 or SAM4 or M0+ registers
603580
else
604581
{
605-
//Check if it is Cortex M0+
606-
cid = readWord(0x41002018); //This is DSU_DID register
607-
if(cid !=0)
608-
{
609-
//M0+ device cid will be 0x10010000.
610-
info.chipId = cid;
611-
info.arch = M0_PLUS;
612-
}
613-
else
614-
{
615-
//M3 or M4
616-
cid = readWord(0x400e0740);
617-
if (cid == 0)
618-
cid = readWord(0x400e0940);
619-
620-
info.chipId = cid;
621-
info.arch = M3_M4;
622-
}
582+
// Check if it is Cortex M0+
583+
cid = readWord(0x41002018); // This is DSU_DID register
584+
if (cid != 0)
585+
{
586+
// M0+ device cid will be 0x10010000.
587+
}
588+
else
589+
{
590+
// M3 or M4
591+
cid = readWord(0x400e0740);
592+
if (cid == 0)
593+
cid = readWord(0x400e0940);
594+
}
623595
}
624-
return info;
625-
596+
return cid;
626597
}
627598

628599
void

src/Samba.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@
3737

3838
#include "SerialPort.h"
3939

40-
41-
42-
43-
enum CHIP_ARCH
44-
{
45-
M0_PLUS,
46-
M3_M4,
47-
ARM7TDMI,
48-
ARM9
49-
};
50-
51-
52-
typedef struct
53-
{
54-
uint32_t chipId;
55-
CHIP_ARCH arch;
56-
}ChipInfo;
57-
5840
class SambaError : public std::exception
5941
{
6042
public:
@@ -87,8 +69,6 @@ class Samba
8769

8870
uint32_t chipId();
8971

90-
ChipInfo chipInfo();
91-
9272
void setDebug(bool debug) { _debug = debug; }
9373

9474
const SerialPort& getSerialPort() { return *_port; }

src/bossac.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,11 @@ main(int argc, char* argv[])
321321
printf("Device found on %s\n", port.c_str());
322322
}
323323

324-
325-
ChipInfo info = samba.chipInfo();
326-
Flash::Ptr flash = flashFactory.create(samba, info);
324+
uint32_t chipId = samba.chipId();
325+
Flash::Ptr flash = flashFactory.create(samba, chipId);
327326
if (flash.get() == NULL)
328327
{
329-
fprintf(stderr, "Flash for chip ID %08x is not supported\n", info.chipId);
328+
fprintf(stderr, "Flash for chip ID %08x is not supported\n", chipId);
330329
return 1;
331330
}
332331

0 commit comments

Comments
 (0)