Skip to content

Commit

Permalink
gx: implement multi option word write multiple addresses.
Browse files Browse the repository at this point in the history
  • Loading branch information
grevaillot committed Apr 21, 2020
1 parent 45babea commit 4331206
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2974,29 +2974,32 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) {
static int stlink_write_option_bytes_gx(stlink_t *sl, uint8_t* base, stm32_addr_t addr, uint32_t len) {

uint32_t val;
uint32_t data;
int ret = 0;

/* Write options bytes */

while (len != 0) {
/* Write options bytes */
write_uint32((unsigned char*) &data, *(uint32_t*) (base));

WLOG("Writing option bytes %#10x to %#10x\n", data, addr);
stlink_write_debug32(sl, addr, data);

/* Write options bytes */
uint32_t data;
write_uint32((unsigned char*) &data, *(uint32_t*) (base));
WLOG("Writing option bytes %#10x to %#10x\n", data, addr);
//stlink_write_debug32(sl, addr, data);
stlink_write_debug32(sl, STM32Gx_FLASH_OPTR, data);
/* Set Options Start bit */
stlink_read_debug32(sl, STM32Gx_FLASH_CR, &val);
val |= (1 << STM32Gx_FLASH_CR_OPTSTRT);
stlink_write_debug32(sl, STM32Gx_FLASH_CR, val);

/* Set Options Start bit */
stlink_read_debug32(sl, STM32Gx_FLASH_CR, &val);
val |= (1 << STM32Gx_FLASH_CR_OPTSTRT);
stlink_write_debug32(sl, STM32Gx_FLASH_CR, val);
wait_flash_busy(sl);

/* Wait for 'busy' bit in FLASH_SR to clear. */
do {
stlink_read_debug32(sl, STM32Gx_FLASH_SR, &val);
} while ((val & (1 << STM32Gx_FLASH_SR_BSY)) != 0);
if ((ret = check_flash_error(sl)))
break;

check_flash_error(sl);
len-=4;
addr+=4;
base+=4;
}

/* Reload options */
stlink_read_debug32(sl, STM32Gx_FLASH_CR, &val);
Expand Down

0 comments on commit 4331206

Please sign in to comment.