memtest-hyperram.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python3
  2. #
  3. # memtest-hyperram.py
  4. #
  5. # Control software for testing the HyperRAM
  6. #
  7. # Copyright (C) 2020-2021 Sylvain Munaut <tnt@246tNt.com>
  8. # SPDX-License-Identifier: MIT
  9. #
  10. import sys
  11. from memtest import WishboneInterface, MemoryTester, HDMIOutput
  12. from memtest import HyperRAMController
  13. # ----------------------------------------------------------------------------
  14. # Main
  15. # ----------------------------------------------------------------------------
  16. def RAM_ADDR_CS(cs, addr):
  17. return (cs << 30) | addr
  18. def main(argv0, port='/dev/ttyUSB1', filename=None):
  19. # Connect to board
  20. wb = WishboneInterface(port)
  21. # Devices on the bus
  22. hyperram = HyperRAMController(wb, 0x00000)
  23. memtest = MemoryTester(wb, 0x10000)
  24. hdmi = HDMIOutput(wb, 0x20000)
  25. # Make sure to disable DMA
  26. hdmi.disable()
  27. wb.aux_csr(0)
  28. # Initialize HyperRAM core
  29. if hyperram.init() is False:
  30. print("[!] Init failed")
  31. return -1
  32. hyperram.set_runtime(True)
  33. # What mode ?
  34. if filename is None:
  35. # Run memtest
  36. for cs in range(4):
  37. if not (hyperram.csm & (1 << cs)):
  38. continue
  39. print("[+] Testing CS=%d" % cs)
  40. good = memtest.run(RAM_ADDR_CS(cs, 0), 1<<21)
  41. if good:
  42. print("[.] All good !")
  43. else:
  44. print("[!] Errors found !")
  45. else:
  46. # Load data file
  47. print("[+] Uploading image data")
  48. img = open(filename, 'rb').read()
  49. img = bytearray([(a << 4) | b for a, b in zip(img[0::2], img[1::2])])
  50. memtest.load_data(RAM_ADDR_CS(3, 0), img)
  51. # Palette (1:1)
  52. print("[+] Uploading palette")
  53. for i in range(4*16):
  54. hdmi.pal_write(i, i&15)
  55. # Start DMA
  56. print("[+] Starting DMA")
  57. wb.aux_csr(1)
  58. hdmi.enable(RAM_ADDR_CS(3, 0), 16)
  59. # Done
  60. return 0
  61. if __name__ == '__main__':
  62. sys.exit(main(*sys.argv) or 0)