From a9697dd956af0f757f2a5ce8463f047525481e64 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 11 Feb 2023 05:52:53 +0000 Subject: [PATCH] stm32f1: Modified the Flash routines to work with GD32VF103 parts too --- src/target/stm32f1.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/target/stm32f1.c b/src/target/stm32f1.c index 48c34e98ed6..46f651959cd 100644 --- a/src/target/stm32f1.c +++ b/src/target/stm32f1.c @@ -41,6 +41,7 @@ #include "target.h" #include "target_internal.h" #include "cortexm.h" +#include "jep106.h" static bool stm32f1_cmd_option(target_s *target, int argc, const char **argv); @@ -640,7 +641,11 @@ static bool stm32f1_flash_write(target_flash_s *flash, target_addr_t dest, const stm32f1_flash_clear_eop(target, FLASH_BANK1_OFFSET); target_mem_write32(target, FLASH_CR, FLASH_CR_PG); - cortexm_mem_write_sized(target, dest, src, offset, ALIGN_16BIT); + /* Use the target API instead of a direct Cortex-M call for GD32VF103 parts */ + if (target->designer_code == JEP106_MANUFACTURER_RV_GIGADEVICE && target->cpuid == 0x80000022U) + target_mem_write(target, dest, src, offset); + else + cortexm_mem_write_sized(target, dest, src, offset, ALIGN_16BIT); /* Wait for completion or an error */ if (!stm32f1_flash_busy_wait(target, FLASH_BANK1_OFFSET, NULL)) @@ -654,7 +659,11 @@ static bool stm32f1_flash_write(target_flash_s *flash, target_addr_t dest, const stm32f1_flash_clear_eop(target, FLASH_BANK2_OFFSET); target_mem_write32(target, FLASH_CR + FLASH_BANK2_OFFSET, FLASH_CR_PG); - cortexm_mem_write_sized(target, dest + offset, data + offset, remainder, ALIGN_16BIT); + /* Use the target API instead of a direct Cortex-M call for GD32VF103 parts */ + if (target->designer_code == JEP106_MANUFACTURER_RV_GIGADEVICE && target->cpuid == 0x80000022U) + target_mem_write(target, dest + offset, data + offset, remainder); + else + cortexm_mem_write_sized(target, dest + offset, data + offset, remainder, ALIGN_16BIT); /* Wait for completion or an error */ if (!stm32f1_flash_busy_wait(target, FLASH_BANK2_OFFSET, NULL))