Skip to content

Commit

Permalink
Applied some changes from commit f7a65bb
Browse files Browse the repository at this point in the history
- Improved chip ID detection
- Removed 'Chip erase', 'Fast write' and 'Fast verify' from device info
- Device.cpp reset(void) function is now reset()
  • Loading branch information
LumitoLuma committed Jun 27, 2021
1 parent a4018c0 commit ce0ecb2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
64 changes: 44 additions & 20 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,67 @@
#include "EefcFlash.h"
#include "NvmFlash.h"

void
Device::readChipId(uint32_t& chipId, uint32_t& extChipId)
{
if ((chipId = _samba.readWord(0x400e0740)) != 0)
{
extChipId = _samba.readWord(0x400e0744);
}
else if ((chipId = _samba.readWord(0x400e0940)) != 0)
{
extChipId = _samba.readWord(0x400e0944);
}
}

void
Device::create()
{
Flash* flashPtr;
uint32_t chipId = 0;
uint32_t cpuId = 0;
uint32_t extChipId = 0;
uint32_t deviceId = 0;

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

// All devices support addresss 0 as the ARM reset vector so if the vector is
// a ARM7TDMI branch, then assume we have an Atmel SAM7/9 CHIPID register
if ((_samba.readWord(0x0) & 0xff000000) == 0xea000000)
{
chipId = _samba.readWord(0xfffff240);
}
// Next try the ARM CPUID register since all Coretex-M devices support it.
// If it identifies a Coretex M0+, then assume we have a SAMD device
// that only supports the ARM device ID register
else if ((_samba.readWord(0xe000ed00) & 0x0000fff0) == 0xC600)
{
deviceId = _samba.readWord(0x41002018);
}
// Assume we have a SAM3, SAM4 or SAME70 so check the CHIPID registers
else if ((chipId = _samba.readWord(0x400e0740)) != 0)
{
extChipId = _samba.readWord(0x400e0744);
}
else if ((chipId = _samba.readWord(0x400e0940)) != 0)
{
extChipId = _samba.readWord(0x400e0944);
}
// Else we don't know what the device is
else
{
throw DeviceUnsupportedError();
// Next try the ARM CPUID register since all Cortex-M devices support it
cpuId = _samba.readWord(0xe000ed00) & 0x0000fff0;

// Cortex-M0+
if (cpuId == 0xC600)
{
// These should support the ARM device ID register
deviceId = _samba.readWord(0x41002018);
}
// Cortex-M4
else if (cpuId == 0xC240)
{
// SAM4 processors have a reset vector to the SAM-BA ROM
if ((_samba.readWord(0x4) & 0xfff00000) == 0x800000)
{
readChipId(chipId, extChipId);
}
// Else we should have a device that supports the ARM device ID register
else
{
deviceId = _samba.readWord(0x41002018);
}
}
// For all other Cortex versions try the Atmel chip ID registers
else
{
readChipId(chipId, extChipId);
}
}

// Instantiate the proper flash for the device
Expand Down Expand Up @@ -486,7 +510,7 @@ Device::create()
}

void
Device::reset(void)
Device::reset()
{
try
{
Expand Down
4 changes: 3 additions & 1 deletion src/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ class Device

FlashPtr& getFlash() { return _flash; }

void reset(void);
void reset();

private:
Samba& _samba;
std::unique_ptr<Flash> _flash;
Family _family;

void readChipId(uint32_t& chipId, uint32_t& extChipId);
};

#endif // _DEVICE_H
Expand Down
7 changes: 0 additions & 7 deletions src/Flasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ FlasherInfo::print()
printf("BOD : %s\n", bod ? "true" : "false");
if (canBor)
printf("BOR : %s\n", bor ? "true" : "false");

if (canChipErase)
printf("Chip Erase : true\n");
if (canWriteBuffer)
printf("Fast Write : true\n");
if (canChecksumBuffer)
printf("Fast Verify : true\n");
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/Samba.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Samba

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

void reset(void);
void reset();

// Extended SAM-BA functions
bool canChipErase() { return _canChipErase; }
Expand Down
2 changes: 1 addition & 1 deletion src/bossac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ main(int argc, char* argv[])
{
uint32_t pageErrors;
uint32_t totalErrors;

timer_start();
if (!flasher.verify(argv[args], pageErrors, totalErrors, config.offsetArg))
{
Expand Down

0 comments on commit ce0ecb2

Please sign in to comment.