Skip to content

Commit f7a65bb

Browse files
committed
Added support for the SAMD51. Rewrote most of the D21 support since the
existing code was not working. Refactored the flash options to defer writing them until an explicit write is called which avoids writing the same user page over and over for the D21 and D51.
1 parent 0f1c73d commit f7a65bb

24 files changed

+1243
-801
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ Supported Device Families
2222
* SAM4E
2323
* SAM4S
2424
* SAMD21
25+
* SAMD51
2526
* SAM3X\*
2627
* SAM3A\*
2728
* SAM7L\*
2829
* SAM9XE\*
30+
* SAME51\*
31+
* SAME52\*
32+
* SAME53\*
33+
* SAME54\*
2934
* SAME70\*
3035

3136
\* Device families which are not tested for each release and could stop working.

src/BossaInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ BossaInfo::BossaInfo(wxWindow* parent) : InfoDialog(parent)
5454
_bodCheckBox->SetValue(flash->getBod());
5555
_borCheckBox->SetValue(flash->getBor());
5656

57-
uint32_t lockRegions = flash->lockRegions();
57+
std::vector<bool> lockRegions = flash->getLockRegions();
5858
bool hasLockRegion = false;
59-
for (uint32_t i = 0; i < lockRegions; i++)
59+
for (uint32_t i = 0; i < lockRegions.size(); i++)
6060
{
61-
if (flash->getLockRegion(i))
61+
if (lockRegions[i])
6262
{
6363
_lockTextCtrl->AppendText(wxString::Format(wxT("%s%d"), hasLockRegion ? "," : "", i));
6464
hasLockRegion = true;

src/BossaThread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ WriteThread::Entry()
140140
if (flash->canBor())
141141
flash->setBor(_bor);
142142
if (_lock)
143-
flash->lockAll();
143+
flash->setLockRegions(std::vector<bool>(flash->lockRegions(), true));
144144
if (_security)
145145
flash->setSecurity();
146+
flash->writeOptions();
146147
}
147148
catch(exception& e)
148149
{

src/BossaWindow.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Device.h"
3535

3636
#include <string>
37+
#include <algorithm>
3738

3839

3940
using namespace std;
@@ -333,12 +334,14 @@ BossaWindow::OnWrite(wxCommandEvent& event)
333334

334335
try
335336
{
336-
if (flash->isLocked())
337+
std::vector<bool> regions = flash->getLockRegions();
338+
339+
if (std::find(regions.begin(), regions.end(), true) != regions.end())
337340
{
338341
if (!Question(wxT("The flash is currently locked. Do you want to unlock it and proceed with the write?")))
339342
return;
340343

341-
flash->unlockAll();
344+
flash->setLockRegions(std::vector<bool>(regions.size(), false));
342345
}
343346
}
344347
catch(exception& e)

src/Command.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
///////////////////////////////////////////////////////////////////////////////
2929
#define __STDC_LIMIT_MACROS
3030
#include <stdio.h>
31-
#include <stdlib.h>
3231
#include <stdarg.h>
3332
#include <errno.h>
3433
#include <string.h>
@@ -416,30 +415,25 @@ CommandDump::invoke(char* argv[], int argc)
416415
{
417416
uint32_t addr;
418417
uint32_t count;
419-
uint8_t* buf;
420418

421419
if (!argNum(argc, 3) ||
422420
!argUint32(argv[1], &addr) ||
423421
!argUint32(argv[2], &count) ||
424422
!connected())
425423
return;
426424

427-
buf = (uint8_t*) malloc(count);
428-
if (!buf)
429-
return;
425+
std::unique_ptr<uint8_t[]> buf(new uint8_t[count]);
430426

431427
try
432428
{
433-
_samba.read(addr, buf, count);
429+
_samba.read(addr, buf.get(), count);
434430
}
435431
catch (...)
436432
{
437-
free(buf);
438433
throw;
439434
}
440435

441-
hexdump(addr, buf, count);
442-
free(buf);
436+
hexdump(addr, buf.get(), count);
443437
}
444438

445439
CommandErase::CommandErase() :
@@ -580,7 +574,7 @@ CommandLock::invoke(char* argv[], int argc)
580574
bits += argv[argn];
581575

582576
_flasher.lock(bits, true);
583-
printf("Locked regions %s", bits.c_str());
577+
printf("Locked regions %s\n", bits.c_str());
584578
}
585579

586580
CommandMrb::CommandMrb() :
@@ -1235,3 +1229,15 @@ CommandReset::invoke(char* argv[], int argc)
12351229
_device.reset();
12361230
}
12371231

1232+
CommandOptions::CommandOptions() :
1233+
Command("options",
1234+
"Write options to flash.",
1235+
"options\n")
1236+
{}
1237+
1238+
void
1239+
CommandOptions::invoke(char* argv[], int argc)
1240+
{
1241+
_flash->writeOptions();
1242+
}
1243+

src/Command.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,11 @@ class CommandReset : public Command
276276
virtual void invoke(char* argv[], int argc);
277277
};
278278

279+
class CommandOptions : public Command
280+
{
281+
public:
282+
CommandOptions();
283+
virtual void invoke(char* argv[], int argc);
284+
};
285+
279286
#endif // _COMMAND_H

0 commit comments

Comments
 (0)