Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for SAM C21 J18A #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/D2xNvmFlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
///////////////////////////////////////////////////////////////////////////////

#include <unistd.h>
#include "D2xNvmFlash.h"

// CMDEX field should be 0xA5 to allow execution of any command.
Expand Down Expand Up @@ -100,7 +101,7 @@ D2xNvmFlash::erase(uint32_t offset, uint32_t size)
// Issue erase command
uint32_t wordAddr = (eraseNum * eraseSize) / 2;
writeReg(NVM_REG_ADDR, wordAddr);
command(NVM_CMD_ER);
command(NVM_CMD_ER, 6000);
}
}

Expand Down Expand Up @@ -227,7 +228,7 @@ D2xNvmFlash::writeOptions()

// Erase user row
writeReg(NVM_REG_ADDR, NVM_UR_ADDR / 2);
command(NVM_CMD_EAR);
command(NVM_CMD_EAR, 6000);

// Write user row in page chunks
for (uint32_t offset = 0; offset < NVM_UR_SIZE; offset += _size)
Expand All @@ -247,7 +248,7 @@ D2xNvmFlash::writeOptions()

// Write the page
writeReg(NVM_REG_ADDR, (NVM_UR_ADDR + offset) / 2);
command(NVM_CMD_WAP);
command(NVM_CMD_WAP, 2500);
}
}

Expand Down Expand Up @@ -286,7 +287,7 @@ D2xNvmFlash::writePage(uint32_t page)
_wordCopy.runv();

writeReg(NVM_REG_ADDR, addr / 2);
command(NVM_CMD_WP);
command(NVM_CMD_WP,2500);
}

void
Expand Down Expand Up @@ -319,12 +320,13 @@ D2xNvmFlash::writeReg(uint8_t reg, uint32_t value)
}

void
D2xNvmFlash::command(uint8_t cmd)
D2xNvmFlash::command(uint8_t cmd, uint16_t wait)
{
waitReady();

writeReg(NVM_REG_CTRLA, CMDEX_KEY | cmd);

usleep(wait);
waitReady();

if (readReg(NVM_REG_INTFLAG) & 0x2)
Expand Down
2 changes: 1 addition & 1 deletion src/D2xNvmFlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class D2xNvmFlash : public Flash
void writeReg(uint8_t reg, uint32_t value);

void waitReady();
void command(uint8_t cmd);
void command(uint8_t cmd, uint16_t wait = 1);
void erase(uint32_t offset, uint32_t size);
void readUserRow(std::unique_ptr<uint8_t[]>& userRow);
};
Expand Down
9 changes: 9 additions & 0 deletions src/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ Device::create()
case 0:
switch (deviceId & 0xffff00ff)
{
//
// SAMC21
//
case 0x11010000: // J18A
_family = FAMILY_SAMC21;
flashPtr = new D2xNvmFlash(_samba, "ATSAMC21x18", 4096, 64, 0x20004000, 0x20008000) ;
break;

//
// SAMD21
//
Expand Down Expand Up @@ -638,6 +646,7 @@ Device::reset()
{
switch (_family)
{
case FAMILY_SAMC21:
case FAMILY_SAMD21:
case FAMILY_SAMR21:
case FAMILY_SAML21:
Expand Down
1 change: 1 addition & 0 deletions src/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Device

FAMILY_SAM9XE,

FAMILY_SAMC21,
FAMILY_SAMD21,
FAMILY_SAMR21,
FAMILY_SAML21,
Expand Down