Skip to content

Commit 87b9082

Browse files
authored
Patch 1.3.0 (#9)
* Adding button to completely erase a chip * Expanding README.md
1 parent e28d3d3 commit 87b9082

11 files changed

+160
-2
lines changed

firmware/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,6 @@ of commands are given below.
6060
a CRC16 XMODEM checksum (2 bytes).
6161
* `ESSTXXXX`: Erases a block of data (writing `0xFF`) at hex position `XXXX000`.
6262
Returns number of wait cycles as 16 bit signed integer.
63+
* `ERASEALL`: Completely wipes the chip, writing `0xFF` to all bytes.
6364
* `TESTTEST`: Simple test routine. Reads the first 32 bytes on the chip. Returns
6465
32 bytes of data.

firmware/constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ GPIO19 - LOAD for A16-A19
4444
#define DELAY_READ 5
4545
#define DELAY_WRITE 5
4646
#define DELAY_ADDR 4
47-
#define BOARD_ID "PICOSST39-v1.1.0"
47+
#define BOARD_ID "PICOSST39-v1.3.0"
4848

4949
#endif

firmware/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ void parse_instructions() {
108108
read_chip_id();
109109
return;
110110
/*
111+
* Completely erase the chip
112+
*/
113+
} else if(check_command(instruction, "ERASEALL", 0, 8)) {
114+
erase_chip();
115+
return;
116+
/*
111117
* Read data from P2000 SLOT1 cartridge, requiring adapter board
112118
*/
113119
} else if(check_command(instruction, "RP2KCR", 0, 6)) {

firmware/routines.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,30 @@ void write_block(uint32_t block_id) {
304304
putchar_raw(checksum);
305305
}
306306

307+
/**
308+
* @brief Erase the complete chip
309+
*/
310+
void erase_chip() {
311+
gpio_put(LED_WR, true);
312+
313+
// chip-erase sequence
314+
write_byte(0x5555, 0xAA);
315+
write_byte(0x2AAA, 0x55);
316+
write_byte(0x5555, 0x80);
317+
write_byte(0x5555, 0xAA);
318+
write_byte(0x2AAA, 0x55);
319+
write_byte(0x5555, 0x10);
320+
321+
// get number of iterations in pollbyte routine
322+
uint16_t cnts = pollbyte(0x0000);
323+
324+
gpio_put(LED_WR, false);
325+
326+
// return result
327+
putchar_raw(cnts >> 8);
328+
putchar_raw(cnts & 0xFF);
329+
}
330+
307331
/*
308332
* @brief Erase sector (4kb)
309333
*/

firmware/routines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ uint16_t pollbyte(uint32_t addr);
7272
*/
7373
void write_block(uint32_t block_id);
7474

75+
/**
76+
* @brief Erase the complete chip
77+
*/
78+
void erase_chip();
79+
7580
/**
7681
* Erase sector (4kb)
7782
*/

gui/src/config.h

Lines changed: 1 addition & 1 deletion
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.2.0"
25+
#define PROGRAM_VERSION "1.3.0"
2626

2727
#define UNUSED(x) (void)(x)
2828

gui/src/mainwindow.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ void MainWindow::build_operations_menu(QVBoxLayout* target_layout) {
269269

270270
// add individual buttons here
271271
this->button_identify_chip = new QPushButton("Identify chip");
272+
this->button_erase_chip = new QPushButton("Erase chip");
272273
this->button_read_rom = new QPushButton("Read ROM");
273274
this->button_read_cartridge = new QPushButton("Read P2000T Cartridge");
274275
this->button_flash_rom = new QPushButton("Write ROM");
@@ -279,8 +280,10 @@ void MainWindow::build_operations_menu(QVBoxLayout* target_layout) {
279280
layout->addWidget(this->button_read_cartridge);
280281
layout->addWidget(this->button_flash_rom);
281282
layout->addWidget(this->button_flash_bank);
283+
layout->addWidget(this->button_erase_chip);
282284

283285
this->button_identify_chip->setEnabled(false);
286+
this->button_erase_chip->setEnabled(false);
284287
this->button_read_cartridge->setEnabled(false);
285288
this->button_read_rom->setEnabled(false);
286289
this->button_flash_rom->setEnabled(false);
@@ -291,6 +294,7 @@ void MainWindow::build_operations_menu(QVBoxLayout* target_layout) {
291294
connect(this->button_flash_rom, SIGNAL(released()), this, SLOT(flash_rom()));
292295
connect(this->button_identify_chip, SIGNAL(released()), this, SLOT(read_chip_id()));
293296
connect(this->button_flash_bank, SIGNAL(released()), this, SLOT(flash_bank()));
297+
connect(this->button_erase_chip, SIGNAL(released()), this, SLOT(erase_chip()));
294298

295299
target_layout->addWidget(container);
296300
this->progress_bar_load = new QProgressBar();
@@ -697,6 +701,7 @@ void MainWindow::read_chip_id() {
697701
this->button_read_rom->setEnabled(true);
698702
this->button_flash_rom->setEnabled(true);
699703
this->button_flash_bank->setEnabled(true);
704+
this->button_erase_chip->setEnabled(true);
700705
} catch (const std::exception& e) {
701706
QMessageBox msg_box;
702707
msg_box.setIcon(QMessageBox::Warning);
@@ -909,6 +914,23 @@ void MainWindow::flash_bank() {
909914
//this->disable_all_buttons();
910915
}
911916

917+
/**
918+
* @brief Put rom on flash cartridge
919+
*/
920+
void MainWindow::erase_chip() {
921+
QMessageBox::StandardButton reply;
922+
reply = QMessageBox::question(this, "Wipe chip?", "Are you sure you want to completely wipe the chip?", QMessageBox::Yes|QMessageBox::No);
923+
if (reply != QMessageBox::Yes) {
924+
return;
925+
}
926+
927+
this->serial_interface->open_port();
928+
this->serial_interface->erase_chip();
929+
this->serial_interface->close_port();
930+
931+
QMessageBox::information(this, "Chip erased.", "Done erasing the chip. All bytes are set of 0xFF.");
932+
}
933+
912934
/**
913935
* @brief Slot to indicate that a sector is about to be written
914936
*/

gui/src/mainwindow.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class MainWindow : public QMainWindow
7777
// buttons
7878
QLabel* label_chip_type;
7979
QPushButton* button_identify_chip;
80+
QPushButton* button_erase_chip;
8081
QPushButton* button_read_rom;
8182
QPushButton* button_read_cartridge;
8283
QPushButton* button_flash_rom;
@@ -245,6 +246,11 @@ private slots:
245246
*/
246247
void flash_bank();
247248

249+
/**
250+
* @brief Erase the chip
251+
*/
252+
void erase_chip();
253+
248254
/**
249255
* @brief Slot to indicate that a page is about to be written
250256
*/

gui/src/serial_interface.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@ uint16_t SerialInterface::get_chip_id() {
265265

266266
}
267267

268+
/**
269+
* @brief Completely erase the chip
270+
*/
271+
void SerialInterface::erase_chip() {
272+
try {
273+
std::string command = "ERASEALL";
274+
auto response = this->send_command_capture_response(command, 2);
275+
} catch (std::exception& e) {
276+
std::cerr << "Caught error: " << e.what() << std::endl;
277+
throw e;
278+
}
279+
}
280+
268281
/********************************************************
269282
* PRIVATE ROUTINES
270283
********************************************************/

gui/src/serial_interface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ class SerialInterface {
141141
*/
142142
uint16_t get_chip_id();
143143

144+
/**
145+
* @brief Completely erase the chip
146+
*/
147+
void erase_chip();
148+
144149
private:
145150

146151
/**

scripts/erase-test.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
import serial
5+
import serial.tools.list_ports
6+
import numpy as np
7+
8+
def read_rom(filename):
9+
f = open(filename, 'rb')
10+
data = bytearray(f.read())
11+
f.close()
12+
return data
13+
14+
#
15+
# Test board functionality
16+
#
17+
class TestBoard(unittest.TestCase):
18+
19+
def setUp(self):
20+
# autofind any available boards
21+
ports = serial.tools.list_ports.comports()
22+
portfound = None
23+
for port in ports:
24+
if port.pid == 0x0A and port.vid == 0x2E8A:
25+
portfound = port.device
26+
break
27+
28+
# specify the COM port below
29+
if portfound:
30+
self.ser = serial.Serial(portfound,
31+
19200,
32+
bytesize=serial.EIGHTBITS,
33+
parity=serial.PARITY_NONE,
34+
stopbits=serial.STOPBITS_ONE,
35+
timeout=None) # open serial port
36+
37+
while(not self.ser.isOpen()):
38+
self.ser.open()
39+
else:
40+
raise Exception('Cannot find suitable port connection')
41+
42+
def teardDown(self):
43+
while(not self.ser.isClosed()):
44+
self.ser.close()
45+
46+
def test_board_id(self):
47+
"""
48+
Test reading board id
49+
"""
50+
self.ser.write(b'READINFO')
51+
rsp = self.ser.read(8)
52+
rsp = self.ser.read(16)
53+
print(rsp)
54+
self.assertEqual(rsp[0:4], b'PICO')
55+
56+
def test_device_id(self):
57+
"""
58+
Test reading board id
59+
"""
60+
self.ser.write(b'DEVIDSST')
61+
rsp = self.ser.read(8)
62+
rsp = self.ser.read(2)
63+
#print(' '.join('0x%02X' % d for d in rsp))
64+
self.assertEqual(rsp, bytearray([0xBF,0xB7]))
65+
66+
def test_erase(self):
67+
"""
68+
Test erasing of sector on board
69+
"""
70+
self.ser.write(b'ERASEALL')
71+
rsp = self.ser.read(8)
72+
rsp = self.ser.read(2) # read pollbyte count
73+
print(' '.join('0x%02X' % d for d in rsp))
74+
75+
if __name__ == '__main__':
76+
unittest.main()

0 commit comments

Comments
 (0)