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 */
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 */
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");
}
#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;
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;
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++)
command_print(CMD_CTX, "stm32x mass erase failed");
}
- return ERROR_OK;
+ return retval;
}
static const struct command_registration stm32x_exec_command_handlers[] = {
.auto_probe = stm32x_auto_probe,
.erase_check = default_flash_mem_blank_check,
.protect_check = stm32x_protect_check,
- .info = stm32x_info,
+ .info = get_stm32x_info,
};