X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fstm32x.c;h=5b31b0421a8dbcf8b02d160aad0a9431fee6dad4;hp=8a3b83232c1d8806b5b3b8c4436b5a34bef76283;hb=4617cd0f911d64a460d99d25c531ddc55f2452ca;hpb=86e851e1e263c79f19eb9db52553de99f19b8bb9 diff --git a/src/flash/nor/stm32x.c b/src/flash/nor/stm32x.c index 8a3b83232c..5b31b0421a 100644 --- a/src/flash/nor/stm32x.c +++ b/src/flash/nor/stm32x.c @@ -446,6 +446,8 @@ static int stm32x_write_block(struct flash_bank *bank, uint8_t *buffer, struct armv7m_algorithm armv7m_info; int retval = ERROR_OK; + /* see contib/loaders/flash/stm32x.s for src */ + static const uint8_t stm32x_flash_write_code[] = { /* write: */ 0xDF, 0xF8, 0x24, 0x40, /* ldr r4, STM32_FLASH_CR */ @@ -462,6 +464,7 @@ static int stm32x_write_block(struct flash_bank *bank, uint8_t *buffer, 0x01, 0xD1, /* bne exit */ 0x01, 0x3A, /* subs r2, r2, #1 */ 0xED, 0xD1, /* bne write */ + /* exit: */ 0x00, 0xBE, /* bkpt #0 */ 0x10, 0x20, 0x02, 0x40, /* STM32_FLASH_CR: .word 0x40022010 */ 0x0C, 0x20, 0x02, 0x40 /* STM32_FLASH_SR: .word 0x4002200C */ @@ -519,7 +522,7 @@ static int stm32x_write_block(struct flash_bank *bank, uint8_t *buffer, if ((retval = target_run_algorithm(target, 0, NULL, 4, reg_params, stm32x_info->write_algorithm->address, - stm32x_info->write_algorithm->address + (sizeof(stm32x_flash_write_code) - 10), + 0, 10000, &armv7m_info)) != ERROR_OK) { LOG_ERROR("error executing stm32x flash write algorithm"); @@ -814,7 +817,7 @@ COMMAND_HANDLER(stm32x_handle_part_id_command) } #endif -static int stm32x_info(struct flash_bank *bank, char *buf, int buf_size) +static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size) { struct target *target = bank->target; uint32_t device_id; @@ -1196,13 +1199,13 @@ static int stm32x_mass_erase(struct flash_bank *bank) if (status & FLASH_WRPRTERR) { LOG_ERROR("stm32x device protected"); - return ERROR_OK; + return ERROR_FLASH_OPERATION_FAILED; } if (status & FLASH_PGERR) { LOG_ERROR("stm32x device programming failed"); - return ERROR_OK; + return ERROR_FLASH_OPERATION_FAILED; } return ERROR_OK; @@ -1223,7 +1226,8 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) if (ERROR_OK != retval) return retval; - if (stm32x_mass_erase(bank) == ERROR_OK) + retval = stm32x_mass_erase(bank); + if (retval == ERROR_OK) { /* set all sectors as erased */ for (i = 0; i < bank->num_sectors; i++) @@ -1238,7 +1242,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) command_print(CMD_CTX, "stm32x mass erase failed"); } - return ERROR_OK; + return retval; } static const struct command_registration stm32x_exec_command_handlers[] = { @@ -1304,5 +1308,5 @@ struct flash_driver stm32x_flash = { .auto_probe = stm32x_auto_probe, .erase_check = default_flash_mem_blank_check, .protect_check = stm32x_protect_check, - .info = stm32x_info, + .info = get_stm32x_info, };