diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c
index 1428b37c68533473a8838f6dcacf7612ca9b574d..b4d7bbc86f72bc6c90751842dab8574bf4e60684 100644
--- a/src/flash/nor/max32xxx.c
+++ b/src/flash/nor/max32xxx.c
@@ -85,10 +85,7 @@
#define ARM_PID_DEFAULT_CM3 0x0000B4C3
#define ARM_PID_DEFAULT_CM4 0x0000B4C4
-#define MAX326XX_ID 0x0000004D
-
-#define WRITE32BIT 0
-#define WRITE128BIT 1
+#define MAX326XX_ID 0x0000004D
#define OPTIONS_128 0x01 /* Perform 128 bit flash writes */
#define OPTIONS_ENC 0x02 /* Encrypt the flash contents */
@@ -98,7 +95,6 @@
#define OPTIONS_RELATIVE_XOR 0x20 /* Only XOR the offset of the address when encrypting */
#define OPTIONS_KEYSIZE 0x40 /* Use a 256 bit KEY */
-
static int max32xxx_mass_erase(struct flash_bank *bank);
struct max32xxx_flash_bank {
@@ -109,11 +105,9 @@ struct max32xxx_flash_bank {
unsigned int sector_size;
unsigned int clkdiv_value;
unsigned int int_state;
- unsigned int burst_size_bits;
- unsigned int enc_options;
+ unsigned int options;
};
-/* see contib/loaders/flash/max32xxx/max32xxx.s for src */
static const uint8_t write_code[] = {
0x9b, 0x46, 0x51, 0xf8, 0x84, 0x3c, 0xa1, 0xf5, 0x82, 0x77, 0x02, 0x93, 0x13, 0xf0, 0x02, 0x03, 0x05, 0x93, 0x1e, 0xd0,
0x4f, 0xf0, 0x80, 0x43, 0x9c, 0x68, 0x64, 0x03, 0x5e, 0xbf, 0x9c, 0x68, 0x44, 0xf4, 0x80, 0x24, 0x9c, 0x60, 0x5c, 0x6a,
@@ -162,15 +156,12 @@ static const uint8_t write_code[] = {
0xff, 0x09, 0x3d, 0xe7, 0x4f, 0xf0, 0xff, 0x09, 0x60, 0xe7, 0x4f, 0xf0, 0xff, 0x09, 0x83, 0xe7, 0x5d, 0x44, 0x9f, 0xe7,
};
-/* Config Command: flash bank name driver base size chip_width bus_width target [driver_option]
- flash bank max32xxx 0 0 [burst_bits]
- */
FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
{
struct max32xxx_flash_bank *info;
- if ((CMD_ARGC < 10) || (CMD_ARGC > 11)) {
- LOG_ERROR("incorrect flash bank max32xxx configuration: 0 0 [enc_options]");
+ if ((CMD_ARGC < 10) || (CMD_ARGC > 10)) {
+ LOG_ERROR("incorrect flash bank max32xxx configuration: 0 0 ");
return ERROR_FLASH_BANK_INVALID;
}
@@ -179,22 +170,7 @@ FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->flc_base);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[7], info->sector_size);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[8], info->clkdiv_value);
- COMMAND_PARSE_NUMBER(u32, CMD_ARGV[9], info->burst_size_bits);
-
- if ((info->burst_size_bits != 128) && (info->burst_size_bits != 32)) {
- LOG_ERROR("Invalid burst size %d, must be 32 or 128", info->burst_size_bits);
- return ERROR_FLASH_BANK_INVALID;
- }
-
- if(CMD_ARGC == 11) {
- COMMAND_PARSE_NUMBER(u32, CMD_ARGV[10], info->enc_options);
- } else {
- if(info->burst_size_bits == 128) {
- info->enc_options = OPTIONS_128;
- } else {
- info->enc_options = 0x0;
- }
- }
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[9], info->options);
info->int_state = 0;
bank->driver_priv = info;
@@ -514,7 +490,7 @@ static int max32xxx_write_block(struct flash_bank *bank, const uint8_t *buffer,
/* mem_params for options */
init_mem_param(&mem_param[0], source->address + (source->size - 4 - 128), 4, PARAM_OUT);
- buf_set_u32(mem_param[0].value, 0, 32, info->enc_options);
+ buf_set_u32(mem_param[0].value, 0, 32, info->options);
/* leave room for stack, 32-bit options and encryption buffer */
retval = target_run_flash_async_algorithm(target, buffer, wcount*4, 1, 1, mem_param,
@@ -556,7 +532,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
if (info->probed == 0)
return ERROR_FLASH_BANK_NOT_PROBED;
- if (info->burst_size_bits == 32) {
+ if ((info->options & OPTIONS_128) == 0) {
if (offset & 0x3) {
LOG_ERROR("offset size must be 32-bit aligned");
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
@@ -600,7 +576,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
}
}
- if ((info->burst_size_bits == 32) && (remaining >= 4)) {
+ if (((info->options & OPTIONS_128) == 0) && (remaining >= 4)) {
/* write in 32-bit units*/
target_read_u32(target, info->flc_base + FLC_CN, &flash_cn);
flash_cn |= FLC_CN_32BIT;
@@ -629,7 +605,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
}
}
- if ((info->burst_size_bits == 128) && (remaining >= 16)) {
+ if ((info->options & OPTIONS_128) && (remaining >= 16)) {
/* write in 128-bit units */
target_read_u32(target, info->flc_base + FLC_CN, &flash_cn);
flash_cn &= ~(FLC_CN_32BIT);
@@ -662,7 +638,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
}
}
- if ((info->burst_size_bits == 32) && remaining > 0) {
+ if (((info->options & OPTIONS_128) == 0) && remaining > 0) {
/* write remaining bytes in a 32-bit unit */
target_read_u32(target, info->flc_base + FLC_CN, &flash_cn);
flash_cn |= FLC_CN_32BIT;
@@ -695,7 +671,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
}
}
- if ((info->burst_size_bits == 128) && remaining > 0) {
+ if ((info->options & OPTIONS_128) && remaining > 0) {
/* write remaining bytes in a 128-bit unit */
if (target_read_u32(target, info->flc_base + FLC_CN, &flash_cn) != ERROR_OK) {
max32xxx_flash_op_post(bank);
diff --git a/tcl/target/max32520.cfg b/tcl/target/max32520.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..4e75a99c3c68621b921750f9b5cfa9bc429cfa73
--- /dev/null
+++ b/tcl/target/max32520.cfg
@@ -0,0 +1,19 @@
+# Maxim Integrated MAX32665 OpenOCD target configuration file
+# www.maximintegrated.com
+
+# Set the reset pin configuration
+reset_config srst_only
+adapter_nsrst_delay 200
+
+# Set flash parameters
+set FLASH_BASE 0x10000000
+set FLASH_SIZE 0x200000
+set FLC_BASE 0x40029000
+set FLASH_SECTOR 0x2000
+
+# Currently set for Emulator
+set FLASH_CLK 40
+
+set FLASH_OPTIONS 0x63
+
+source [find target/max32xxx.cfg]
diff --git a/tcl/target/max32620.cfg b/tcl/target/max32620.cfg
index 1ee892dc6bab3b7099f18371706af0446a22dcb2..8aed3a806407991deefc8df11ab66c4fac2fa288 100644
--- a/tcl/target/max32620.cfg
+++ b/tcl/target/max32620.cfg
@@ -11,7 +11,7 @@ set FLASH_SIZE 0x200000
set FLC_BASE 0x40002000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 32
+set FLASH_OPTIONS 0x00
# Setup the reserved TAP
set RSV_TAP 1
diff --git a/tcl/target/max32625.cfg b/tcl/target/max32625.cfg
index 44e62f708b95bed52f91f64cceda55ead5c4defd..f29fabf20ba00dd868ef1631d45b4075fc10bc95 100644
--- a/tcl/target/max32625.cfg
+++ b/tcl/target/max32625.cfg
@@ -11,7 +11,7 @@ set FLASH_SIZE 0x80000
set FLC_BASE 0x40002000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 32
+set FLASH_OPTIONS 0x00
# Setup the reserved TAP
set RSV_TAP 1
diff --git a/tcl/target/max3263x.cfg b/tcl/target/max3263x.cfg
index 06565ef6dee96123706703eaf8a0d89a7a05ebbb..2b78df6e3344ab8072fd5e7d2cba5938a213920f 100644
--- a/tcl/target/max3263x.cfg
+++ b/tcl/target/max3263x.cfg
@@ -10,7 +10,7 @@ set FLASH_SIZE 0x200000
set FLC_BASE 0x40002000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 32
+set FLASH_OPTIONS 0x00
# Setup the reserved TAP
set RSV_TAP 1
diff --git a/tcl/target/max32650.cfg b/tcl/target/max32650.cfg
index 1ae0f69813ae8c5858826df9a77f4f4758511a47..e5c28bc93f67a02e5a6ade814f6d28d856b4a60d 100644
--- a/tcl/target/max32650.cfg
+++ b/tcl/target/max32650.cfg
@@ -11,7 +11,6 @@ set FLASH_SIZE 0x300000
set FLC_BASE 0x40029000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 32
-# set FLASH_BITS 128
+set FLASH_OPTIONS 0x00
source [find target/max32xxx.cfg]
diff --git a/tcl/target/max32660.cfg b/tcl/target/max32660.cfg
index 723d4d5a85ff490203efc4e161faea5cc71f32fb..6c6d60179f2d987563af5ccb9891bc19237db092 100644
--- a/tcl/target/max32660.cfg
+++ b/tcl/target/max32660.cfg
@@ -11,7 +11,6 @@ set FLASH_SIZE 0x40000
set FLC_BASE 0x40029000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 32
-# set FLASH_BITS 128
+set FLASH_OPTIONS 0x00
source [find target/max32xxx.cfg]
diff --git a/tcl/target/max32665.cfg b/tcl/target/max32665.cfg
index 5d05ee448cac52e12aa3ca26fd1c716e09750c6e..893ffa8bb4edd3b9d9dd19128f8f1d1096badc07 100644
--- a/tcl/target/max32665.cfg
+++ b/tcl/target/max32665.cfg
@@ -11,6 +11,6 @@ set FLASH_SIZE 0x300000
set FLC_BASE 0x40029000
set FLASH_SECTOR 0x2000
set FLASH_CLK 96
-set FLASH_BITS 128
+set FLASH_OPTIONS 0x01
source [find target/max32xxx.cfg]
diff --git a/tcl/target/max32xxx.cfg b/tcl/target/max32xxx.cfg
index 9039f0d925b5bac76b06524be8e5ad8bcdc8c78d..9f5b2719e09ef166e07eeb99a0eb90c452ce98ed 100644
--- a/tcl/target/max32xxx.cfg
+++ b/tcl/target/max32xxx.cfg
@@ -77,21 +77,19 @@ if { [info exists FLASH_CLK] } {
set _FLASH_CLK 96
}
-if { [info exists FLASH_BITS] } {
- set _FLASH_BITS $FLASH_BITS
+# OPTIONS_128 0x01 /* Perform 128 bit flash writes */
+# OPTIONS_ENC 0x02 /* Encrypt the flash contents */
+# OPTIONS_AUTH 0x04 /* Authenticate the flash contents */
+# OPTIONS_COUNT 0x08 /* Add counter values to authentication */
+# OPTIONS_INTER 0x10 /* Interleave the authentication and count values*/
+# OPTIONS_RELATIVE_XOR 0x20 /* Only XOR the offset of the address when encrypting */
+# OPTIONS_KEYSIZE 0x40 /* Use a 256 bit KEY */
+
+if { [info exists FLASH_OPTIONS] } {
+ set _FLASH_OPTIONS $FLASH_OPTIONS
} else {
- set _FLASH_BITS 32
-}
-
-if { [info exists ENC_OPTIONS] } {
- set _ENC_OPTIONS $ENC_OPTIONS
-} else {
- if { $FLASH_BITS == 128 } {
- set _ENC_OPTIONS 1
- } else {
- set _ENC_OPTIONS 0
- }
+ set _FLASH_OPTIONS 0
}
flash bank $_CHIPNAME.flash max32xxx $_FLASH_BASE $_FLASH_SIZE 0 0 $_CHIPNAME.cpu \
-$_FLC_BASE $_FLASH_SECTOR $_FLASH_CLK $_FLASH_BITS $_ENC_OPTIONS
+$_FLC_BASE $_FLASH_SECTOR $_FLASH_CLK $_FLASH_OPTIONS