Skip to content

Commit ce0ecb2

Browse files
committed
Applied some changes from commit f7a65bb
- Improved chip ID detection - Removed 'Chip erase', 'Fast write' and 'Fast verify' from device info - Device.cpp reset(void) function is now reset()
1 parent a4018c0 commit ce0ecb2

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

src/Device.cpp

+44-20
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,67 @@
3131
#include "EefcFlash.h"
3232
#include "NvmFlash.h"
3333

34+
void
35+
Device::readChipId(uint32_t& chipId, uint32_t& extChipId)
36+
{
37+
if ((chipId = _samba.readWord(0x400e0740)) != 0)
38+
{
39+
extChipId = _samba.readWord(0x400e0744);
40+
}
41+
else if ((chipId = _samba.readWord(0x400e0940)) != 0)
42+
{
43+
extChipId = _samba.readWord(0x400e0944);
44+
}
45+
}
46+
3447
void
3548
Device::create()
3649
{
3750
Flash* flashPtr;
3851
uint32_t chipId = 0;
52+
uint32_t cpuId = 0;
3953
uint32_t extChipId = 0;
4054
uint32_t deviceId = 0;
4155

4256
// Device identification must be performed carefully to avoid reading from
43-
// addresses that devices do not support.
57+
// addresses that devices do not support which will lock up the CPU
4458

4559
// All devices support addresss 0 as the ARM reset vector so if the vector is
4660
// a ARM7TDMI branch, then assume we have an Atmel SAM7/9 CHIPID register
4761
if ((_samba.readWord(0x0) & 0xff000000) == 0xea000000)
4862
{
4963
chipId = _samba.readWord(0xfffff240);
5064
}
51-
// Next try the ARM CPUID register since all Coretex-M devices support it.
52-
// If it identifies a Coretex M0+, then assume we have a SAMD device
53-
// that only supports the ARM device ID register
54-
else if ((_samba.readWord(0xe000ed00) & 0x0000fff0) == 0xC600)
55-
{
56-
deviceId = _samba.readWord(0x41002018);
57-
}
58-
// Assume we have a SAM3, SAM4 or SAME70 so check the CHIPID registers
59-
else if ((chipId = _samba.readWord(0x400e0740)) != 0)
60-
{
61-
extChipId = _samba.readWord(0x400e0744);
62-
}
63-
else if ((chipId = _samba.readWord(0x400e0940)) != 0)
64-
{
65-
extChipId = _samba.readWord(0x400e0944);
66-
}
67-
// Else we don't know what the device is
6865
else
6966
{
70-
throw DeviceUnsupportedError();
67+
// Next try the ARM CPUID register since all Cortex-M devices support it
68+
cpuId = _samba.readWord(0xe000ed00) & 0x0000fff0;
69+
70+
// Cortex-M0+
71+
if (cpuId == 0xC600)
72+
{
73+
// These should support the ARM device ID register
74+
deviceId = _samba.readWord(0x41002018);
75+
}
76+
// Cortex-M4
77+
else if (cpuId == 0xC240)
78+
{
79+
// SAM4 processors have a reset vector to the SAM-BA ROM
80+
if ((_samba.readWord(0x4) & 0xfff00000) == 0x800000)
81+
{
82+
readChipId(chipId, extChipId);
83+
}
84+
// Else we should have a device that supports the ARM device ID register
85+
else
86+
{
87+
deviceId = _samba.readWord(0x41002018);
88+
}
89+
}
90+
// For all other Cortex versions try the Atmel chip ID registers
91+
else
92+
{
93+
readChipId(chipId, extChipId);
94+
}
7195
}
7296

7397
// Instantiate the proper flash for the device
@@ -486,7 +510,7 @@ Device::create()
486510
}
487511

488512
void
489-
Device::reset(void)
513+
Device::reset()
490514
{
491515
try
492516
{

src/Device.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ class Device
8484

8585
FlashPtr& getFlash() { return _flash; }
8686

87-
void reset(void);
87+
void reset();
8888

8989
private:
9090
Samba& _samba;
9191
std::unique_ptr<Flash> _flash;
9292
Family _family;
93+
94+
void readChipId(uint32_t& chipId, uint32_t& extChipId);
9395
};
9496

9597
#endif // _DEVICE_H

src/Flasher.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ FlasherInfo::print()
6868
printf("BOD : %s\n", bod ? "true" : "false");
6969
if (canBor)
7070
printf("BOR : %s\n", bor ? "true" : "false");
71-
72-
if (canChipErase)
73-
printf("Chip Erase : true\n");
74-
if (canWriteBuffer)
75-
printf("Fast Write : true\n");
76-
if (canChecksumBuffer)
77-
printf("Fast Verify : true\n");
7871
}
7972

8073
void

src/Samba.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Samba
7474

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

77-
void reset(void);
77+
void reset();
7878

7979
// Extended SAM-BA functions
8080
bool canChipErase() { return _canChipErase; }

src/bossac.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ main(int argc, char* argv[])
442442
{
443443
uint32_t pageErrors;
444444
uint32_t totalErrors;
445-
445+
446446
timer_start();
447447
if (!flasher.verify(argv[args], pageErrors, totalErrors, config.offsetArg))
448448
{

0 commit comments

Comments
 (0)