Detect read-protected state in WCH RISC-V target driver
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Targets/TargetBitFieldDescriptor.hpp"
|
||||
#include "src/Targets/RiscV/Wch/TargetDescriptionFile.hpp"
|
||||
|
||||
namespace Targets::RiscV::Wch::Peripherals::Flash
|
||||
{
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Targets/TargetBitFieldDescriptor.hpp"
|
||||
|
||||
namespace Targets::RiscV::Wch::Peripherals::Flash
|
||||
{
|
||||
struct FlashOptionByteRegisterFields
|
||||
{
|
||||
const TargetBitFieldDescriptor& readProtected;
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "src/Targets/TargetBitFieldDescriptor.hpp"
|
||||
#include "src/Targets/RiscV/Wch/TargetDescriptionFile.hpp"
|
||||
|
||||
namespace Targets::RiscV::Wch::Peripherals::Flash
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "src/Services/StringService.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/TargetController/Exceptions/TargetFailure.hpp"
|
||||
#include "src/TargetController/Exceptions/TargetOperationFailure.hpp"
|
||||
|
||||
namespace Targets::RiscV::Wch
|
||||
@@ -41,6 +42,7 @@ namespace Targets::RiscV::Wch
|
||||
, flashBootKeyRegisterDescriptor(this->flashPeripheralDescriptor.getRegisterDescriptor("flash", "boot_modekeyr"))
|
||||
, flashStatusRegisterDescriptor(this->flashPeripheralDescriptor.getRegisterDescriptor("flash", "statr"))
|
||||
, flashControlRegisterDescriptor(this->flashPeripheralDescriptor.getRegisterDescriptor("flash", "ctrl"))
|
||||
, flashOptionByteRegisterDescriptor(this->flashPeripheralDescriptor.getRegisterDescriptor("flash", "obr"))
|
||||
, flashControlRegisterFields(
|
||||
Peripherals::Flash::FlashControlRegisterFields{
|
||||
.locked = this->flashControlRegisterDescriptor.getBitFieldDescriptor("lock"),
|
||||
@@ -55,6 +57,11 @@ namespace Targets::RiscV::Wch
|
||||
.bootMode = this->flashStatusRegisterDescriptor.getBitFieldDescriptor("boot_mode"),
|
||||
}
|
||||
)
|
||||
, flashOptionByteRegisterFields(
|
||||
Peripherals::Flash::FlashOptionByteRegisterFields{
|
||||
.readProtected = this->flashOptionByteRegisterDescriptor.getBitFieldDescriptor("rdprt"),
|
||||
}
|
||||
)
|
||||
, rccPeripheralDescriptor(this->targetDescriptionFile.getTargetPeripheralDescriptor("rcc"))
|
||||
, portPeripheralClockEnableRegisterDescriptor(
|
||||
this->rccPeripheralDescriptor.getRegisterDescriptor("rcc", "apb2pcenr")
|
||||
@@ -121,6 +128,11 @@ namespace Targets::RiscV::Wch
|
||||
}
|
||||
|
||||
this->variant = *(variantIt->second);
|
||||
|
||||
const auto optionByteValue = this->readRegisterDynamicValue(this->flashOptionByteRegisterDescriptor);
|
||||
if (optionByteValue.bitFieldAs<bool>(this->flashOptionByteRegisterFields.readProtected)) {
|
||||
throw Exceptions::TargetFailure{"Program memory is currently \"read-protected\""};
|
||||
}
|
||||
}
|
||||
|
||||
void WchRiscV::postActivate() {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "GpioPadDescriptor.hpp"
|
||||
#include "Peripherals/Flash/FlashControlRegisterFields.hpp"
|
||||
#include "Peripherals/Flash/FlashStatusRegisterFields.hpp"
|
||||
#include "Peripherals/Flash/FlashOptionByteRegisterFields.hpp"
|
||||
|
||||
namespace Targets::RiscV::Wch
|
||||
{
|
||||
@@ -106,9 +107,11 @@ namespace Targets::RiscV::Wch
|
||||
const TargetRegisterDescriptor& flashBootKeyRegisterDescriptor;
|
||||
const TargetRegisterDescriptor& flashStatusRegisterDescriptor;
|
||||
const TargetRegisterDescriptor& flashControlRegisterDescriptor;
|
||||
const TargetRegisterDescriptor& flashOptionByteRegisterDescriptor;
|
||||
|
||||
const Peripherals::Flash::FlashControlRegisterFields flashControlRegisterFields;
|
||||
const Peripherals::Flash::FlashStatusRegisterFields flashStatusRegisterFields;
|
||||
const Peripherals::Flash::FlashOptionByteRegisterFields flashOptionByteRegisterFields;
|
||||
|
||||
const TargetPeripheralDescriptor rccPeripheralDescriptor;
|
||||
const TargetRegisterDescriptor& portPeripheralClockEnableRegisterDescriptor;
|
||||
|
||||
Reference in New Issue
Block a user