Let's build our own On Chip Debugger application - STEP 1

 Do you remember the old nice times when we had only Microsoft debug?!


Well, it's time to extend our AURIX™ocd with the dump and ascii features!


Add the Dump feature

This feature can be easily added by creating a new command:
Dump memory:          dump <addr> <n_bytes>

thus imply a read loop from the given address, as in the below code snippet:

// DUMP viewer
else if (strncmp(cmd, "dump", 8) == 0) {
      if (n_items < 3) {
        printf("Syntax: dump <addr> <n_bytes>\n");
        continue;
      }

      txDemo.addr.address = param0;
  for (uint32_t i=0; i < param1; i++)
  {
  if (i%4 == 0)
  printf("\n0x%8.8X: ", txDemo.addr.address);
    value = 0xEEEEEEEE;   
        ret = mcd->read32(core, &txDemo.addr, &value);
        mcdd_handle_err(stdout, &core, ret);
        printf("0x%8.8X ", value);
txDemo.addr.address += 4;
  }
  printf("\n");
}

resulting into:

Add the Ascii feature

This feature can be easily added by creating a new command:
ASCII viewer:         ascii <addr> <n_bytes>

thus imply a read loop from the given address, as in the below code snippet:
      // ASCII viewer
else if (strncmp(cmd, "ascii", 8) == 0) {
      if (n_items < 3) {
        printf("Syntax: ascii <addr> <n_bytes>\n");
        continue;
      }

  // Local variables
  char c0, c1, c2, c3;

      txDemo.addr.address = param0;
  for (uint32_t i=0; i < param1; i++)
  {
    value = 0xEEEEEEEE;   
        ret = mcd->read32(core, &txDemo.addr, &value);
        mcdd_handle_err(stdout, &core, ret);
// Now print it as HEX and ASCII - byte by byte... little to big endian format
printf("0x%8.8X: ", txDemo.addr.address);
c0 = (value&0xFF);
printf("0x%2.2X-", c0);
c1 = (value>>8)&0xFF;
printf("0x%2.2X-", c1);
c2 = (value>>16)&0xFF;
printf("0x%2.2X-", c2);
c3 = (value>>24)&0xFF;
printf("0x%2.2X  ", c3);
printf("%c %c %c %c\n", c0, c1, c2, c3);
txDemo.addr.address += 4;
  }
  printf("\n");
}

resulting into:




Where in the red box is readable: "Shell > \0 ..", as expected and coded in the respective code (Shell via UART communication (ASCLIN_Shell_UART_1 for KIT_AURIX_TC275_LK)


Add the Seek feature

This feature can be easily added by creating a new command:
Seek in Flash:        seek <addr> <value> <size>

thus imply a read loop from the given address searching for the given value, as in the below code snippet:
      // SEEK
else if (strncmp(cmd, "seek", 8) == 0) {
      if (n_items < 4) {
        printf("Syntax: seek <addr> <value> <size>\n");
        continue;
      }

  bool bFound = FALSE;
      txDemo.addr.address = param0;
  for (uint32_t i=0; i < param2; i++)
  {
  // Scan the memory range seeking for the given 32-bit value
    value = 0xEEEEEEEE;   
        ret = mcd->read32(core, &txDemo.addr, &value);
        mcdd_handle_err(stdout, &core, ret);
if (ret != MCD_RET_ACT_NONE) break;
if (value == param1) {
printf("\nSeek FOUND: 0x%8.8X", param1);
printf(" at addr: 0x%8.8X\n", txDemo.addr.address);
bFound = TRUE;
break;
}
else
printf(".");
txDemo.addr.address += 4;
  }
  if (!bFound) 
  printf("\nSeek FAIL: <value> unfound in the given range [0x%8.8X - 0x%8.8X]\n", param0, txDemo.addr.address);
}

resulting into:


Where in the above screen-shot is visible the result of a 'seek 0x70019000 0x6C656853 1024' command. The execution starts with a loop scanning the memory (from address 0x70019000) for the code 0x6C656853 (that corresponds to the string 'Shel'). Once found, the tool report the searched word. This confirm that at address 0x700194D0 the searched string is located (as already proven by the previous example of 'ascii' command).

Such tool and related source codes are available at https://github.com/aurixinino/aurixocd/tree/main/AURIX_DEBUG_1

Enjoy!! In case of feedbacks, use the below field or place in GitHub, thanks!

Commenti