Skip to content

Commit 317fbf4

Browse files
authored
Patch v1.5.2 (#16)
* Improving error messages * Incrementing version for firmware to match GUI
1 parent 9b0ce4b commit 317fbf4

File tree

8 files changed

+148
-17
lines changed

8 files changed

+148
-17
lines changed

firmware/constants.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ GPIO19 - LOAD for A16-A19
4545
#define DELAY_READ_VERIFY 1
4646
#define DELAY_WRITE 1
4747
#define DELAY_ADDR 1
48-
#define BOARD_ID "PICOSST39-v1.4.0"
48+
#define BOARD_ID "PICOSST39-v1.5.2"
4949

5050
#define BLOCK_SIZE 0x100
5151
#define SECTOR_SIZE 0x1000
@@ -54,4 +54,4 @@ GPIO19 - LOAD for A16-A19
5454
#define NOP __asm volatile ("nop\n");
5555
#define NOP50 __asm volatile ("nop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\nnop\n");
5656

57-
#endif
57+
#endif

gui/src/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define _CONFIG_H
2323

2424
#define PROGRAM_NAME "PICO SST39sf0x0 Programmer"
25-
#define PROGRAM_VERSION "1.5.1"
25+
#define PROGRAM_VERSION "1.5.2"
2626
#define UNUSED(x) (void)(x)
2727

2828
#endif // _CONFIG_H

gui/src/flashthread.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ void FlashThread::flash_sst39sf0x0() {
3939
// check that the chip id is correct
4040
unsigned int chip_id = this->serial_interface->get_chip_id();
4141
if(!(chip_id == 0xBFB5 || chip_id == 0xBFB6 || chip_id == 0xBFB7)) {
42-
emit(flash_chip_id_error(chip_id));
42+
std::string chip_id_str = tr("0x%1%2").arg((uint16_t)chip_id >> 8, 2, 16, QChar('0')).arg((uint8_t)chip_id & 0xFF, 2, 16, QChar('0')).toStdString();
43+
emit(thread_abort(tr("Unknown chip id: %1").arg(chip_id_str.c_str())));
44+
this->serial_interface->close_port();
45+
return;
4346
return;
4447
}
4548

gui/src/flashthread.h

-6
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ class FlashThread : public IOWorker {
106106
* @param block_id
107107
*/
108108
void flash_sector_done(unsigned int sector_id, unsigned int nr_sectors);
109-
110-
/**
111-
* @brief signal when flash chip id is incorrect
112-
* @param block_id
113-
*/
114-
void flash_chip_id_error(unsigned int chip_id);
115109
};
116110

117111
#endif // FLASHTHREAD_H

gui/src/ioworker.h

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class IOWorker : public QThread {
111111

112112
protected:
113113

114+
signals:
115+
void thread_abort(const QString&);
116+
114117
};
115118

116119
#endif // IOWORKER_H

gui/src/mainwindow.cpp

+119-5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ MainWindow::MainWindow(const std::shared_ptr<QStringList> _log_messages, QWidget
5353
this->hex_widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
5454
container_layout->addWidget(this->hex_widget);
5555

56+
this->button_reload_file = new QPushButton("Reload file");
57+
container_layout->addWidget(this->button_reload_file);
58+
this->button_reload_file->setEnabled(false);
59+
connect(this->button_reload_file, SIGNAL(released()), this, SLOT(slot_reload_file()));
60+
5661
// create central widget for writing data
5762
QScrollArea *scroll_area = new QScrollArea();
5863
layout->addWidget(scroll_area);
@@ -569,9 +574,10 @@ void MainWindow::slot_open() {
569574
return;
570575
}
571576

572-
file.open(QIODevice::ReadOnly);
573577
if(file.exists()) {
578+
file.open(QIODevice::ReadOnly);
574579
QByteArray data = file.readAll();
580+
this->current_filename = file.fileName();
575581
int filesize = data.size();
576582

577583
// ask the user whether they want to expand the image
@@ -582,11 +588,15 @@ void MainWindow::slot_open() {
582588
"be used as a cartridge, would you like to to expand it "
583589
"to 16kb by padding the data with 0x00?", QMessageBox::Yes|QMessageBox::No);
584590
if (reply == QMessageBox::Yes) {
591+
this->current_file_expanded = true;
585592
resize_qbytearray(&data, 0x4000);
593+
} else {
594+
this->current_file_expanded = false;
586595
}
587596
}
588597

589598
this->hex_widget->set_data(data);
599+
this->button_reload_file->setEnabled(true);
590600

591601
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
592602
QFileInfo finfo(file);
@@ -607,6 +617,46 @@ void MainWindow::slot_open() {
607617
}
608618
}
609619

620+
/**
621+
* @brief MainWindow::reload a file
622+
*/
623+
void MainWindow::slot_reload_file() {
624+
QFile file(this->current_filename);
625+
626+
if(file.exists()) {
627+
file.open(QIODevice::ReadOnly);
628+
QByteArray data = file.readAll();
629+
this->current_filename = file.fileName();
630+
int filesize = data.size();
631+
632+
// ask the user whether they want to expand the image
633+
if(data.size() < 0x4000 && this->current_file_expanded) {
634+
resize_qbytearray(&data, 0x4000);
635+
}
636+
637+
this->hex_widget->set_data(data);
638+
639+
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
640+
QFileInfo finfo(file);
641+
642+
QString usage;
643+
if(data.size() == 0x4000) {
644+
usage = QString(" | %1 kb / %2 kb (%3 %)")
645+
.arg(QString::number((float)filesize/(float)1024, 'f', 1))
646+
.arg(QString::number(16, 'f', 1))
647+
.arg((float)filesize/(float)(16 * 1024) * 100, 0, 'f', 1);
648+
}
649+
650+
this->label_data_descriptor->setText(QString("<b>%1</b> | Size: %2 kb | MD5: %3" + usage)
651+
.arg(finfo.fileName())
652+
.arg(data.size() / 1024)
653+
.arg(QString(hash.toHex()))
654+
);
655+
656+
statusBar()->showMessage(tr("Reloaded %1 from drive.").arg(this->current_filename));
657+
}
658+
}
659+
610660
/**
611661
* @brief Open a binary file
612662
*/
@@ -741,6 +791,7 @@ void MainWindow::load_default_image() {
741791
if(timer.isActive()) {
742792
QByteArray data = fd->downloadedData();
743793
this->hex_widget->set_data(data);
794+
this->button_reload_file->setEnabled(false);
744795

745796
QString rom_name = image.split(QChar('/')).back();
746797

@@ -870,6 +921,7 @@ void MainWindow::read_rom() {
870921
connect(this->readerthread.get(), SIGNAL(read_result_ready()), this, SLOT(read_result_ready()));
871922
connect(this->readerthread.get(), SIGNAL(read_block_start(uint,uint)), this, SLOT(read_block_start(uint,uint)));
872923
connect(this->readerthread.get(), SIGNAL(read_block_done(uint,uint)), this, SLOT(read_block_done(uint,uint)));
924+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
873925
this->readerthread->start();
874926
}
875927

@@ -899,6 +951,7 @@ void MainWindow::read_cartridge() {
899951
connect(this->cartridgereaderthread.get(), SIGNAL(read_result_ready()), this, SLOT(read_result_ready()));
900952
connect(this->cartridgereaderthread.get(), SIGNAL(read_block_start(uint,uint)), this, SLOT(read_block_start(uint,uint)));
901953
connect(this->cartridgereaderthread.get(), SIGNAL(read_block_done(uint,uint)), this, SLOT(read_block_done(uint,uint)));
954+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
902955
this->cartridgereaderthread->start();
903956
}
904957

@@ -955,7 +1008,17 @@ void MainWindow::flash_rom() {
9551008

9561009
// verify whether the chip is correct
9571010
qDebug() << "Verifying chip";
958-
this->verify_chip();
1011+
try {
1012+
this->verify_chip();
1013+
} catch(const std::exception& e) {
1014+
this->raise_error_window(QMessageBox::Critical,
1015+
"Cannot flash this ROM to bank due to a problem with "
1016+
"with the CHIP id. Please carefully check the chip and "
1017+
"whether it is properly inserted into the socket."
1018+
"\n\nError message: " + QString(e.what())
1019+
);
1020+
return;
1021+
}
9591022

9601023
if((this->num_blocks * 256) < this->flash_data.size()) {
9611024

@@ -984,7 +1047,7 @@ void MainWindow::flash_rom() {
9841047
connect(this->flashthread.get(), SIGNAL(flash_result_ready()), this, SLOT(flash_result_ready()));
9851048
connect(this->flashthread.get(), SIGNAL(flash_sector_start(uint,uint)), this, SLOT(flash_sector_start(uint,uint)));
9861049
connect(this->flashthread.get(), SIGNAL(flash_sector_done(uint,uint)), this, SLOT(flash_sector_done(uint,uint)));
987-
connect(this->flashthread.get(), SIGNAL(flash_chip_id_error(uint)), this, SLOT(flash_chip_id_error(uint)));
1050+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
9881051
flashthread->start();
9891052

9901053
// disable all buttons
@@ -1011,7 +1074,17 @@ void MainWindow::flash_bank() {
10111074
this->flash_data = this->hex_widget->get_data();
10121075

10131076
// verify whether the chip is correct
1014-
this->verify_chip();
1077+
try {
1078+
this->verify_chip();
1079+
} catch(const std::exception& e) {
1080+
this->raise_error_window(QMessageBox::Critical,
1081+
"Cannot flash this ROM to bank due to a problem with "
1082+
"with the CHIP id. Please carefully check the chip and "
1083+
"whether it is properly inserted into the socket."
1084+
"\n\nError message: " + QString(e.what())
1085+
);
1086+
return;
1087+
}
10151088

10161089
if(this->flash_data.size() > 16 * 1024) {
10171090
this->raise_error_window(QMessageBox::Critical,
@@ -1034,7 +1107,7 @@ void MainWindow::flash_bank() {
10341107
connect(this->flashthread.get(), SIGNAL(flash_result_ready()), this, SLOT(flash_result_ready()));
10351108
connect(this->flashthread.get(), SIGNAL(flash_sector_start(uint,uint)), this, SLOT(flash_sector_start(uint,uint)));
10361109
connect(this->flashthread.get(), SIGNAL(flash_sector_done(uint,uint)), this, SLOT(flash_sector_done(uint,uint)));
1037-
connect(this->flashthread.get(), SIGNAL(flash_chip_id_error(uint)), this, SLOT(flash_chip_id_error(uint)));
1110+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
10381111
flashthread->start();
10391112

10401113
// disable all buttons
@@ -1045,6 +1118,19 @@ void MainWindow::flash_bank() {
10451118
* @brief Put rom on flash cartridge
10461119
*/
10471120
void MainWindow::erase_chip() {
1121+
// verify whether the chip is correct
1122+
try {
1123+
this->verify_chip();
1124+
} catch(const std::exception& e) {
1125+
this->raise_error_window(QMessageBox::Critical,
1126+
"Cannot flash this ROM to bank due to a problem with "
1127+
"with the CHIP id. Please carefully check the chip and "
1128+
"whether it is properly inserted into the socket."
1129+
"\n\nError message: " + QString(e.what())
1130+
);
1131+
return;
1132+
}
1133+
10481134
QMessageBox::StandardButton reply;
10491135
reply = QMessageBox::question(this, "Wipe chip?", "Are you sure you want to completely wipe the chip?", QMessageBox::Yes|QMessageBox::No);
10501136
if (reply != QMessageBox::Yes) {
@@ -1079,6 +1165,7 @@ void MainWindow::scan_chip() {
10791165
connect(this->readerthread.get(), SIGNAL(read_result_ready()), this, SLOT(scan_chip_result_ready()));
10801166
connect(this->readerthread.get(), SIGNAL(read_block_start(uint,uint)), this, SLOT(read_block_start(uint,uint)));
10811167
connect(this->readerthread.get(), SIGNAL(read_block_done(uint,uint)), this, SLOT(read_block_done(uint,uint)));
1168+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
10821169
this->readerthread->start();
10831170
}
10841171

@@ -1126,6 +1213,7 @@ void MainWindow::flash_result_ready() {
11261213
connect(this->readerthread.get(), SIGNAL(read_result_ready()), this, SLOT(verify_result_ready()));
11271214
connect(this->readerthread.get(), SIGNAL(read_block_start(uint,uint)), this, SLOT(verify_block_start(uint,uint)));
11281215
connect(this->readerthread.get(), SIGNAL(read_block_done(uint,uint)), this, SLOT(verify_block_done(uint,uint)));
1216+
connect(this->readerthread.get(), SIGNAL(thread_abort(const QString&)), this, SLOT(thread_abort(const QString&)));
11291217
this->readerthread->start();
11301218
}
11311219

@@ -1193,3 +1281,29 @@ void MainWindow::verify_result_ready() {
11931281
// this->enable_all_buttons();
11941282
this->progress_bar_load->reset();
11951283
}
1284+
1285+
void MainWindow::thread_abort(const QString& error) {
1286+
// clean up threads
1287+
if(this->readerthread) {
1288+
while(!this->readerthread->isFinished()) {}
1289+
this->readerthread.reset(); // delete object
1290+
}
1291+
1292+
if(this->flashthread) {
1293+
while(!this->flashthread->isFinished()) {}
1294+
this->flashthread.reset(); // delete object
1295+
}
1296+
1297+
if(this->cartridgereaderthread) {
1298+
while(!this->cartridgereaderthread->isFinished()) {}
1299+
this->cartridgereaderthread.reset(); // delete object
1300+
}
1301+
1302+
// throw error message
1303+
this->raise_error_window(QMessageBox::Critical,
1304+
"Operation terminated unexpectedly. Please carefully "
1305+
"check all settings and verify that the chip is "
1306+
"properly inserted into the socket."
1307+
"\n\nError message: " + error
1308+
);
1309+
}

gui/src/mainwindow.h

+12
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ class MainWindow : public QMainWindow
9292
QPushButton* button_flash_rom;
9393
QPushButton* button_flash_bank;
9494
QPushButton* button_scan_slots;
95+
QPushButton* button_reload_file;
9596

9697
// file data
9798
QString current_filename;
99+
bool current_file_expanded = false;
98100
std::unique_ptr<CartridgeReadThread> cartridgereaderthread;
99101
std::unique_ptr<ReadThread> readerthread;
100102
std::unique_ptr<FlashThread> flashthread;
@@ -178,6 +180,11 @@ private slots:
178180
*/
179181
void slot_open();
180182

183+
/**
184+
* @brief Reload a file
185+
*/
186+
void slot_reload_file();
187+
181188
/**
182189
* @brief Save a binary file
183190
*/
@@ -325,5 +332,10 @@ private slots:
325332
*/
326333
void verify_result_ready();
327334

335+
/****************************************************************************
336+
* SIGNALS :: OTHER
337+
****************************************************************************/
338+
void thread_abort(const QString& error);
339+
328340
};
329341
#endif // MAINWINDOW_H

gui/src/readthread.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ void ReadThread::run() {
4444
this->nr_banks = 512 / 16;
4545
break;
4646
default:
47-
throw std::runtime_error("Unknown chip suffix: " + std::to_string(chip_id));
47+
emit(thread_abort("Invalid suffix for chip id."));
48+
this->serial_interface->close_port();
49+
return;
4850
break;
4951
}
5052
} else {
51-
throw std::runtime_error("Unknown chip id: " + std::to_string(chip_id));
53+
std::string chip_id_str = tr("0x%1%2").arg((uint16_t)chip_id >> 8, 2, 16, QChar('0')).arg((uint8_t)chip_id & 0xFF, 2, 16, QChar('0')).toStdString();
54+
emit(thread_abort(tr("Unknown chip id: %1").arg(chip_id_str.c_str())));
55+
this->serial_interface->close_port();
56+
return;
5257
}
5358
}
5459

0 commit comments

Comments
 (0)