Skip to content

Commit

Permalink
stm32f1: Modified the Flash routines to work with GD32VF103 parts too
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmux authored and esden committed Oct 31, 2023
1 parent 903b005 commit a9697dd
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/target/stm32f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down

0 comments on commit a9697dd

Please sign in to comment.