Skip to content

Commit

Permalink
Fix for option byte read (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightwalker-87 committed Jan 2, 2023
1 parent 2a8a36e commit 405141e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions config/chips/F401xD_xE.chip
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ flash_pagesize 0x4000 // 16 KB
sram_size 0x18000 // 96 KB
bootrom_base 0x1fff0000
bootrom_size 0x7800 // 30 KB
option_base 0x40023C14
option_size 0x4
option_base 0x40023C14 // STM32_F4_OPTION_BYTES_BASE
option_size 0x4 // 4 B
flags swo
2 changes: 1 addition & 1 deletion config/chips/F446.chip
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ sram_size 0x20000 // 128 KB
bootrom_base 0x1fff0000
bootrom_size 0x7800 // 30 KB
option_base 0x40023c14 // STM32_F4_OPTION_BYTES_BASE
option_size 0x4 // 4 B
option_size 0x10 // 16 B
flags swo
28 changes: 16 additions & 12 deletions src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,25 @@ int main(int ac, char** av) {
(unsigned)remaining_option_length,
sl->option_base);

if (NULL != o.filename) {
if (0 == o.size) {
o.size = sl->option_size;
}
err = stlink_fread(sl, o.filename, o.format == FLASH_FORMAT_IHEX, sl->option_base, o.size);
} else {
uint32_t option_byte = 0;
err = stlink_read_option_bytes32(sl, &option_byte);
if (err == -1) {
printf("could not read option bytes (%d)\n", err);
uint32_t option_byte = 0;
err = stlink_read_option_bytes32(sl, &option_byte);
if (err == -1) {
printf("could not read option bytes (%d)\n", err);
goto on_error;
} else if (NULL != o.filename) {
// if (0 == o.size) { o.size = sl->option_size; }
// err = stlink_fread(sl, o.filename, o.format == FLASH_FORMAT_IHEX, sl->option_base, o.size);
int fd = open(o.filename, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
if (fd == -1) {
fprintf(stderr, "open(%s) == -1\n", o.filename);
goto on_error;
} else {
printf("%08x\n", option_byte);
}
write(fd, option_byte, 4);
close(fd);
} else {
printf("%08x\n", option_byte);
}

} else if (o.area == FLASH_OPTION_BYTES_BOOT_ADD) {
uint32_t option_byte = 0;
err = stlink_read_option_bytes_boot_add32(sl, &option_byte);
Expand Down
9 changes: 3 additions & 6 deletions src/stlink-lib/option_bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ static int stlink_write_option_bytes_f4(stlink_t *sl, stm32_addr_t addr, uint8_t
int stlink_read_option_bytes_f7(stlink_t *sl, uint32_t *option_byte) {
int err = -1;
for (uint32_t counter = 0; counter < (sl->option_size / 4 - 1); counter++) {
err = stlink_read_debug32(sl, sl->option_base + counter * sizeof(uint32_t),
option_byte);
err = stlink_read_debug32(sl, sl->option_base + counter * sizeof(uint32_t), option_byte);
if (err == -1) {
return err;
} else {
Expand Down Expand Up @@ -272,8 +271,7 @@ static int stlink_write_option_bytes_f7(stlink_t *sl, stm32_addr_t addr, uint8_t
// Clear errors
clear_flash_error(sl);

ILOG("Asked to write option byte %#10x to %#010x.\n", *(uint32_t *)(base),
addr);
ILOG("Asked to write option byte %#10x to %#010x.\n", *(uint32_t *)(base), addr);
write_uint32((unsigned char *)&option_byte, *(uint32_t *)(base));
ILOG("Write %d option bytes %#010x to %#010x!\n", len, option_byte, addr);

Expand Down Expand Up @@ -306,8 +304,7 @@ static int stlink_write_option_bytes_f7(stlink_t *sl, stm32_addr_t addr, uint8_t

ret = check_flash_error(sl);
if (!ret)
ILOG("Wrote %d option bytes %#010x to %#010x!\n", len, *(uint32_t *)base,
addr);
ILOG("Wrote %d option bytes %#010x to %#010x!\n", len, *(uint32_t *)base, addr);

/* option bytes are reloaded at reset only, no obl. */

Expand Down

0 comments on commit 405141e

Please sign in to comment.