From 986826957135c963dd0990884c6c8aeaf0abfa83 Mon Sep 17 00:00:00 2001
From: Vedran <vedran_extern@pm.me>
Date: Fri, 12 Apr 2024 19:55:56 +0200
Subject: [PATCH] Use defines for memory addresses

---
 src/target/kinetis.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/target/kinetis.c b/src/target/kinetis.c
index 2715a26f293..4d6681713c5 100644
--- a/src/target/kinetis.c
+++ b/src/target/kinetis.c
@@ -95,6 +95,19 @@
 /* 8 byte phrases need to be written to the k64 flash */
 #define K64_WRITE_LEN 8U
 
+/* Target registers */
+#define MK20DX256_FLASH_BASE        0x00000000U
+#define MK20DX256_FLASH_SIZE        0x00040000U
+#define MK20DX256_FLASH_BLK_SIZE    0x00000800U
+#define MK20DX256_FLEXNVM_BASE      0x10000000U
+#define MK20DX256_FLEXNVM_SIZE      0x00008000U
+#define MK20DX256_FLEXNVM_BLK_SIZE  0x00000400U
+#define MK20DX256_SRAM_L_BASE       0x1fff8000U
+#define MK20DX256_SRAM_L_SIZE       0x00008000U
+#define MK20DX256_SRAM_H_BASE       0x20000000U
+#define MK20DX256_SRAM_H_SIZE       0x00008000U
+
+
 static bool kinetis_cmd_unsafe(target_s *t, int argc, const char **argv);
 
 const command_s kinetis_cmd_list[] = {
@@ -330,12 +343,10 @@ bool kinetis_probe(target_s *const t)
 			return false;
 		case 0x090U: /* K20 Family, DIEID=0x1 */
 			t->driver = "MK20DX256";
-			target_add_ram(t, 0x1fff8000, 0x00008000);	/* SRAM_L, 32 KB */
-			target_add_ram(t, 0x20000000, 0x00008000);	/* SRAM_H, 32 KB */
-
-			kinetis_add_flash(t, 0x00000000, 0x40000, 0x800, KL_WRITE_LEN); /* P-Flash, 256 KB, 2 KB Sectors */
-			kinetis_add_flash(t, 0x10000000, 0x8000, 0x400, KL_WRITE_LEN); /* FlexNVM, 32 KB, 1 KB Sectors */
-
+			target_add_ram(t, MK20DX256_SRAM_L_BASE, MK20DX256_SRAM_L_SIZE);	/* SRAM_L, 32 KB */
+			target_add_ram(t, MK20DX256_SRAM_H_BASE, MK20DX256_SRAM_H_SIZE);	/* SRAM_H, 32 KB */
+			kinetis_add_flash(t, MK20DX256_FLASH_BASE, MK20DX256_FLASH_SIZE, MK20DX256_FLASH_BLK_SIZE, KL_WRITE_LEN);       /* P-Flash, 256 KB, 2 KB Sectors */
+			kinetis_add_flash(t, MK20DX256_FLEXNVM_BASE, MK20DX256_FLEXNVM_SIZE, MK20DX256_FLEXNVM_BLK_SIZE, KL_WRITE_LEN); /* FlexNVM, 32 KB, 1 KB Sectors */
 			break;
 		case 0x110U: /* K20 Family, DIEID=0x2 */
 		case 0x190U: /* K20 Family, DIEID=0x3 */