stm32l4: Handle failing flash_size read like on other devices.
[fw/openocd] / src / flash / nor / stm32f2x.c
index 89fc75dcf3aa618466ada65baac7573a1ae28fcb..4269c44619f29abee94f63249d6c5def9aa1adc1 100644 (file)
@@ -19,9 +19,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -551,7 +549,7 @@ static int stm32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
                        &write_algorithm) != ERROR_OK) {
                LOG_WARNING("no working area available, can't do block memory writes");
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
-       };
+       }
 
        retval = target_write_buffer(target, write_algorithm->address,
                        sizeof(stm32x_flash_write_code),
@@ -570,7 +568,7 @@ static int stm32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
                        LOG_WARNING("no large enough working area available, can't do block memory writes");
                        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
                }
-       };
+       }
 
        armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
        armv7m_info.core_mode = ARM_MODE_THREAD;
@@ -787,6 +785,7 @@ static int stm32x_probe(struct flash_bank *bank)
        switch (device_id & 0xfff) {
        case 0x411:
        case 0x413:
+       case 0x441:
                max_flash_size_in_kb = 1024;
                break;
        case 0x419:
@@ -801,6 +800,9 @@ static int stm32x_probe(struct flash_bank *bank)
        case 0x421:
                max_flash_size_in_kb = 512;
                break;
+       case 0x458:
+               max_flash_size_in_kb = 128;
+               break;
        case 0x449:
                max_flash_size_in_kb = 1024;
                max_sector_size_in_kb = 256;
@@ -953,7 +955,6 @@ static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
 
        case 0x413:
        case 0x419:
-       case 0x434:
                device_str = "STM32F4xx";
 
                switch (rev_id) {
@@ -990,6 +991,8 @@ static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
        case 0x423:
        case 0x431:
        case 0x433:
+       case 0x458:
+       case 0x441:
                device_str = "STM32F4xx (Low Power)";
 
                switch (rev_id) {
@@ -1016,6 +1019,15 @@ static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
                        break;
                }
                break;
+       case 0x434:
+               device_str = "STM32F46x/F47x";
+
+               switch (rev_id) {
+               case 0x1000:
+                       rev_str = "A";
+                       break;
+               }
+               break;
 
        default:
                snprintf(buf, buf_size, "Cannot identify target as a STM32F2/4/7\n");
@@ -1114,6 +1126,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command)
 static int stm32x_mass_erase(struct flash_bank *bank)
 {
        int retval;
+       uint32_t flash_mer;
        struct target *target = bank->target;
        struct stm32x_flash_bank *stm32x_info = NULL;
 
@@ -1130,13 +1143,14 @@ static int stm32x_mass_erase(struct flash_bank *bank)
 
        /* mass erase flash memory */
        if (stm32x_info->has_large_mem)
-               retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_MER | FLASH_MER1);
+               flash_mer = FLASH_MER | FLASH_MER1;
        else
-               retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_MER);
+               flash_mer = FLASH_MER;
+       retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), flash_mer);
        if (retval != ERROR_OK)
                return retval;
        retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR),
-               FLASH_MER | FLASH_STRT);
+               flash_mer | FLASH_STRT);
        if (retval != ERROR_OK)
                return retval;