diff --git a/Makefile b/Makefile index 30f149d5..6002acd1 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ INSTALLDIR=install # Determine OS # OS:=$(shell uname -s | cut -c -7) +OS=MINGW32 # # Windows rules @@ -36,7 +37,7 @@ OS:=$(shell uname -s | cut -c -7) 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" diff --git a/src/EefcFlash.cpp b/src/EefcFlash.cpp index 87bc6354..58b1124d 100644 --- a/src/EefcFlash.cpp +++ b/src/EefcFlash.cpp @@ -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); @@ -304,7 +304,7 @@ EefcFlash::waitFSR() } if (fsr0 & fsr1 & 0x1) break; - usleep(100); + usleep(100000); } if (tries > 500) throw FlashCmdError(); diff --git a/src/FlashFactory.cpp b/src/FlashFactory.cpp index 535c5c28..f9610c22 100644 --- a/src/FlashFactory.cpp +++ b/src/FlashFactory.cpp @@ -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; @@ -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; } } diff --git a/src/FlashFactory.h b/src/FlashFactory.h index 0e720f3c..35491927 100644 --- a/src/FlashFactory.h +++ b/src/FlashFactory.h @@ -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 diff --git a/src/Samba.cpp b/src/Samba.cpp index d2c43007..e3c88712 100644 --- a/src/Samba.cpp +++ b/src/Samba.cpp @@ -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"); } @@ -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) { @@ -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; diff --git a/src/Samba.h b/src/Samba.h index f250e8e0..50393fa2 100644 --- a/src/Samba.h +++ b/src/Samba.h @@ -68,6 +68,7 @@ class Samba std::string version(); uint32_t chipId(); + uint32_t chipExtId(uint32_t chipId); void setDebug(bool debug) { _debug = debug; } diff --git a/src/bossac.cpp b/src/bossac.cpp index dcfa1ef0..b89c5c50 100644 --- a/src/bossac.cpp +++ b/src/bossac.cpp @@ -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);