This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] AM62x, AM62Ax, AM62D-Q1, AM62P, AM62L, AM64x, AM243x: Compare OSPI Registers

Part Number: AM625


Context:

In MCU+ SDK and MCAL SDK, often while debugging OSPI & FLASH related failures, we come at a stage where comparing the OSPI Controller Register helps us debug faster. Comparing each register and their respective bit fields takes considerable time. 

This FAQ covers an easier way to differentiate between two sets of registers using a script and an XML file.

Current Method: Requires the user to look back and forth at the TRM Register bit field values and compare them, which consumes more time.

Proposed Method: The script will give you the differences, see a sample register(0xFC40000) difference as shown below:

  • Step 1: Getting the OSPI Register Dump Files

    Once you have put a breakpoint at a certain point in your application code file/drivers, then you can proceed to open "Memory Browser" in CCS.

    In "Memory Browser", enter the address 0xFC40000. There will be an option to "Save Memory"/"Export". Click the same and follow the next steps.

    Provide the file path as follows and select the File Type as "TI Data". Note, here it says the file name as "dump1.txt". The other file where you will have different set of register values starting 0xFC40000, should be named as "dump2.txt".

    Specify the Start Address as 0xFC40000 and number of memory words to read as 64. Please see the relevant screenshot.

    Once done, you will end up having two sets of files "dump1.txt" and "dump2.txt".

  • Step 2: Preparing The Files

    In the obtained file, remove the first line. The first line would like like this: "1651 9 fc40000 0 40 0" and get rid of the space at the bottom of the file as well.

    So the file will have the register values one by one in the following format: (Attaching contents of a sample file)

    C1183881
    140333EE
    00000002
    64641818
    0000002D
    00101003
    00000080
    00000000
    00000000
    00000000
    00000000
    00000000
    00000001
    00000001
    00010005
    FFFFFFFF
    00000000
    00000040
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    FFFFFFFF
    00000000
    00000000
    00000004
    00000000
    00000000
    00000000
    5ABB0400
    00000000
    00000000
    00000000
    50505044
    00000000
    43060080
    00000000
    00000000
    00000000
    00800000
    00FF81F9
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    00000000
    EEEDFA5A
    06F90000
    00000000
    00000000
    00000000
    00000000
    00000000
    03000300

  • Step 3: Running The Python Script

    Create a separate directory to store the following files:

    • dump1.txt and dump2.txt
    • script.py, download this file, by clicking this: 
      import xml.etree.ElementTree as ET
      
      def parse_registers_from_xml(xml_file):
          tree = ET.parse(xml_file)
          root = tree.getroot()
      
          registers = {}
          for reg in root.findall(".//register"):
              offset = int(reg.get("offset"), 16)
              reg_name = reg.get("id")
              bitfields = []
              for bf in reg.findall(".//bitfield"):
                  bf_id = bf.get("id")
                  begin = int(bf.get("begin"))
                  end = int(bf.get("end"))
                  bitfields.append({"id": bf_id, "begin": begin, "end": end})
              registers[offset] = {"name": reg_name, "bitfields": bitfields}
          return registers
      
      
      def read_dump_file(filename):
          with open(filename) as f:
              lines = [int(line.strip(), 16) for line in f if line.strip()]
          return lines
      
      
      def extract_bitfield_value(value, begin, end):
          width = begin - end + 1
          mask = (1 << width) - 1
          return (value >> end) & mask
      
      
      def compare_dumps(xml_map, dump1, dump2):
          print("Comparing register dumps...\n")
          for i, (v1, v2) in enumerate(zip(dump1, dump2)):
              offset = i * 4
              if v1 != v2:
                  reg = xml_map.get(offset)
                  if not reg:
                      print(f"Offset 0x{offset:02X}: Value changed from {v1:#010x} → {v2:#010x} (Unknown register)")
                      continue
      
                  print(f"Register @ 0x{offset:02X} ({reg['name']}):")
                  print(f"    Old: 0x{v1:08X}")
                  print(f"    New: 0x{v2:08X}")
      
                  for bf in reg["bitfields"]:
                      old_val = extract_bitfield_value(v1, bf["begin"], bf["end"])
                      new_val = extract_bitfield_value(v2, bf["begin"], bf["end"])
                      if old_val != new_val:
                          print(f"      → Bitfield {bf['id']} ({bf['begin']}:{bf['end']}) changed: {old_val} → {new_val}")
                  print()
      
      
      if __name__ == "__main__":
          xml_file = "register_map.xml"
          dump1_file = "dump1.txt"
          dump2_file = "dump2.txt"
      
          xml_map = parse_registers_from_xml(xml_file)
          dump1 = read_dump_file(dump1_file)
          dump2 = read_dump_file(dump2_file)
      
          compare_dumps(xml_map, dump1, dump2)
    • register_map.xml file, by clicking this: register_map.xml

    Run the python script as follows> python script.py

    Attaching a sample output: