Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/famicom-dumper-writer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-11-17 22:56:44 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2022-11-17 22:56:44 +0300
commit9a982cf3a5d66e06b80fa81b3738e792108fbc1a (patch)
tree79f23e4b64465d266961110c36316a267f701ada
parent9592793cf73e40ef716291a8b38b16430c1b62f4 (diff)
UNROM512 writing support, new version
-rw-r--r--STM32/Core/Inc/comm.h2
-rw-r--r--STM32/Core/Inc/dumper.h6
-rw-r--r--STM32/Core/Src/dumper.c145
-rw-r--r--STM32/Core/Src/main.c15
4 files changed, 143 insertions, 25 deletions
diff --git a/STM32/Core/Inc/comm.h b/STM32/Core/Inc/comm.h
index 6d5ba5b..d480467 100644
--- a/STM32/Core/Inc/comm.h
+++ b/STM32/Core/Inc/comm.h
@@ -52,6 +52,8 @@
#define COMMAND_FDS_DISK_WRITE_PROTECTED 57
#define COMMAND_FDS_BLOCK_CRC_ERROR 58
#define COMMAND_SET_COOLBOY_GPIO_MODE 59
+#define COMMAND_UNROM512_ERASE_REQUEST 60
+#define COMMAND_UNROM512_WRITE_REQUEST 61
#define COMMAND_BOOTLOADER 0xFE
#define COMMAND_DEBUG 0xFF
diff --git a/STM32/Core/Inc/dumper.h b/STM32/Core/Inc/dumper.h
index 36eb96b..f604cda 100644
--- a/STM32/Core/Inc/dumper.h
+++ b/STM32/Core/Inc/dumper.h
@@ -1,9 +1,9 @@
#ifndef _DUMPER_H_
#define _DUMPER_H_
-#define PROTOCOL_VERSION 4
+#define PROTOCOL_VERSION 5
#define FIRMWARE_VERSION_MAJOR 3
-#define FIRMWARE_VERSION_MINOR 0
+#define FIRMWARE_VERSION_MINOR 2
#define FIRMWARE_VERSION_SUFFIX 0
#define HARDWARE_VERSION_ADDRESS 0x08070000 - 2048
#define HARDWARE_VERSION ((volatile uint8_t*)(HARDWARE_VERSION_ADDRESS))
@@ -52,6 +52,8 @@ void read_chr_crc_send(uint16_t address, uint16_t len);
void write_chr(uint16_t address, uint16_t len, uint8_t *data);
void erase_flash_sector();
void write_flash(uint16_t address, uint16_t len, uint8_t *data);
+void erase_unrom512();
+void write_unrom512(uint32_t address, uint16_t len, uint8_t *data);
void fds_transfer(uint8_t block_read_start, uint8_t block_read_count, uint8_t block_write_count, uint8_t *block_write_ids, uint16_t *write_lengths, uint8_t *write_data);
void get_mirroring();
void set_coolboy_gpio_mode(uint8_t coolboy_gpio_mode);
diff --git a/STM32/Core/Src/dumper.c b/STM32/Core/Src/dumper.c
index 7187f12..276df9f 100644
--- a/STM32/Core/Src/dumper.c
+++ b/STM32/Core/Src/dumper.c
@@ -39,6 +39,7 @@ void reset(void)
void set_flash_buffer_size(uint16_t value)
{
// Set maximum number of bytes in multi-byte flash program
+ // 0 = disable multi-byte program
uint8_t bit_value = 0;
while (value > 1)
{
@@ -128,7 +129,7 @@ void erase_flash_sector()
PRG(0x8000 | 0x0000) = 0x30;
uint32_t start_time = HAL_GetTick();
-// waiting for result
+ // waiting for result
uint8_t ff_count = 0;
while (1)
{
@@ -161,11 +162,22 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *data)
uint16_t a = address;
uint16_t last_address = 0;
uint8_t last_data = 0;
- uint16_t address_base = a & flash_buffer_mask;
- while ((len > 0) && ((a & flash_buffer_mask) == address_base))
+ if (flash_buffer_mask != 0xFFFF)
{
+ // multi-byte program
+ uint16_t address_base = a & flash_buffer_mask;
+ while ((len > 0) && ((a & flash_buffer_mask) == address_base))
+ {
+ if (*d != 0xFF)
+ count++;
+ a++;
+ len--;
+ d++;
+ }
+ } else {
+ // single-byte program
if (*d != 0xFF)
- count++;
+ count = 1;
a++;
len--;
d++;
@@ -173,27 +185,41 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *data)
if (count)
{
- PRG(0x8000 | 0x0000) = 0xF0;
- PRG(0x8000 | 0x0AAA) = 0xAA;
- PRG(0x8000 | 0x0555) = 0x55;
- PRG(0x8000 | 0x0000) = 0x25;
- PRG(0x8000 | 0x0000) = count - 1;
-
- while (count > 0)
+ if (count > 0)
{
- if (*data != 0xFF)
+ // multi-byte
+ PRG(0x8000 | 0x0000) = 0xF0;
+ PRG(0x8000 | 0x0AAA) = 0xAA;
+ PRG(0x8000 | 0x0555) = 0x55;
+ PRG(0x8000 | 0x0000) = 0x25;
+ PRG(0x8000 | 0x0000) = count - 1;
+ while (count > 0)
{
- PRG(0x8000 | address) = *data;
- last_address = address;
- last_data = *data;
- count--;
+ if (*data != 0xFF)
+ {
+ PRG(0x8000 | address) = *data;
+ last_address = address;
+ last_data = *data;
+ count--;
+ }
+ address++;
+ data++;
}
+ PRG(0x8000 + 0x0000) = 0x29;
+ } else {
+ // single-byte
+ PRG(0x8000 | 0x0000) = 0xF0;
+ PRG(0x8000 | 0x0AAA) = 0xAA;
+ PRG(0x8000 | 0x0555) = 0x55;
+ PRG(0x8000 | 0x0AAA) = 0xA0;
+ PRG(0x8000 | address) = *data;
+ last_address = address;
+ last_data = *data;
+ count--;
address++;
data++;
}
- PRG(0x8000 + 0x0000) = 0x29;
-
uint32_t start_time = HAL_GetTick();
// waiting for result
while (1)
@@ -228,8 +254,7 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *data)
{
read_1 = PRG(0x8000 | last_address);
read_2 = PRG(0x8000 | last_address);
- if (read_1 == read_2 && read_2 == last_data)
- break; // OK
+ if ((read_1 == read_2) && (read_2 == last_data)) break; // OK
}
}
}
@@ -240,6 +265,85 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *data)
comm_start(COMMAND_PRG_WRITE_DONE, 0);
}
+void unrom512_cmd_write(uint32_t address, uint8_t data)
+{
+ PRG(0xC000) = address >> 14;
+ PRG(0x8000 | (address & 0x3FFF)) = data;
+}
+
+uint8_t unrom512_cmd_read(uint32_t address)
+{
+ PRG(0xC000) = address >> 14;
+ return PRG(0x8000 | (address & 0x3FFF));
+}
+
+void erase_unrom512()
+{
+ led_yellow();
+ unrom512_cmd_write(0x0000, 0xF0);
+ unrom512_cmd_write(0x5555, 0xAA);
+ unrom512_cmd_write(0x2AAA, 0x55);
+ unrom512_cmd_write(0x5555, 0x80);
+ unrom512_cmd_write(0x5555, 0xAA);
+ unrom512_cmd_write(0x2AAA, 0x55);
+ unrom512_cmd_write(0x5555, 0x10);
+
+ uint32_t start_time = HAL_GetTick();
+ // waiting for result
+ uint8_t ff_count = 0;
+ while (1)
+ {
+ if (HAL_GetTick() >= start_time + 5000) // 5 seconds timeout
+ {
+ // timeout
+ comm_start(COMMAND_FLASH_ERASE_TIMEOUT, 0);
+ break;
+ }
+ if (PRG(0x8000) != 0xFF)
+ ff_count = 0;
+ else
+ ff_count++;
+ if (ff_count >= 2)
+ {
+ // OK
+ comm_start(COMMAND_PRG_WRITE_DONE, 0);
+ break;
+ }
+ }
+}
+
+void write_unrom512(uint32_t address, uint16_t len, uint8_t *data)
+{
+ led_red();
+ PRG(0x8000 | 0x0000) = 0xF0;
+ while (len > 0)
+ {
+ unrom512_cmd_write(0x5555, 0xAA);
+ unrom512_cmd_write(0x2AAA, 0x55);
+ unrom512_cmd_write(0x5555, 0xA0);
+ unrom512_cmd_write(address, *data);
+
+ uint32_t start_time = HAL_GetTick();
+ // waiting for result
+ while (1)
+ {
+ if (HAL_GetTick() >= start_time + 50) // 50 ms timeout
+ {
+ // timeout
+ comm_start(COMMAND_FLASH_WRITE_TIMEOUT, 0);
+ return;
+ }
+ uint8_t read_1 = unrom512_cmd_read(address);
+ uint8_t read_2 = unrom512_cmd_read(address);
+ if ((read_1 == read_2) && (read_2 == *data)) break; // OK
+ }
+ address++;
+ data++;
+ len--;
+ }
+ comm_start(COMMAND_PRG_WRITE_DONE, 0);
+}
+
static uint8_t transfer_fds_byte(uint8_t *output, uint8_t input, uint8_t *end_of_head)
{
uint32_t start_time;
@@ -586,7 +690,6 @@ void get_mirroring()
comm_send_byte(HAL_GPIO_ReadPin(CIRAM_A10_GPIO_Port, CIRAM_A10_Pin));
}
-
void set_coolboy_gpio_mode(uint8_t coolboy_gpio_mode)
{
if (coolboy_gpio_mode)
diff --git a/STM32/Core/Src/main.c b/STM32/Core/Src/main.c
index 37b5d0e..8ca37b4 100644
--- a/STM32/Core/Src/main.c
+++ b/STM32/Core/Src/main.c
@@ -136,6 +136,7 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint16_t address;
+ uint32_t address32;
uint16_t length;
led_blue();
@@ -153,8 +154,8 @@ int main(void)
comm_send_byte(PROTOCOL_VERSION);
comm_send_byte(0xFF);
comm_send_byte(0xFF); // unlimited send buffer
- comm_send_byte((RECV_BUFFER_SIZE - 5) & 0xFF);
- comm_send_byte(((RECV_BUFFER_SIZE - 5) >> 8) & 0xFF);
+ comm_send_byte((RECV_BUFFER_SIZE - 8) & 0xFF);
+ comm_send_byte(((RECV_BUFFER_SIZE - 8) >> 8) & 0xFF);
comm_send_byte(FIRMWARE_VERSION_MAJOR & 0xFF);
comm_send_byte((FIRMWARE_VERSION_MAJOR >> 8) & 0xFF);
comm_send_byte(FIRMWARE_VERSION_MINOR);
@@ -210,6 +211,16 @@ int main(void)
write_flash(address, length, (uint8_t*) &recv_buffer[4]);
break;
+ case COMMAND_UNROM512_ERASE_REQUEST:
+ erase_unrom512();
+ break;
+
+ case COMMAND_UNROM512_WRITE_REQUEST:
+ address32 = recv_buffer[0] | ((uint32_t) recv_buffer[1] << 8) | ((uint32_t) recv_buffer[2] << 16) | ((uint32_t) recv_buffer[3] << 24);
+ length = recv_buffer[4] | ((uint16_t) recv_buffer[5] << 8);
+ write_unrom512(address32, length, (uint8_t*) &recv_buffer[6]);
+ break;
+
case COMMAND_CHR_INIT:
comm_start(COMMAND_CHR_STARTED, 0);
break;