flash/nor/efr32: fixed lockbits and user data
[fw/openocd] / src / flash / nor / stm32f1x.c
index afc6ec9b6c628638f3584534514ece61462b16b3..90cee641206a3c792601096e5bdb8e985dfbe98b 100644 (file)
@@ -402,8 +402,6 @@ static int stm32x_erase(struct flash_bank *bank, unsigned int first,
                retval = stm32x_wait_status_busy(bank, FLASH_ERASE_TIMEOUT);
                if (retval != ERROR_OK)
                        return retval;
-
-               bank->sectors[i].is_erased = 1;
        }
 
        retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_LOCK);
@@ -642,6 +640,9 @@ static int stm32x_get_device_id(struct flash_bank *bank, uint32_t *device_id)
        case CORTEX_M4_PARTNO: /* STM32F3x devices */
                device_id_register = 0xE0042000;
                break;
+       case CORTEX_M23_PARTNO: /* GD32E23x devices */
+               device_id_register = 0x40015800;
+               break;
        default:
                LOG_ERROR("Cannot identify target as a stm32x");
                return ERROR_FAIL;
@@ -676,6 +677,9 @@ static int stm32x_get_flash_size(struct flash_bank *bank, uint16_t *flash_size_i
        case CORTEX_M4_PARTNO: /* STM32F3x devices */
                flash_size_reg = 0x1FFFF7CC;
                break;
+       case CORTEX_M23_PARTNO: /* GD32E23x devices */
+               flash_size_reg = 0x1FFFF7E0;
+               break;
        default:
                LOG_ERROR("Cannot identify target as a stm32x");
                return ERROR_FAIL;
@@ -758,8 +762,8 @@ static int stm32x_probe(struct flash_bank *bank)
                page_size = 1024;
                stm32x_info->ppage_size = 4;
                max_flash_size_in_kb = 128;
-               /* GigaDevice GD32F1x0 & GD32F3x0 series devices share DEV_ID
-                  with STM32F101/2/3 medium-density line,
+               /* GigaDevice GD32F1x0 & GD32F3x0 & GD32E23x series devices
+                  share DEV_ID with STM32F101/2/3 medium-density line,
                   however they use a REV_ID different from any STM32 device.
                   The main difference is another offset of user option bits
                   (like WDG_SW, nRST_STOP, nRST_STDBY) in option byte register
@@ -776,6 +780,11 @@ static int stm32x_probe(struct flash_bank *bank)
                        stm32x_info->user_data_offset = 16;
                        stm32x_info->option_offset = 6;
                        break;
+               case 0x1909: /* gd32e23x */
+                       stm32x_info->user_data_offset = 16;
+                       stm32x_info->option_offset = 6;
+                       max_flash_size_in_kb = 64;
+                       break;
                }
                break;
        case 0x412: /* stm32f1x low-density */
@@ -986,6 +995,10 @@ static int get_stm32x_info(struct flash_bank *bank, struct command_invocation *c
                        device_str = "GD32F3x0";
                        break;
 
+               case 0x1909: /* gd32e23x */
+                       device_str = "GD32E23x";
+                       break;
+
                case 0x2000:
                        rev_str = "B";
                        break;
@@ -1524,19 +1537,15 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
                return retval;
 
        retval = stm32x_mass_erase(bank);
-       if (retval == ERROR_OK) {
-               /* set all sectors as erased */
-               for (unsigned int i = 0; i < bank->num_sectors; i++)
-                       bank->sectors[i].is_erased = 1;
-
+       if (retval == ERROR_OK)
                command_print(CMD, "stm32x mass erase complete");
-       else
+       else
                command_print(CMD, "stm32x mass erase failed");
 
        return retval;
 }
 
-static const struct command_registration stm32x_exec_command_handlers[] = {
+static const struct command_registration stm32f1x_exec_command_handlers[] = {
        {
                .name = "lock",
                .handler = stm32x_handle_lock_command,
@@ -1584,20 +1593,20 @@ static const struct command_registration stm32x_exec_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-static const struct command_registration stm32x_command_handlers[] = {
+static const struct command_registration stm32f1x_command_handlers[] = {
        {
                .name = "stm32f1x",
                .mode = COMMAND_ANY,
                .help = "stm32f1x flash command group",
                .usage = "",
-               .chain = stm32x_exec_command_handlers,
+               .chain = stm32f1x_exec_command_handlers,
        },
        COMMAND_REGISTRATION_DONE
 };
 
 const struct flash_driver stm32f1x_flash = {
        .name = "stm32f1x",
-       .commands = stm32x_command_handlers,
+       .commands = stm32f1x_command_handlers,
        .flash_bank_command = stm32x_flash_bank_command,
        .erase = stm32x_erase,
        .protect = stm32x_protect,