Store the masked chip_id in the stlink structure. Should fix unexpected
[fw/stlink] / src / test_usb.c
index cc8ae7299dd7317ff3e569cfb1b4c728ddf5e6e9..be4981db051069cc0c97f0ee34572c56d9a59bcd 100644 (file)
@@ -4,8 +4,13 @@
 
 int main(int ac, char** av) {
     stlink_t* sl;
+    reg regs;
 
-    sl = stlink_open_usb(NULL, 10);
+    /* unused */
+    ac = ac;
+    av = av;
+
+    sl = stlink_open_usb(10);
     if (sl != NULL) {
         printf("-- version\n");
         stlink_version(sl);
@@ -22,8 +27,8 @@ int main(int ac, char** av) {
 
         printf("-- mode after entering swd mode: %d\n", stlink_current_mode(sl));
 
-        printf("-- chip id: %#x\n", stlink_chip_id(sl));
-        printf("-- core_id: %#x\n", stlink_core_id(sl));
+        printf("-- chip id: %#x\n", sl->chip_id);
+        printf("-- core_id: %#x\n", sl->core_id);
 
         cortex_m3_cpuid_t cpuid;
         stlink_cpu_id(sl, &cpuid);
@@ -40,17 +45,43 @@ int main(int ac, char** av) {
         stlink_read_mem32(sl, CM3_REG_FP_CTRL, 4);
         
         // no idea what reg this is..  */
-        /*     stlink_read_mem32(sl, 0xe000ed90, 4);
+        //     stlink_read_mem32(sl, 0xe000ed90, 4);
         // no idea what register this is...
-        /*     stlink_read_mem32(sl, 0xe000edf0, 4);
+        //     stlink_read_mem32(sl, 0xe000edf0, 4);
         // offset 0xC into TIM11 register? TIMx_DIER?
-        /*     stlink_read_mem32(sl, 0x4001100c, 4); */
+        //     stlink_read_mem32(sl, 0x4001100c, 4); */
+
+        /* Test 32 bit Write */
+        write_uint32(sl->q_buf,0x01234567);
+        stlink_write_mem32(sl,0x200000a8,4);
+        write_uint32(sl->q_buf,0x89abcdef);
+        stlink_write_mem32(sl,0x200000ac, 4);
+        stlink_read_mem32(sl, 0x200000a8, 4);
+        stlink_read_mem32(sl, 0x200000ac, 4);
+        
+        /* Test 8 bit write */
+        write_uint32(sl->q_buf,0x01234567);
+        stlink_write_mem8(sl,0x200001a8,3);
+        write_uint32(sl->q_buf,0x89abcdef);
+        stlink_write_mem8(sl, 0x200001ac, 3);
+        stlink_read_mem32(sl, 0x200001a8, 4);
+        stlink_read_mem32(sl, 0x200001ac, 4);
 
         printf("-- status\n");
         stlink_status(sl);
 
         printf("-- reset\n");
         stlink_reset(sl);
+        stlink_force_debug(sl);
+        /* Test reg write*/
+        stlink_write_reg(sl, 0x01234567, 3);
+        stlink_write_reg(sl, 0x89abcdef, 4);
+        stlink_write_reg(sl, 0x12345678, 15);
+        for (off = 0; off < 21; off += 1)
+            stlink_read_reg(sl, off, &regs);
+        
+       
+        stlink_read_all_regs(sl, &regs);
 
         printf("-- status\n");
         stlink_status(sl);