From c445865f366638809d4a49fa867165fb084e1233 Mon Sep 17 00:00:00 2001 From: Dan White Date: Sat, 12 May 2012 20:53:07 -0500 Subject: [PATCH] WIP --- python-lib/mpsse-test.py | 78 ++++++++++++++++++++++------------------ python-lib/usbio.py | 8 ++--- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/python-lib/mpsse-test.py b/python-lib/mpsse-test.py index 79c7f0b..a71b557 100755 --- a/python-lib/mpsse-test.py +++ b/python-lib/mpsse-test.py @@ -111,6 +111,7 @@ for i in range(5, 8): ############################################################################## # ADC # (TODO) +# see 'ADC testing stuff' section below # adc = usbio.ADS8201(spi0) @@ -166,7 +167,7 @@ for h in arb.h: ota.fast = 1 ota.gain = 8 ota.offset = 0 -#arb.write() +arb.write() amux.selA = 48 amux.selB = 48 @@ -175,7 +176,7 @@ for ota in amux.ota: ota.fast = 1 ota.gain = 8 ota.offset = 0 -#amux.write() +amux.write() @@ -227,44 +228,53 @@ if 0: r.append(v) print x, v - figure() - plot(n, r) - xlabel('DAC code') - ylabel('ADC count') - title('DAC_ch0 --> ADC_ch4 direct connection') - savefig('dac-adc-loopback.pdf') - show() + if 0: + figure() + plot(n, r) + xlabel('DAC code') + ylabel('ADC count') + title('DAC_ch0 --> ADC_ch4 direct connection') + savefig('dac-adc-loopback.pdf') + show() ############################################################################## # Flash testing # -flash = usbio.M25PExx(spi0) -flash.power(True) -print flash.status() -print 'id:', str2hex(flash.id()) -print flash.status() -print 'data:', str2hex(flash.read(0x4000, 16)) - -flash.writeEnable(True) - -from intelhex import IntelHex -#h = IntelHex('../msp4th/hello-world.hex') -h = IntelHex('../msp4th/x.hex') -a = [a for a in h.addresses() if (a >= 0x4000 and a < 0xf000)] -alen = max(a) - min(a) -#code = ''.join([chr(h[i]) for i in range(0x4000, 0x10000-2)]) -code = h.gets(0x4000, alen) -#code = 0*'\x00' + code + '\x00\x40' -flash.write(min(a), code) - -vectors = ''.join([chr(h[i]) for i in range(0xff00, 0x10000-2)]) -vectors += '\x00\x40' -flash.write(0xff00, vectors) - -while not flash.isReady(): - print 'waiting...' +if 0: + flash = usbio.M25PExx(spi0) + flash.power(True) + print flash.status() + print 'id:', str2hex(flash.id()) + print flash.status() + print 'data:', str2hex(flash.read(0x4000, 16)) + + flash.writeEnable(True) + + from intelhex import IntelHex + #h = IntelHex('../msp4th/hello-world.hex') + h = IntelHex('../msp4th/x.hex') + + #code space in RAM, only get/send used block of bytes + a = [a for a in h.addresses() if (a >= 0x4000 and a < 0xff00)] + alen = max(a) - min(a) + code = h.gets(0x4000, alen) + flash.write(min(a), code) + + # 0xffd0 -- 0xffff are interrupt vectors + # gcc et.al. for some reason do not give a value for 0xfffe word + # the flash loader in ROM jumps to addr pointed here + # force to start of RAM + # + # the flash uses 256-byte pages, include code from 0xff00 - 0xffcf + # as it was excluded above + vectors = ''.join([chr(h[i]) for i in range(0xff00, 0x10000-2)]) + vectors += '\x00\x40' + flash.write(0xff00, vectors) + + while not flash.isReady(): + print 'waiting...' if 0: nread = 0 diff --git a/python-lib/usbio.py b/python-lib/usbio.py index 9878dc4..a3d4fb8 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -250,11 +250,11 @@ class I2C(object): def pinState(self, bitfield): """Set GPIO pins to given bitfield state, ignoring scl/sda pins.""" - b = intbv(bitfield, max=2**8) - b[self.scl] = self.io[self.scl] - b[self.sda] = self.io[self.sda] + bits = intbv(bitfield, max=2**8) + bits[self.scl] = self.io[self.scl] + bits[self.sda] = self.io[self.sda] print 'port:', b(self.port, 8), '-->', - self.port[:] = d + self.port[:] = bits print b(self.port, 8) ftdi.write_data(self.context, chr(self.port), 1) -- 2.25.1