nor/flash/stm32f1x: add stm32f07x support
[fw/openocd] / src / flash / nor / lpc2000.c
index 3962f305c809ba3cef780cccb7cb6aa81c04c01d..259b42f1c4b7ab784750c5be2ec75c56afafd875 100644 (file)
  * - 176x (tested with LPC1768)
  *
  * lpc4300 (also available as lpc1800 - alias)
- * - 43x2 | 3 | 5 | 7 (tested with 4337)
+ * - 43x2 | 3 | 5 | 7 (tested with LPC4337/LPC4357)
  * - 18x2 | 3 | 5 | 7
  *
  * lpc800:
- * - 810 | 1 | 2 (tested with 812)
+ * - 810 | 1 | 2 (tested with LPC810/LPC812)
  */
 
 typedef enum {
@@ -230,15 +230,15 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
        } else if (lpc2000_info->variant == lpc1700) {
                switch (bank->size) {
                        case 4 * 1024:
-                               lpc2000_info->cmd51_max_buffer = 1024;
+                               lpc2000_info->cmd51_max_buffer = 256;
                                bank->num_sectors = 1;
                                break;
                        case 8 * 1024:
-                               lpc2000_info->cmd51_max_buffer = 1024;
+                               lpc2000_info->cmd51_max_buffer = 512;
                                bank->num_sectors = 2;
                                break;
                        case 16 * 1024:
-                               lpc2000_info->cmd51_max_buffer = 1024;
+                               lpc2000_info->cmd51_max_buffer = 512;
                                bank->num_sectors = 4;
                                break;
                        case 32 * 1024:
@@ -303,9 +303,11 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
                        lpc2000_info->cmd51_max_buffer = 1024;
                switch (bank->size) {
                        case 4 * 1024:
+                               lpc2000_info->cmd51_max_buffer = 256;
                                bank->num_sectors = 4;
                                break;
                        case 8 * 1024:
+                               lpc2000_info->cmd51_max_buffer = 512;
                                bank->num_sectors = 8;
                                break;
                        case 16 * 1024:
@@ -485,7 +487,7 @@ static int lpc2000_iap_call(struct flash_bank *bank, struct working_area *iap_wo
        result_table[3] = target_buffer_get_u32(target, mem_params[1].value + 0x10);
 
        LOG_DEBUG("IAP command = %i (0x%8.8" PRIx32 ", 0x%8.8" PRIx32 ", 0x%8.8" PRIx32 ", 0x%8.8" PRIx32 ", 0x%8.8" PRIx32
-                       ") completed with result = %8.8" PRIx32,
+                       ") completed with result = %8.8x",
                        code, param_table[0], param_table[1], param_table[2], param_table[3], param_table[4], status_code);
 
        destroy_mem_param(&mem_params[0]);
@@ -559,7 +561,8 @@ FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command)
        if (CMD_ARGC < 8)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       struct lpc2000_flash_bank *lpc2000_info = malloc(sizeof(struct lpc2000_flash_bank));
+       struct lpc2000_flash_bank *lpc2000_info = calloc(1, sizeof(*lpc2000_info));
+
        bank->driver_priv = lpc2000_info;
 
        if (strcmp(CMD_ARGV[6], "lpc2000_v1") == 0) {
@@ -652,6 +655,10 @@ static int lpc2000_erase(struct flash_bank *bank, int first, int last)
        if (retval != ERROR_OK)
                return retval;
 
+       if (lpc2000_info->variant == lpc4300)
+               /* Init IAP Anyway */
+               lpc2000_iap_call(bank, iap_working_area, 49, param_table, result_table);
+
        /* Prepare sectors */
        int status_code = lpc2000_iap_call(bank, iap_working_area, 50, param_table, result_table);
        switch (status_code) {
@@ -780,6 +787,10 @@ static int lpc2000_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offs
        uint32_t param_table[5] = {0};
        uint32_t result_table[4];
 
+       if (lpc2000_info->variant == lpc4300)
+               /* Init IAP Anyway */
+               lpc2000_iap_call(bank, iap_working_area, 49, param_table, result_table);
+
        while (bytes_remaining > 0) {
                uint32_t thisrun_bytes;
                if (bytes_remaining >= lpc2000_info->cmd51_max_buffer)