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

Fix EraseAsync #274

Merged
merged 1 commit into from
Nov 24, 2020
Merged
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
44 changes: 22 additions & 22 deletions nanoFramework.Tools.DebugLibrary.Shared/NFDevice/NanoDeviceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance
}

// check if the device is responsive
PingConnectionType isPresent = Ping();
if (Ping() == PingConnectionType.NoConnection)
{
// it's not, try reconnect
Expand All @@ -387,9 +386,7 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance
}
}

List<Commands.Monitor_FlashSectorMap.FlashSectorData> reply = DebugEngine.GetFlashSectorMap();

if (reply == null)
if (DebugEngine.FlashSectorMap == null)
{
return false;
}
Expand All @@ -401,15 +398,14 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance

bool isConnectedToCLR = ((ping != null) && (ping.Source == Commands.Monitor_Ping.c_Ping_Source_NanoCLR));


if (isConnectedToCLR)
{
DebugEngine.PauseExecution();
}

List<Commands.Monitor_FlashSectorMap.FlashSectorData> eraseSectors = new List<Commands.Monitor_FlashSectorMap.FlashSectorData>();

foreach (Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData in reply)
foreach (Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData in DebugEngine.FlashSectorMap)
{
if (cancellationToken.IsCancellationRequested)
{
Expand Down Expand Up @@ -481,27 +477,31 @@ public async Task<bool> EraseAsync(EraseOptions options, CancellationToken cance

foreach (Commands.Monitor_FlashSectorMap.FlashSectorData flashSectorData in eraseSectors)
{
progress?.Report($"Erasing sector @ 0x{flashSectorData.m_StartAddress:X8}...");
for (int block = 0; block < flashSectorData.m_NumBlocks; block++)
{
progress?.Report($"Erasing sector @ 0x{flashSectorData.m_StartAddress:X8}...");

(AccessMemoryErrorCodes ErrorCode, bool Success) = DebugEngine.EraseMemory(
(uint)(flashSectorData.m_StartAddress + block * flashSectorData.m_BytesPerBlock),
flashSectorData.m_BytesPerBlock);

(AccessMemoryErrorCodes ErrorCode, bool Success) = DebugEngine.EraseMemory(flashSectorData.m_StartAddress, (flashSectorData.m_NumBlocks * flashSectorData.m_BytesPerBlock));
if (!Success)
{
progress?.Report($"Error erasing sector @ 0x{flashSectorData.m_StartAddress:X8}.");

if (!Success)
{
progress?.Report($"Error erasing sector @ 0x{flashSectorData.m_StartAddress:X8}.");
return false;
}

return false;
}
// check the error code returned
if (ErrorCode != AccessMemoryErrorCodes.NoError)
{
// operation failed
progress?.Report($"Error erasing sector @ 0x{flashSectorData.m_StartAddress:X8}. Error code: {ErrorCode}.");

// check the error code returned
if (ErrorCode != AccessMemoryErrorCodes.NoError)
{
// operation failed
progress?.Report($"Error erasing sector @ 0x{flashSectorData.m_StartAddress:X8}. Error code: {ErrorCode}.");

// don't bother continuing
return false;
// don't bother continuing
return false;
}
}

value++;
}

Expand Down