Erasing XMEGA application section upon entering programming mode
This commit is contained in:
@@ -179,4 +179,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
inline bool operator == (Avr8ResponseId id, unsigned char rawId) {
|
||||
return rawId == id;
|
||||
}
|
||||
|
||||
enum class Avr8EraseMemoryMode: unsigned char
|
||||
{
|
||||
CHIP = 0x00,
|
||||
APPLICATION_SECTION = 0x01,
|
||||
BOOT_SECTION = 0x02,
|
||||
EEPROM = 0x03,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "Avr8GenericCommandFrame.hpp"
|
||||
|
||||
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Avr8Generic
|
||||
{
|
||||
class EraseMemory: public Avr8GenericCommandFrame<std::array<unsigned char, 7>>
|
||||
{
|
||||
public:
|
||||
EraseMemory(Avr8EraseMemoryMode mode) {
|
||||
/*
|
||||
* The erase memory command consists of 7 bytes:
|
||||
* 1. Command ID (0x20)
|
||||
* 2. Version (0x00)
|
||||
* 3. Erase mode (see Avr8EraseMemoryMode enum)
|
||||
* 4. Start address (4 bytes) - this is just hardcoded to 0x00000000 for now.
|
||||
*/
|
||||
this->payload = {
|
||||
0x20,
|
||||
0x00,
|
||||
static_cast<unsigned char>(mode),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/ClearSoftwareBreakpoints.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EnterProgrammingMode.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/LeaveProgrammingMode.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/EraseMemory.hpp"
|
||||
|
||||
// AVR events
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Events/AVR8Generic/BreakEvent.hpp"
|
||||
@@ -691,6 +692,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
}
|
||||
|
||||
this->programmingModeEnabled = true;
|
||||
|
||||
if (this->configVariant == Avr8ConfigVariant::XMEGA) {
|
||||
Logger::warning(
|
||||
"The entire application section of program memory will be erased, in preparation for programming"
|
||||
);
|
||||
this->eraseMemory(Avr8EraseMemoryMode::APPLICATION_SECTION);
|
||||
}
|
||||
}
|
||||
|
||||
void EdbgAvr8Interface::disableProgrammingMode() {
|
||||
@@ -1659,6 +1667,16 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
if (response.getResponseId() == Avr8ResponseId::FAILED) {
|
||||
throw Avr8CommandFailure("AVR8 Write memory command failed", response);
|
||||
}
|
||||
|
||||
|
||||
void EdbgAvr8Interface::eraseMemory(Avr8EraseMemoryMode mode) {
|
||||
auto response = this->edbgInterface.sendAvrCommandFrameAndWaitForResponseFrame(
|
||||
CommandFrames::Avr8Generic::EraseMemory(mode)
|
||||
);
|
||||
|
||||
if (response.getResponseId() == Avr8ResponseId::FAILED) {
|
||||
throw Avr8CommandFailure("AVR8 erase memory command failed", response);
|
||||
}
|
||||
}
|
||||
|
||||
void EdbgAvr8Interface::refreshTargetState() {
|
||||
|
||||
@@ -537,6 +537,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
*/
|
||||
void writeMemory(Avr8MemoryType type, std::uint32_t address, const Targets::TargetMemoryBuffer& buffer);
|
||||
|
||||
/**
|
||||
* Erases a particular region of memory, depending on the value of mode.
|
||||
*
|
||||
* @param mode
|
||||
*/
|
||||
void eraseMemory(Avr8EraseMemoryMode mode);
|
||||
|
||||
/**
|
||||
* Fetches the current target state.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user