Skip to content

Commit

Permalink
0.3.rev.A. Improve EEPROM support
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonsmartins committed Feb 3, 2024
1 parent 67ee294 commit a2ab715
Show file tree
Hide file tree
Showing 20 changed files with 429 additions and 106 deletions.
Binary file modified docs/specs.odt
Binary file not shown.
Binary file modified docs/specs.pdf
Binary file not shown.
69 changes: 51 additions & 18 deletions firmware/usbflashprog/modules/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,34 @@

// ---------------------------------------------------------------------------

/* @brief Command sequence to Unprotect an EEPROM 28C/X28 (ST/Atmel/Xicor). */
// clang-format off
constexpr Device::TDeviceCommand kDeviceCmdUnprotect28C[] = {
{0x1555, 0xAA}, {0xAAA, 0x55}, {0x1555, 0x80},
{0x1555, 0xAA}, {0xAAA, 0x55}, {0x1555, 0x20}

/* @brief Command sequence to Unprotect an EEPROM 28C/X28 64
(ST/Atmel/Xicor). */
constexpr Device::TDeviceCommand kDeviceCmdUnprotect28C64[] = {
{0x1555, 0xAA}, {0x0AAA, 0x55}, {0x1555, 0x80},
{0x1555, 0xAA}, {0x0AAA, 0x55}, {0x1555, 0x20}
};
// clang-format on

/* @brief Command sequence to Protect an EEPROM 28C/X28 (ST/Atmel/Xicor). */
// clang-format off
constexpr Device::TDeviceCommand kDeviceCmdProtect28C[] = {
{0x1555, 0xAA}, {0xAAA, 0x55}, {0x1555, 0xA0}
/* @brief Command sequence to Protect an EEPROM 28C/X28 64
(ST/Atmel/Xicor). */
constexpr Device::TDeviceCommand kDeviceCmdProtect28C64[] = {
{0x1555, 0xAA}, {0x0AAA, 0x55}, {0x1555, 0xA0}
};

/* @brief Command sequence to Unprotect an EEPROM 28C/X28 256
(ST/Atmel/Xicor). */
constexpr Device::TDeviceCommand kDeviceCmdUnprotect28C256[] = {
{0x5555, 0xAA}, {0x2AAA, 0x55}, {0x5555, 0x80},
{0x5555, 0xAA}, {0x2AAA, 0x55}, {0x5555, 0x20}
};

/* @brief Command sequence to Protect an EEPROM 28C/X28 256
(ST/Atmel/Xicor). */
constexpr Device::TDeviceCommand kDeviceCmdProtect28C256[] = {
{0x5555, 0xAA}, {0x2AAA, 0x55}, {0x5555, 0xA0}
};

// clang-format on

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -488,8 +503,10 @@ bool Device::erase27E_() {
bool Device::unprotect(uint8_t algo) {
// Unprotect entire chip
switch (algo) {
case kCmdDeviceAlgorithm28C:
return protect28C_(false);
case kCmdDeviceAlgorithm28C64:
return protect28C_(false, false);
case kCmdDeviceAlgorithm28C256:
return protect28C_(false, true);
default:
return false;
}
Expand All @@ -498,28 +515,44 @@ bool Device::unprotect(uint8_t algo) {
bool Device::protect(uint8_t algo) {
// Protect entire chip
switch (algo) {
case kCmdDeviceAlgorithm28C:
return protect28C_(true);
case kCmdDeviceAlgorithm28C64:
return protect28C_(true, false);
case kCmdDeviceAlgorithm28C256:
return protect28C_(true, true);
default:
return false;
}
}

bool Device::protect28C_(bool protect) {
bool Device::protect28C_(bool protect, bool is256) {
// EEPROM 28C/X28/AT28 Algorithm
bool success = true;
// ~CE is LO
setCE(true);
// write command
if (protect) {
for (const TDeviceCommand& cmd : kDeviceCmdProtect28C) {
if (protect && !is256) {
for (const TDeviceCommand& cmd : kDeviceCmdProtect28C64) {
if (!writeAtAddr_(cmd.addr, cmd.data)) {
success = false;
break;
}
}
} else {
for (const TDeviceCommand& cmd : kDeviceCmdUnprotect28C) {
} else if (protect && is256) {
for (const TDeviceCommand& cmd : kDeviceCmdProtect28C256) {
if (!writeAtAddr_(cmd.addr, cmd.data)) {
success = false;
break;
}
}
} else if (!protect && !is256) {
for (const TDeviceCommand& cmd : kDeviceCmdUnprotect28C64) {
if (!writeAtAddr_(cmd.addr, cmd.data)) {
success = false;
break;
}
}
} else if (!protect && is256) {
for (const TDeviceCommand& cmd : kDeviceCmdUnprotect28C256) {
if (!writeAtAddr_(cmd.addr, cmd.data)) {
success = false;
break;
Expand Down
4 changes: 3 additions & 1 deletion firmware/usbflashprog/modules/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,11 @@ class Device {
/*
* @brief Runs the device protect/unprotect (EEPROM 28C algorithm).
* @param protect If true, protects device. Otherwise, unprotects device.
* @param is256 If true, uses the 28C256 algorithm.
* Otherwise, uses the 28C64 algorithm.
* @return True if sucessfull. False otherwise.
*/
bool protect28C_(bool protect);
bool protect28C_(bool protect, bool is256);

private:
/*
Expand Down
39 changes: 22 additions & 17 deletions firmware/usbflashprog/modules/opcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand All @@ -274,11 +275,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand All @@ -288,11 +290,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand Down Expand Up @@ -328,8 +331,10 @@ enum kCmdDeviceAlgorithmEnum {
kCmdDeviceAlgorithmUnknown = 0x00,
/** @brief CMD / DEVICE : Defines an algorithm EPROM 27E/SF/W27. */
kCmdDeviceAlgorithm27E = 0x01,
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C. */
kCmdDeviceAlgorithm28C = 0x02
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C64. */
kCmdDeviceAlgorithm28C64 = 0x02,
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C256 or upper. */
kCmdDeviceAlgorithm28C256 = 0x03
};

// ---------------------------------------------------------------------------
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 0 additions & 19 deletions software/usbflashprog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,26 @@ elseif(NORMAL_BUILD)
)

set(PROJECT_SOURCES
config.hpp
backend/opcodes.cpp
backend/opcodes.hpp
backend/runner.cpp
backend/runner.hpp
backend/epromfile/qepromfilebase.cpp
backend/epromfile/qepromfilebase.hpp
backend/epromfile/qbinfile.cpp
backend/epromfile/qbinfile.hpp
backend/epromfile/qsrecfile.cpp
backend/epromfile/qsrecfile.hpp
backend/epromfile/qhexfile.cpp
backend/epromfile/qhexfile.hpp
backend/epromfile/qatmelfile.cpp
backend/epromfile/qatmelfile.hpp
backend/epromfile/qepromfile.cpp
backend/epromfile/qepromfile.hpp
backend/devices/device.cpp
backend/devices/device.hpp
backend/devices/parallel/pdevice.cpp
backend/devices/parallel/pdevice.hpp
backend/devices/parallel/dummy.cpp
backend/devices/parallel/dummy.hpp
backend/devices/parallel/sram.cpp
backend/devices/parallel/sram.hpp
backend/devices/parallel/eprom.cpp
backend/devices/parallel/eprom.hpp
backend/devices/parallel/eeprom.cpp
backend/devices/parallel/eeprom.hpp
ui/qhexeditor.cpp
ui/qhexeditor.hpp
ui/mainwindow.cpp
ui/mainwindow.hpp
ui/mainwindow.ui
ui/settings.cpp
ui/settings.hpp
ui/settings.ui
main.cpp
main.hpp
)

set(PROJECT_RESOURCES
Expand Down
23 changes: 21 additions & 2 deletions software/usbflashprog/backend/devices/parallel/eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EEPROM::EEPROM(QObject *parent) : ParDevice(parent) {
size_ = 2048;
twp_ = 2;
twc_ = 10000;
protectAlgo_ = kCmdDeviceAlgorithm28C;
protectAlgo_ = kCmdDeviceAlgorithm28C64;
maxAttemptsProg_ = 3;
DEBUG << info_.toString();
}
Expand All @@ -55,6 +55,8 @@ EEPROM::~EEPROM() {}

void EEPROM::setSize(uint32_t value) {
ParDevice::setSize(value);
protectAlgo_ = (size_ <= 0x2000) ? kCmdDeviceAlgorithm28C64
: kCmdDeviceAlgorithm28C256;
bool oldValue = info_.capability.hasUnprotect;
bool newValue = (size_ >= 0x2000); // >= 8KB
if (oldValue != newValue) {
Expand Down Expand Up @@ -96,11 +98,28 @@ EEPROM28AT::~EEPROM28AT() {}

void EEPROM28AT::setSize(uint32_t value) {
EEPROM::setSize(value);
switch (size_) {
case 0x02000: // 8KB
case 0x04000: // 16KB
case 0x08000: // 32KB
sectorSize_ = 64;
break;
case 0x10000: // 64KB
case 0x20000: // 128KB
sectorSize_ = 128;
break;
case 0x40000: // 256KB
sectorSize_ = 256;
break;
default:
if (size_ < 0x02000) sectorSize_ = 0;
if (size_ > 0x40000) sectorSize_ = 256;
break;
}
bool oldValue = info_.capability.hasSectorSize;
bool newValue = (size_ >= 0x2000); // >= 8KB
if (oldValue != newValue) {
info_.capability.hasSectorSize = newValue;
sectorSize_ = newValue ? 64 : 0;
DEBUG << info_.toString();
}
}
39 changes: 22 additions & 17 deletions software/usbflashprog/backend/opcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand All @@ -284,11 +285,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand All @@ -298,11 +300,12 @@ enum kCmdOpCodeEnum {
* @details The parameter (one byte) represents the algorithm, and
* follows the table:
* <pre>
* +------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C |
* +------------------------------+
* +-------------------------------+
* |Algorithm| Description |
* | 0x01 | EPROM 27E/W27/27SF |
* | 0x02 | EEPROM 28C64 |
* | 0x03 | EEPROM 28C256/upper |
* +-------------------------------+
* </pre>
* @see kCmdDeviceAlgorithmEnum
*/
Expand Down Expand Up @@ -341,8 +344,10 @@ enum kCmdDeviceAlgorithmEnum {
kCmdDeviceAlgorithmUnknown = 0x00,
/** @brief CMD / DEVICE : Defines an algorithm EPROM 27E/SF/W27. */
kCmdDeviceAlgorithm27E = 0x01,
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C. */
kCmdDeviceAlgorithm28C = 0x02
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C64. */
kCmdDeviceAlgorithm28C64 = 0x02,
/** @brief CMD / DEVICE : Defines an algorithm EEPROM 28C256 or upper. */
kCmdDeviceAlgorithm28C256 = 0x03
};

// ---------------------------------------------------------------------------
Expand Down
17 changes: 2 additions & 15 deletions software/usbflashprog/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,22 @@ FetchContent_MakeAvailable(googletest)
set(PROJ_NAME ufprog_test)

set(PROJECT_SOURCES
../config.hpp
../backend/opcodes.cpp
../backend/opcodes.hpp
../backend/runner.cpp
../backend/runner.hpp
../backend/devices/device.hpp
../backend/devices/device.cpp
../backend/devices/parallel/pdevice.hpp
../backend/devices/parallel/pdevice.cpp
../backend/devices/parallel/sram.hpp
../backend/devices/parallel/sram.cpp
../backend/devices/parallel/eprom.hpp
../backend/devices/parallel/eprom.cpp
../backend/devices/parallel/eeprom.cpp
mock/qserialport.hpp
emulator/emulator.cpp
emulator/emulator.hpp
emulator/chip.cpp
emulator/chip.hpp
emulator/sram.cpp
emulator/sram.hpp
emulator/eprom.cpp
emulator/eprom.hpp
backend/chip_test.hpp
emulator/eeprom.cpp
backend/chip_test.cpp
backend/runner_test.hpp
backend/runner_test.cpp
backend/opcodes_test.hpp
backend/opcodes_test.cpp
main.hpp
main.cpp
)

Expand Down
Loading

0 comments on commit a2ab715

Please sign in to comment.