X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fstr7x.c;h=30b8c07f7596dbfd30c757ed0eb58ba5dd91361f;hp=3574a897d47890d378ea10bfb49206510c0137ed;hb=86ca2270f40d650a849e778518e7aa9c2c713341;hpb=bcb0124b1501fb42659cdc2a343dec173aaa196a diff --git a/src/flash/str7x.c b/src/flash/str7x.c index 3574a897d4..30b8c07f75 100644 --- a/src/flash/str7x.c +++ b/src/flash/str7x.c @@ -314,6 +314,11 @@ int str7x_erase(struct flash_bank_s *bank, int first, int last) u32 retval; u32 b0_sectors = 0, b1_sectors = 0; + if (bank->target->state != TARGET_HALTED) + { + return ERROR_TARGET_NOT_HALTED; + } + for (i = first; i <= last; i++) { if (str7x_info->sector_bank[i] == 0) @@ -568,6 +573,11 @@ int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) u32 check_address = offset; int i; + if (bank->target->state != TARGET_HALTED) + { + return ERROR_TARGET_NOT_HALTED; + } + if (offset & 0x7) { WARNING("offset 0x%x breaks required 8-byte alignment", offset); @@ -627,18 +637,18 @@ int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) while (dwords_remaining > 0) { - // command + /* command */ cmd = FLASH_DWPG; target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); - // address + /* address */ target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), address); - // data word 1 + /* data word 1 */ target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, buffer + bytes_written); bytes_written += 4; - // data word 2 + /* data word 2 */ target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, buffer + bytes_written); bytes_written += 4; @@ -674,18 +684,18 @@ int str7x_write(struct flash_bank_s *bank, u8 *buffer, u32 offset, u32 count) bytes_written++; } - // command + /* command */ cmd = FLASH_DWPG; target_write_u32(target, str7x_get_flash_adr(bank, FLASH_CR0), cmd); - // address + /* address */ target_write_u32(target, str7x_get_flash_adr(bank, FLASH_AR), address); - // data word 1 + /* data word 1 */ target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR0), 4, 1, last_dword); bytes_written += 4; - // data word 2 + /* data word 2 */ target->type->write_memory(target, str7x_get_flash_adr(bank, FLASH_DR1), 4, 1, last_dword + 4); bytes_written += 4;