Skip to content

Commit

Permalink
support for sam4e with extended chip id
Browse files Browse the repository at this point in the history
  • Loading branch information
tonokip committed Apr 6, 2017
1 parent c5c8991 commit 5231a16
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ INSTALLDIR=install
# Determine OS
#
OS:=$(shell uname -s | cut -c -7)
OS=MINGW32

#
# Windows rules
#
ifeq ($(OS),MINGW32)
EXE=.exe
COMMON_SRCS+=WinSerialPort.cpp WinPortFactory.cpp
COMMON_LDFLAGS=-Wl,--enable-auto-import -static -static-libstdc++ -static-libgcc
COMMON_LDFLAGS=-Wl,--enable-auto-import -static -static-libstdc++ -static-libgcc -Lc:\mingw32\opt\lib
COMMON_LIBS=-ltermcap -Wl,--as-needed -lsetupapi
BOSSA_RC=BossaRes.rc
WIXDIR="C:\Program Files (x86)\WiX Toolset v3.10\bin"
Expand Down
4 changes: 2 additions & 2 deletions src/EefcFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ EefcFlash::EefcFlash(Samba& samba,
{
assert(planes == 1 || planes == 2);
assert(pages <= 2048);
assert(lockRegions <= 32);
assert(lockRegions <= 128);

// SAM3 Errata (FWS must be 6)
_samba.writeWord(EEFC0_FMR, 0x6 << 8);
Expand Down Expand Up @@ -304,7 +304,7 @@ EefcFlash::waitFSR()
}
if (fsr0 & fsr1 & 0x1)
break;
usleep(100);
usleep(100000);
}
if (tries > 500)
throw FlashCmdError();
Expand Down
22 changes: 21 additions & 1 deletion src/FlashFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FlashFactory::~FlashFactory()
}

Flash::Ptr
FlashFactory::create(Samba& samba, uint32_t chipId)
FlashFactory::create(Samba& samba, uint32_t chipId, uint32_t extID)
{
Flash* flash = NULL;

Expand Down Expand Up @@ -248,6 +248,26 @@ FlashFactory::create(Samba& samba, uint32_t chipId)
case 0x1001001c:
flash = new NvmFlash( samba, "ATSAMR21E18A", 0x2000, 4096, 64, 1, 16, 0x20004000, 0x20008000, 0x41004000, true ) ;
break;

// SAM4E
case 0xa3cc0ce0 :
switch(extID)
{
case 0x00120200:
flash = new EefcFlash(samba, "ATSAM4E16E", 0x00400000, 2048, 512, 1, 128, 0x20001000, 0x20001000, 0x400e0a00, false);
//flash = new EefcFlash(samba, "ATSAM4E16E", 0x00404000, 2016, 512, 1, 128, 0x20001000, 0x20001000, 0x400e0a00, false);
break;
case 0x00120208:
flash = new EefcFlash(samba, "ATSAM4E8E", 0x00400000, 1024, 512, 1, 128, 0x20001000, 0x20001000, 0x400e0a00, false);
break;
case 0x00120201:
flash = new EefcFlash(samba, "ATSAM4E16C", 0x00400000, 2048, 512, 1, 128, 0x20001000, 0x20001000, 0x400e0a00, false);
break;
case 0x00120209:
flash = new EefcFlash(samba, "ATSAM4E8C", 0x00400000, 1024, 512, 1, 128, 0x20001000, 0x20001000, 0x400e0a00, false);
break;
}
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/FlashFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FlashFactory
FlashFactory();
virtual ~FlashFactory();

Flash::Ptr create(Samba& samba, uint32_t chipId);
Flash::Ptr create(Samba& samba, uint32_t chipId, uint32_t extID );
};

#endif // _FLASHFACTORY_H
32 changes: 32 additions & 0 deletions src/Samba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ Samba::init()
// Check for SAM4 architecture
if (arch >= 0x88 && arch <= 0x8a)
return true;

// SAM4E Architecture Identifier
if( arch == 0x3c )
return true;

if (_debug)
printf("Unsupported Cortex-M4 architecture\n");
}
Expand Down Expand Up @@ -654,6 +659,28 @@ Samba::chipId()
return cid;
}

uint32_t
Samba::chipExtId(uint32_t chipId)
{
uint32_t chipExtId = 0;

// are more lookup tables really needed?
// maybe I should just check the CID Extension Flag.
switch(chipId)
{
//SAM4E
case 0xa3cc0ce0:
chipExtId = readWord(0x400E0744);
break;
}

if(chipExtId)
printf( "CHIP ID Extension 0x%08x found\n", chipExtId ) ;

return chipExtId;
}


void
Samba::reset(void)
{
Expand All @@ -676,6 +703,11 @@ Samba::reset(void)
writeWord(0x400E1A00, 0xA500000D);
break;

// SAM4E
case 0xa3cc0ce0:
writeWord(0x400E1800,0xA500000D); // SAM4E Reset peripherals, processor and assert NRST
break;

default:
printf("Reset not supported for this CPU.\n");
return;
Expand Down
1 change: 1 addition & 0 deletions src/Samba.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Samba
std::string version();

uint32_t chipId();
uint32_t chipExtId(uint32_t chipId);

void setDebug(bool debug) { _debug = debug; }

Expand Down
3 changes: 2 additions & 1 deletion src/bossac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,9 @@ main(int argc, char* argv[])

uint32_t chipId = samba.chipId();
printf( "SAM-BA device 0x%08x found\n", chipId ) ;
uint32_t chipExtId = samba.chipExtId(chipId);

Flash::Ptr flash = flashFactory.create(samba, chipId);
Flash::Ptr flash = flashFactory.create(samba, chipId, chipExtId);
if (flash.get() == NULL)
{
fprintf(stderr, "Flash for chip ID %08x is not supported\n", chipId);
Expand Down

0 comments on commit 5231a16

Please sign in to comment.