Added BOOT_FLASH memory type in AVR8 EDBG driver

This commit is contained in:
Nav
2022-06-03 15:45:43 +01:00
parent a97cdeae6f
commit 94b7130dbb
2 changed files with 39 additions and 9 deletions

View File

@@ -140,7 +140,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
FLASH_PAGE = 0xB0, FLASH_PAGE = 0xB0,
/** /**
* The APPL_FLASH memory type can be used to read/write flash memory on the target. * The APPL_FLASH memory type can be used to read/write to the application section of the flash memory on the
* target.
* *
* Only available with the XMEGA (PDI) and UPDI (PDI_1W) config variants. * Only available with the XMEGA (PDI) and UPDI (PDI_1W) config variants.
* *
@@ -148,6 +149,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* any attempts of writing data. * any attempts of writing data.
*/ */
APPL_FLASH = 0xC0, APPL_FLASH = 0xC0,
BOOT_FLASH = 0xC1,
/** /**
* The SPM memory type can be used to read memory from the target whilst in debugging mode. * The SPM memory type can be used to read memory from the target whilst in debugging mode.

View File

@@ -693,7 +693,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
} else if ( } else if (
this->configVariant == Avr8ConfigVariant::XMEGA || this->configVariant == Avr8ConfigVariant::UPDI this->configVariant == Avr8ConfigVariant::XMEGA || this->configVariant == Avr8ConfigVariant::UPDI
) { ) {
avr8MemoryType = Avr8MemoryType::APPL_FLASH; const auto bootSectionStartAddress = this->targetParameters.bootSectionStartAddress.value();
if (startAddress >= bootSectionStartAddress) {
avr8MemoryType = Avr8MemoryType::BOOT_FLASH;
/*
* When using the BOOT_FLASH memory type, the address should be relative to the start of the
* boot section.
*/
startAddress -= bootSectionStartAddress;
} else {
avr8MemoryType = Avr8MemoryType::APPL_FLASH;
}
} }
break; break;
} }
@@ -1410,6 +1422,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
memoryType == Avr8MemoryType::FLASH_PAGE memoryType == Avr8MemoryType::FLASH_PAGE
|| memoryType == Avr8MemoryType::SPM || memoryType == Avr8MemoryType::SPM
|| memoryType == Avr8MemoryType::APPL_FLASH || memoryType == Avr8MemoryType::APPL_FLASH
|| memoryType == Avr8MemoryType::BOOT_FLASH
; ;
} }
@@ -1423,7 +1436,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
alignTo = this->targetParameters.flashPageSize.value(); alignTo = this->targetParameters.flashPageSize.value();
break; break;
} }
case Avr8MemoryType::APPL_FLASH: { case Avr8MemoryType::APPL_FLASH:
case Avr8MemoryType::BOOT_FLASH: {
if (this->configVariant == Avr8ConfigVariant::UPDI) { if (this->configVariant == Avr8ConfigVariant::UPDI) {
// For UPDI sessions, memory access via the APPL_FLASH must be word aligned. // For UPDI sessions, memory access via the APPL_FLASH must be word aligned.
alignTo = 2; alignTo = 2;
@@ -1463,7 +1477,8 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
alignTo = this->targetParameters.flashPageSize.value(); alignTo = this->targetParameters.flashPageSize.value();
break; break;
} }
case Avr8MemoryType::APPL_FLASH: { case Avr8MemoryType::APPL_FLASH:
case Avr8MemoryType::BOOT_FLASH: {
if (this->configVariant == Avr8ConfigVariant::UPDI) { if (this->configVariant == Avr8ConfigVariant::UPDI) {
// For UPDI sessions, memory access via the APPL_FLASH must be word aligned. // For UPDI sessions, memory access via the APPL_FLASH must be word aligned.
alignTo = 2; alignTo = 2;
@@ -1561,8 +1576,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
} }
} }
if (type == Avr8MemoryType::FLASH_PAGE || type == Avr8MemoryType::APPL_FLASH) { if (
// With the FLASH_PAGE and APPL_FLASH memory types, we can only read one page at a time. type == Avr8MemoryType::FLASH_PAGE
|| type == Avr8MemoryType::APPL_FLASH
|| type == Avr8MemoryType::BOOT_FLASH
) {
// With the FLASH_PAGE, APPL_FLASH and BOOT_FLASH memory types, we can only read one page at a time.
const auto pageSize = this->targetParameters.flashPageSize.value(); const auto pageSize = this->targetParameters.flashPageSize.value();
if (bytes > pageSize) { if (bytes > pageSize) {
@@ -1612,7 +1631,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
return output; return output;
} }
if (type != Avr8MemoryType::FLASH_PAGE && type != Avr8MemoryType::SPM && type != Avr8MemoryType::APPL_FLASH) { if (
type != Avr8MemoryType::FLASH_PAGE
&& type != Avr8MemoryType::SPM
&& type != Avr8MemoryType::APPL_FLASH
&& type != Avr8MemoryType::BOOT_FLASH
) {
/* /*
* EDBG AVR8 debug tools behave in a really weird way when responding with more than two packets * EDBG AVR8 debug tools behave in a really weird way when responding with more than two packets
* for a single read (non-flash) memory command. The data they return in this case appears to be of little * for a single read (non-flash) memory command. The data they return in this case appears to be of little
@@ -1689,8 +1713,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
} }
} }
if (type == Avr8MemoryType::FLASH_PAGE || type == Avr8MemoryType::APPL_FLASH) { if (
// With the FLASH_PAGE and APPL_FLASH memory type, we can only write one page at a time. type == Avr8MemoryType::FLASH_PAGE
|| type == Avr8MemoryType::APPL_FLASH
|| type == Avr8MemoryType::BOOT_FLASH
) {
// With the FLASH_PAGE, APPL_FLASH and BOOT_FLASH memory types, we can only write one page at a time.
const auto pageSize = this->targetParameters.flashPageSize.value(); const auto pageSize = this->targetParameters.flashPageSize.value();
if (bytes > pageSize) { if (bytes > pageSize) {