diff --git a/src/.uviemon_history b/src/.uviemon_history
index 36dc45d7054edcd12416a60b05326069c2282e30..8a570aa5cff964caabdf881cf517c408bd873f8d 100644
--- a/src/.uviemon_history
+++ b/src/.uviemon_history
@@ -71,3 +71,8 @@ run
 load ../../test_2
 run
 exit
+mem 0xFFFFF000
+quit
+exit
+exit
+exit
diff --git a/src/address_map.h b/src/address_map.h
index 278c934945de982b25a65bb71d4bf4b79631d512..1332ced186a63df62d6f853b51b8e270c18a4dfc 100644
--- a/src/address_map.h
+++ b/src/address_map.h
@@ -18,4 +18,26 @@ const uint32_t ADDRESSES[SUPPORTED_CPUS][DEFINED_ADDRESSES] = {
 	{ 0x40000000, 0xFF900000, 0xE0000000, 0xFF904010 }
 };
 
+
+#define AHB_PNP 0xFFFFF000
+
+#define DEV_GAISLER_LEON3        0x003
+#define DEV_GAISLER_LEON3DSU     0x004
+#define DEV_GAISLER_LEON4        0x048
+#define DEV_GAISLER_LEON4DSU     0x049
+#define DEV_GAISLER_LEON3FT      0x053
+#define KNOWN_CPUS               5
+
+const uint32_t CPU_MAP[KNOWN_CPUS][2] = {
+	{ DEV_GAISLER_LEON3, 0 },
+	{ DEV_GAISLER_LEON3DSU, 0 },
+	{ DEV_GAISLER_LEON4, 1 },
+	{ DEV_GAISLER_LEON4DSU, 1 },
+	{ DEV_GAISLER_LEON3FT, 0 }
+};
+
+extern const char *CPU_NAMES[];
+
+#define amba_pnp_device(id)  (((id) >> 12) & 0xfff)
+
 #endif
diff --git a/src/adress_map.c b/src/adress_map.c
new file mode 100644
index 0000000000000000000000000000000000000000..297433965806e1a86aeaeed6753ebf1e0b6a6827
--- /dev/null
+++ b/src/adress_map.c
@@ -0,0 +1 @@
+const char* CPU_NAMES[] = { "LEON 3", "LEON 4" };
diff --git a/src/ftdi_device.cpp b/src/ftdi_device.cpp
index 8df90bfad25c150acec222668e3f33302b65d1fc..90df503e4516b906c93b7f7251b442c81ed23c30 100644
--- a/src/ftdi_device.cpp
+++ b/src/ftdi_device.cpp
@@ -71,6 +71,26 @@ FT_STATUS open_device(DWORD device_index, int cpu_type)
 		return ftStatus;
 	}
 
+	// Try to autodetect CPU type
+	if (device.cpu_type == -1) {
+		printf("Autodetecting CPU...");
+		DWORD cpu = amba_pnp_device(ioread32(AHB_PNP));
+
+		for(int i = 0; i < KNOWN_CPUS; i++) {
+			if (cpu == CPU_MAP[i][0]) {
+				device.cpu_type = CPU_MAP[i][1];
+				printf("%s CPU found!\n", CPU_NAMES[device.cpu_type]);
+				break;
+			}
+		}
+
+		if (device.cpu_type == -1) {
+			printf("Unknown cpu type: %03x ... Try to explicitly indicate a cpu with -cpu_type\n", cpu);
+			exit(-1);
+		}
+		
+	}
+
 	// Move this to another step?
 	init_core_1(); // Initialize core 1 (this will run all the programs)
 	//_initCore2();  // Initialize core 2 (this will be idle)
diff --git a/src/uviemon.cpp b/src/uviemon.cpp
index 2c088475e07fa503e98affd458b9fe26cae3313d..4680bce3c0b3d2ac8a89c1d1cfdacb5a0c1d0ec5 100644
--- a/src/uviemon.cpp
+++ b/src/uviemon.cpp
@@ -87,6 +87,7 @@ void showHelp()
 	printf("\t -help: \t This list of all available commands\n");
 	printf("\t -info: \t Version numbers and driver info\n");
 	printf("\t -list: \t List all available FTDI devices\n");
+	printf("\t -cpu_tye <num>: \t 0 for LEON 3 and 1 for LEON4 autodetection used of omitted \n");
 	printf("\t -jtag <num>: \t Open console with jtag device\n\n");
 }
 
@@ -110,7 +111,7 @@ int main(int argc, char *argv[])
 	}
 
 	int i = 1;
-	int cpu_type = 0;
+	int cpu_type = -1;
 	int device_index = 0;
 
 	while(i < argc) {