EDBG AVR command frames for the AVRISP sub-protocol.

This commit is contained in:
Nav
2022-03-02 22:45:29 +00:00
parent f6399faf9e
commit a9fe05e802
6 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
#pragma once
#include "src/Exceptions/Exception.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Avr8Generic.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AvrCommandFrame.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/AVRISP/AvrIspResponseFrame.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::AvrIsp
{
template<class PayloadContainerType>
class AvrIspCommandFrame: public AvrCommandFrame<PayloadContainerType>
{
public:
using ExpectedResponseFrameType = ResponseFrames::AvrIsp::AvrIspResponseFrame;
AvrIspCommandFrame(): AvrCommandFrame<PayloadContainerType>(ProtocolHandlerId::AVRISP) {}
};
}

View File

@@ -0,0 +1,59 @@
#pragma once
#include <cstdint>
#include "AvrIspCommandFrame.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::AvrIsp
{
class EnterProgrammingMode: public AvrIspCommandFrame<std::array<unsigned char, 12>>
{
public:
EnterProgrammingMode(
std::uint8_t timeout,
std::uint8_t stabDelay,
std::uint8_t commandExecutionDelay,
std::uint8_t syncLoops,
std::uint8_t byteDelay,
std::uint8_t pollValue,
std::uint8_t pollIndex
) {
/*
* The enter programming mode command consists of 12 bytes:
*
* 1. Command ID (0x10)
*
* -- The fields from this point are taken from the AVR8 TDFs --
*
* 2. Command timeout in milliseconds
* 3. Pin stabilization delay in milliseconds
* 4. Command execution delay in milliseconds
* 5. Number of synchronisation loops
* 6. Millisecond delay between each byte in the command
* 7. Poll value
* 8. Poll index
*
* -- The fields from this point are the four bytes of the low-level SPI command --
*
* 9. CMD1 - For the enter programming mode command, this appears to always be 0xAC
* 10. CMD2 - For AVR8 targets, this also appears to be a fixed value of 0x53
* 11. CMD3 - 0x00
* 12. CMD4 - 0x00
*/
this->payload = {
0x10,
timeout,
stabDelay,
commandExecutionDelay,
syncLoops,
byteDelay,
pollValue,
pollIndex,
0xAC,
0x53,
0x00,
0x00,
};
}
};
}

View File

@@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include "AvrIspCommandFrame.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::AvrIsp
{
class LeaveProgrammingMode: public AvrIspCommandFrame<std::array<unsigned char, 3>>
{
public:
LeaveProgrammingMode(
std::uint8_t preDelay,
std::uint8_t postDelay
) {
/*
* The leave programming mode command consists of 3 bytes:
*
* 1. Command ID (0x11)
*
* -- The fields from this point are taken from the AVR8 TDFs --
*
* 2. Pre-delay
* 3. Post-delay
*/
this->payload = {
0x11,
preDelay,
postDelay,
};
}
};
}

View File

@@ -0,0 +1,65 @@
#pragma once
#include <cstdint>
#include <src/Targets/Microchip/AVR/Fuse.hpp>
#include "AvrIspCommandFrame.hpp"
#include "src/Targets/Microchip/AVR/Fuse.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::AvrIsp
{
class ReadFuse: public AvrIspCommandFrame<std::array<unsigned char, 6>>
{
public:
ReadFuse(
Targets::Microchip::Avr::FuseType fuseType,
std::uint8_t returnAddress
) {
using Targets::Microchip::Avr::FuseType;
/*
* The read fuse command consists of 6 bytes:
*
* 1. Command ID (0x18)
* 2. Return Address
* 3. CMD1
* 4. CMD2
* 5. CMD3
* 6. CMD4
*/
this->payload = {
0x18,
returnAddress,
0x00,
0x00,
0x00,
0x00,
};
switch (fuseType) {
case FuseType::LOW: {
this->payload[2] = 0x50;
this->payload[3] = 0x00;
this->payload[4] = 0x00;
this->payload[5] = 0x00;
break;
}
case FuseType::HIGH: {
this->payload[2] = 0x58;
this->payload[3] = 0x08;
this->payload[4] = 0x00;
this->payload[5] = 0x00;
break;
}
case FuseType::EXTENDED: {
this->payload[2] = 0x50;
this->payload[3] = 0x08;
this->payload[4] = 0x00;
this->payload[5] = 0x00;
break;
}
}
}
};
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include <cstdint>
#include <src/Targets/Microchip/AVR/Fuse.hpp>
#include "AvrIspCommandFrame.hpp"
#include "src/Targets/Microchip/AVR/Fuse.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::AvrIsp
{
class ReadSignature: public AvrIspCommandFrame<std::array<unsigned char, 6>>
{
public:
ReadSignature(
std::uint8_t signatureByteAddress,
std::uint8_t returnAddress
) {
using Targets::Microchip::Avr::FuseType;
/*
* The read signature command consists of 6 bytes:
*
* 1. Command ID (0x1B)
* 2. Return Address
* 3. CMD1
* 4. CMD2
* 5. CMD3
* 6. CMD4
*/
this->payload = {
0x1B,
returnAddress,
0x30,
0x00,
static_cast<unsigned char>(signatureByteAddress & 0x03),
0x00,
};
}
};
}

View File

@@ -6,6 +6,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg
{
DISCOVERY = 0x00,
HOUSE_KEEPING = 0x01,
AVRISP = 0x11,
AVR8_GENERIC = 0x12,
AVR32_GENERIC = 0x13,
};