]> git.sur5r.net Git - openocd/blobdiff - src/flash/stm32x.c
More robust handling of unknown target state for step/continue packet.
[openocd] / src / flash / stm32x.c
index 7e26ece3a7de0167684028a93726f475931bacaa..e85c0e5a715ee2815e21665fe84acf37de21c6c4 100644 (file)
@@ -43,7 +43,6 @@ int stm32x_probe(struct flash_bank_s *bank);
 int stm32x_auto_probe(struct flash_bank_s *bank);
 int stm32x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 int stm32x_protect_check(struct flash_bank_s *bank);
-int stm32x_erase_check(struct flash_bank_s *bank);
 int stm32x_info(struct flash_bank_s *bank, char *buf, int buf_size);
 
 int stm32x_handle_lock_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
@@ -62,7 +61,7 @@ flash_driver_t stm32x_flash =
        .write = stm32x_write,
        .probe = stm32x_probe,
        .auto_probe = stm32x_auto_probe,
-       .erase_check = stm32x_erase_check,
+       .erase_check = default_flash_blank_check,
        .protect_check = stm32x_protect_check,
        .info = stm32x_info
 };
@@ -278,43 +277,6 @@ int stm32x_write_options(struct flash_bank_s *bank)
        return ERROR_OK;
 }
 
-int stm32x_blank_check(struct flash_bank_s *bank, int first, int last)
-{
-       target_t *target = bank->target;
-       u8 *buffer;
-       int i;
-       int nBytes;
-       
-       if ((first < 0) || (last > bank->num_sectors))
-               return ERROR_FLASH_SECTOR_INVALID;
-
-       if (target->state != TARGET_HALTED)
-       {
-               return ERROR_TARGET_NOT_HALTED;
-       }
-
-       buffer = malloc(256);
-       
-       for (i = first; i <= last; i++)
-       {
-               bank->sectors[i].is_erased = 1;
-
-               target->type->read_memory(target, bank->base + bank->sectors[i].offset, 4, 256/4, buffer);
-               
-               for (nBytes = 0; nBytes < 256; nBytes++)
-               {
-                       if (buffer[nBytes] != 0xFF)
-                       {
-                               bank->sectors[i].is_erased = 0;
-                               break;
-                       }
-               }       
-       }
-       
-       free(buffer);
-
-       return ERROR_OK;
-}
 
 int stm32x_protect_check(struct flash_bank_s *bank)
 {
@@ -477,7 +439,8 @@ int stm32x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        };
        
-       target_write_buffer(target, stm32x_info->write_algorithm->address, sizeof(stm32x_flash_write_code), stm32x_flash_write_code);
+       if ((retval=target_write_buffer(target, stm32x_info->write_algorithm->address, sizeof(stm32x_flash_write_code), stm32x_flash_write_code))!=ERROR_OK)
+               return retval;
 
        /* memory buffer */
        while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK)
@@ -496,7 +459,6 @@ int stm32x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
        
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
        armv7m_info.core_mode = ARMV7M_MODE_ANY;
-       armv7m_info.core_state = ARMV7M_STATE_THUMB;
        
        init_reg_param(&reg_params[0], "r0", 32, PARAM_OUT);
        init_reg_param(&reg_params[1], "r1", 32, PARAM_OUT);
@@ -507,7 +469,8 @@ int stm32x_write_block(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 co
        {
                u32 thisrun_count = (count > (buffer_size / 2)) ? (buffer_size / 2) : count;
                
-               target_write_buffer(target, source->address, thisrun_count * 2, buffer);
+               if ((retval = target_write_buffer(target, source->address, thisrun_count * 2, buffer))!=ERROR_OK)
+                       break;
                
                buf_set_u32(reg_params[0].value, 0, 32, source->address);
                buf_set_u32(reg_params[1].value, 0, 32, address);
@@ -707,11 +670,6 @@ int stm32x_handle_part_id_command(struct command_context_s *cmd_ctx, char *cmd,
        return ERROR_OK;
 }
 
-int stm32x_erase_check(struct flash_bank_s *bank)
-{
-       return stm32x_blank_check(bank, 0, bank->num_sectors - 1);
-}
-
 int stm32x_info(struct flash_bank_s *bank, char *buf, int buf_size)
 {
        snprintf(buf, buf_size, "stm32x flash driver info" );