Skip to content

Commit

Permalink
Revert changing all compiler warning preventions
Browse files Browse the repository at this point in the history
  • Loading branch information
rutgerhendriks committed Jul 6, 2020
1 parent bda20cf commit e273ec5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
48 changes: 23 additions & 25 deletions src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ static void cleanup(int signum) {
exit(1);
}

static void usage(void)
{
static void usage(void) {
puts("command line: ./st-flash [--debug] [--reset] [--opt] [--serial <serial>] [--format <format>] [--flash=<fsize>] [--freq=<Hz>] [--area=<area>] {read|write} [path] [addr] [size]");
puts("command line: ./st-flash [--debug] [--freq=<Hz>] [--serial <serial>] erase");
puts("command line: ./st-flash [--debug] [--freq=<Hz>] [--serial <serial>] reset");
Expand Down Expand Up @@ -60,13 +59,13 @@ int main(int ac, char** av) {
return(-1);
}

ILOG("st-flash %s\n", STLINK_VERSION);
printf("st-flash %s\n", STLINK_VERSION);

sl = stlink_open_usb(o.log_level, 1, (char *)o.serial, o.freq);

if (sl == NULL) { return(-1); }

if (STLINK_FLASH_TYPE_UNKNOWN == sl->flash_type) {
if (sl->flash_type == STLINK_FLASH_TYPE_UNKNOWN) {
printf("Failed to connect to target\n");
return(-1);
}
Expand All @@ -84,14 +83,14 @@ int main(int ac, char** av) {
signal(SIGTERM, &cleanup);
signal(SIGSEGV, &cleanup);

if (STLINK_DEV_DFU_MODE == stlink_current_mode(sl)) {
if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
if (stlink_exit_dfu_mode(sl)) {
printf("Failed to exit DFU mode\n");
goto on_error;
}
}

if (STLINK_DEV_DEBUG_MODE != stlink_current_mode(sl)) {
if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
if (stlink_enter_swd_mode(sl)) {
printf("Failed to enter SWD mode\n");
goto on_error;
Expand All @@ -113,7 +112,7 @@ int main(int ac, char** av) {
}

// disable DMA - Set All DMA CCR Registers to zero. - AKS 1/7/2013
if (STLINK_CHIPID_STM32_F4 == sl->chip_id) {
if (sl->chip_id == STLINK_CHIPID_STM32_F4) {
memset(sl->q_buf, 0, 4);

for (int i = 0; i < 8; i++) {
Expand All @@ -136,10 +135,9 @@ int main(int ac, char** av) {
goto on_error;
}

if (FLASH_CMD_WRITE == o.cmd) // write
{
if (o.cmd == FLASH_CMD_WRITE) { // write
size_t size = 0;
if (FLASH_FORMAT_IHEX == o.format) {
if (o.format == FLASH_FORMAT_IHEX) {
err = stlink_parse_ihex(o.filename, stlink_get_erased_pattern(sl), &mem, &size, &o.addr);

if (err == -1) {
Expand All @@ -149,7 +147,7 @@ int main(int ac, char** av) {
}
if ((o.addr >= sl->flash_base) &&
(o.addr < sl->flash_base + sl->flash_size)) {
if (FLASH_FORMAT_IHEX == o.format) {
if (o.format == FLASH_FORMAT_IHEX) {
err = stlink_mwrite_flash(sl, mem, (uint32_t)size, o.addr);
} else {
err = stlink_fwrite_flash(sl, o.filename, o.addr);
Expand All @@ -161,7 +159,7 @@ int main(int ac, char** av) {
}
} else if ((o.addr >= sl->sram_base) &&
(o.addr < sl->sram_base + sl->sram_size)) {
if (FLASH_FORMAT_IHEX == o.format) {
if (o.format == FLASH_FORMAT_IHEX) {
err = stlink_mwrite_sram(sl, mem, (uint32_t)size, o.addr);
} else {
err = stlink_fwrite_sram(sl, o.filename, o.addr);
Expand All @@ -179,7 +177,7 @@ int main(int ac, char** av) {
printf("stlink_fwrite_option_bytes() == -1\n");
goto on_error;
}
} else if (FLASH_OPTION_BYTES == o.area) {
} else if (o.area == FLASH_OPTION_BYTES) {
if (o.val == 0) {
printf("attempting to set option byte to 0, abort.\n");
goto on_error;
Expand All @@ -191,15 +189,15 @@ int main(int ac, char** av) {
printf("stlink_write_option_bytes32() == -1\n");
goto on_error;
}
} else if (FLASH_OPTCR == o.area) {
} else if (o.area == FLASH_OPTCR) {
DLOG("@@@@ Write %d (%0#10x) to option control register\n", o.val, o.val);

err = stlink_write_option_control_register32(sl, o.val);
} else if (FLASH_OPTCR1 == o.area) {
} else if (o.area == FLASH_OPTCR1) {
DLOG("@@@@ Write %d (%0#10x) to option control register 1\n", o.val, o.val);

err = stlink_write_option_control_register1_32(sl, o.val);
} else if (FLASH_OPTION_BYTES_BOOT_ADD == o.area) {
} else if (o.area == FLASH_OPTION_BYTES_BOOT_ADD) {
DLOG("@@@@ Write %d (%0#10x) to option bytes boot address\n", o.val, o.val);

err = stlink_write_option_bytes_boot_add32(sl, o.val);
Expand All @@ -208,14 +206,14 @@ int main(int ac, char** av) {
printf("Unknown memory region\n");
goto on_error;
}
} else if (FLASH_CMD_ERASE == o.cmd) {
} else if (o.cmd == FLASH_CMD_ERASE) {
err = stlink_erase_flash_mass(sl);

if (err == -1) {
printf("stlink_erase_flash_mass() == -1\n");
goto on_error;
}
} else if (CMD_RESET == o.cmd) {
} else if (o.cmd == CMD_RESET) {
if (sl->version.stlink_v > 1) {
if (stlink_jtag_reset(sl, 2)) {
printf("Failed to reset JTAG\n");
Expand All @@ -228,28 +226,28 @@ int main(int ac, char** av) {
goto on_error;
}
} else { // read
if ((FLASH_MAIN_MEMORY == o.area) || (FLASH_SYSTEM_MEMORY == o.area)) {
if ((o.area == FLASH_MAIN_MEMORY) || (o.area == FLASH_SYSTEM_MEMORY)) {
if ((o.size == 0) && (o.addr >= sl->flash_base) && (o.addr < sl->flash_base + sl->flash_size)) {
o.size = sl->flash_size;
}
else if ((o.size == 0) && (o.addr >= sl->sram_base) && (o.addr < sl->sram_base + sl->sram_size)) {
o.size = sl->sram_size;
}
err = stlink_fread(sl, o.filename, FLASH_FORMAT_IHEX == o.format, o.addr, o.size);
err = stlink_fread(sl, o.filename, o.format == FLASH_FORMAT_IHEX, o.addr, o.size);

if (err == -1) {
printf("stlink_fread() == -1\n");
goto on_error;
}
} else if (FLASH_OPTION_BYTES == o.area) {
} else if (o.area == FLASH_OPTION_BYTES) {
uint8_t remaining_option_length = sl->option_size / 4;
DLOG("@@@@ Read %d (%#x) option bytes from %#10x\n", remaining_option_length, 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, FLASH_FORMAT_IHEX == o.format, sl->option_base, o.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);
Expand All @@ -260,7 +258,7 @@ int main(int ac, char** av) {
printf("%08x\n", option_byte);
}
}
} else if (FLASH_OPTION_BYTES_BOOT_ADD == o.area) {
} else if (o.area == FLASH_OPTION_BYTES_BOOT_ADD) {
uint32_t option_byte = 0;
err = stlink_read_option_bytes_boot_add32(sl, &option_byte);
if (err == -1) {
Expand All @@ -269,7 +267,7 @@ int main(int ac, char** av) {
} else {
printf("%08x\n",option_byte);
}
} else if (FLASH_OPTCR == o.area) {
} else if (o.area == FLASH_OPTCR) {
uint32_t option_byte = 0;
err = stlink_read_option_control_register32(sl, &option_byte);
if (err == -1) {
Expand All @@ -278,7 +276,7 @@ int main(int ac, char** av) {
} else {
printf("%08x\n",option_byte);
}
} else if (FLASH_OPTCR1 == o.area) {
} else if (o.area == FLASH_OPTCR1) {
uint32_t option_byte = 0;
err = stlink_read_option_control_register1_32(sl, &option_byte);
if (err == -1) {
Expand Down
22 changes: 11 additions & 11 deletions src/st-flash/flash_opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
break;

case FLASH_CMD_READ: // expect filename, addr and size
if ((FLASH_MAIN_MEMORY == o->area) || (FLASH_SYSTEM_MEMORY == o->area)) {
if ((o->area == FLASH_MAIN_MEMORY) || (o->area == FLASH_SYSTEM_MEMORY)) {
if (ac != 3) { return invalid_args("read <path> <addr> <size>"); }

o->filename = av[0];
Expand All @@ -295,12 +295,12 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}

break;
} else if ((FLASH_OTP == o->area)) {
} else if ((o->area == FLASH_OTP)) {
return bad_arg("TODO: otp not implemented yet");
if (ac > 1) { return invalid_args("otp read: [path]"); }
if (ac > 0) { o->filename = av[0]; }
break;
} else if ((FLASH_OPTION_BYTES == o->area)) {
} else if ((o->area == FLASH_OPTION_BYTES)) {
if (ac > 2) { return invalid_args("option bytes read: [path] [size]"); }
if (ac > 0) { o->filename = av[0]; }
if (ac > 1) {
Expand All @@ -313,13 +313,13 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
}
}
break;
} else if ((FLASH_OPTION_BYTES_BOOT_ADD == o->area)) {
} else if ((o->area == FLASH_OPTION_BYTES_BOOT_ADD)) {
if (ac > 0) { return invalid_args("option bytes boot_add read"); }
break;
} else if ((FLASH_OPTCR == o->area)) {
} else if ((o->area == FLASH_OPTCR)) {
if (ac > 0) { return invalid_args("option control register read"); }
break;
} else if ((FLASH_OPTCR1 == o->area)) {
} else if ((o->area == FLASH_OPTCR1)) {
if (ac > 0) { return invalid_args("option control register 1 read"); }
break;
}
Expand All @@ -328,7 +328,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {

case FLASH_CMD_WRITE:
// TODO: should be boot add 0 and boot add 1 uint32
if (FLASH_OPTION_BYTES == o->area) { // expect filename and optional address
if (o->area == FLASH_OPTION_BYTES) { // expect filename and optional address
if (ac >=1 && ac <= 2) {
o->filename = av[0];
} else {
Expand All @@ -344,7 +344,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
o->addr = (stm32_addr_t) addr;
}
}
} else if (FLASH_OPTION_BYTES_BOOT_ADD == o->area) { // expect option bytes boot address
} else if (o->area == FLASH_OPTION_BYTES_BOOT_ADD) { // expect option bytes boot address
if (ac != 1) { return invalid_args("option bytes boot_add write <value>"); }

uint32_t val;
Expand All @@ -355,7 +355,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
} else {
o->val = (uint32_t)val;
}
} else if (FLASH_OPTCR == o->area) { // expect option control register value
} else if (o->area == FLASH_OPTCR) { // expect option control register value
if (ac != 1) { return invalid_args("option control register write <value>"); }

uint32_t val;
Expand All @@ -366,7 +366,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
} else {
o->val = (uint32_t) val;
}
} else if (FLASH_OPTCR1 == o->area) { // expect option control register 1 value
} else if (o->area == FLASH_OPTCR1) { // expect option control register 1 value
if (ac != 1) { return invalid_args("option control register 1 write <value>"); }

uint32_t val;
Expand All @@ -376,7 +376,7 @@ int flash_get_opts(struct flash_opts* o, int ac, char** av) {
} else {
o->val = (uint32_t) val;
}
} else if (FLASH_FORMAT_BINARY == o->format) { // expect filename and addr
} else if (o->format == FLASH_FORMAT_BINARY) { // expect filename and addr
if (ac != 2) { return invalid_args("write <path> <addr>"); }

o->filename = av[0];
Expand Down
1 change: 0 additions & 1 deletion src/stlink-lib/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ int _stlink_usb_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len) {

cmd[i++] = STLINK_DEBUG_COMMAND;
cmd[i++] = STLINK_DEBUG_READMEM_32BIT;
DLOG("using address %#010x\n", addr);
write_uint32(&cmd[i], addr);
write_uint16(&cmd[i + 4], len);
size = send_recv(slu, 1, cmd, slu->cmd_len, data, len);
Expand Down

0 comments on commit e273ec5

Please sign in to comment.