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>2023-01-19 13:49:28 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2023-01-19 13:49:28 +0300
commitd69051f3bef6d236c9802d3a9ced5f53e8a7ead3 (patch)
tree8ab21dca116d6e36ac0c4ca41bbfd2e79a9ed148
parent90ea5498625b436e6fe01cf0ba0ce720f16e5359 (diff)
Critical flash writing fixes
-rw-r--r--STM32/Core/Src/flash.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/STM32/Core/Src/flash.c b/STM32/Core/Src/flash.c
index 6bcd682..8c35eee 100644
--- a/STM32/Core/Src/flash.c
+++ b/STM32/Core/Src/flash.c
@@ -56,6 +56,7 @@ void erase_flash_sector()
void write_flash(uint16_t address, uint16_t len, uint8_t *data)
{
led_red();
+ PRG(0x8000 | 0x0000) = 0xF0; // reset flash
while (len > 0)
{
uint16_t count = 0;
@@ -89,15 +90,15 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *data)
if (count > 1)
{
// 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)
+ while (count)
{
if (*data != 0xFF)
{
+ PRG(0x8000 | address) = *data;
last_address = address;
last_data = *data;
count--;
@@ -108,16 +109,21 @@ void write_flash(uint16_t address, uint16_t len, uint8_t *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++;
+ while (count)
+ {
+ if (*data != 0xFF)
+ {
+ 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++;
+ }
}
uint32_t start_time = HAL_GetTick();