Exemplo n.º 1
0
class SimpleSerial_ChipWhispererLite(SimpleSerialTemplate):
    _name = 'NewAE USB (CWLite/CW1200)'

    def __init__(self):
        SimpleSerialTemplate.__init__(self)
        self._baud = 38400
        self.cwlite_usart = None
        self.params.addChildren([{
            'name': 'baud',
            'type': 'int',
            'key': 'baud',
            'limits': (500, 2000000),
            'get': self.baud,
            'set': self.setBaud,
            'default': 38400
        }])

    def close(self):
        pass

    @setupSetParam("baud")
    def setBaud(self, baud):
        self._baud = baud
        if self.cwlite_usart:
            self.cwlite_usart.init(baud)
        else:
            logging.error('Baud rate not set, need to connect first')

    def baud(self):
        return self._baud

    def con(self, scope=None):
        if scope is None or not hasattr(scope, "qtadc"):
            Warning(
                "You need a scope with OpenADC connected to use this Target")

        scope.connectStatus.connect(self.dis)
        if hasattr(scope, 'qtadc'):
            ser = scope.qtadc.ser
        else:
            ser = scope._cwusb
        self.cwlite_usart = CWL_USART(ser)
        self.cwlite_usart.init(baud=self.findParam('baud').getValue())
        self.params.refreshAllParameters()
        self.connectStatus.setValue(True)

    def hardware_inWaiting(self):
        bwait = self.cwlite_usart.inWaiting()
        if bwait == 127:
            logging.warning(
                'SAM3U Serial buffers OVERRUN - data loss has occurred.')
        return bwait

    def hardware_write(self, string):
        self.cwlite_usart.write(string)

    def hardware_read(self, num, timeout=250):
        return self.cwlite_usart.read(num, timeout)
Exemplo n.º 2
0
class SimpleSerial_ChipWhispererLite(SimpleSerialTemplate):
    _name = 'NewAE USB (CWLite/CW1200)'

    def __init__(self):
        SimpleSerialTemplate.__init__(self)
        self._baud = 38400
        self.cwlite_usart = None
        self.params.addChildren([
            {'name':'baud', 'type':'int', 'key':'baud', 'limits':(500, 2000000), 'get':self.baud, 'set':self.setBaud, 'default':38400}
        ])

    @setupSetParam("baud")
    def setBaud(self, baud):
        self._baud = baud
        if self.cwlite_usart:
            self.cwlite_usart.init(baud)
        else:
            logging.error('Baud rate not set, need to connect first')

    def baud(self):
        return self._baud

    def write(self, string):
        self.cwlite_usart.write(string)

    def inWaiting(self):
        bwait =  self.cwlite_usart.inWaiting()
        if bwait == 127:
            logging.warning('SAM3U Serial buffers OVERRUN - data loss has occurred.')
        return bwait

    def read(self, num=0, timeout=250):
        data = bytearray(self.cwlite_usart.read(num, timeout=timeout))
        result = data.decode('latin-1')
        return result

    def flush(self):
        waiting = self.inWaiting()
        while waiting > 0:
            self.cwlite_usart.read(waiting)
            waiting = self.inWaiting()

    def flushInput(self):
        self.flush()

    def close(self):
        pass

    def con(self, scope = None):
        if scope is None or not hasattr(scope, "qtadc"): Warning("You need a scope with OpenADC connected to use this Target")

        scope.connectStatus.connect(self.dis)
        self.cwlite_usart = CWL_USART(scope.qtadc.ser)
        self.cwlite_usart.init(baud=self.findParam('baud').getValue())
        self.params.refreshAllParameters()
        self.connectStatus.setValue(True)
Exemplo n.º 3
0
class SimpleSerial_ChipWhispererLite(SimpleSerialTemplate):
    _name = 'NewAE USB (CWLite/CW1200)'

    def __init__(self):
        SimpleSerialTemplate.__init__(self)
        self._baud = 38400
        self.cwlite_usart = None

    def close(self):
        pass

    def setBaud(self, baud):
        self._baud = baud
        if self.cwlite_usart:
            self.cwlite_usart.init(baud)
        else:
            logging.error('Baud rate not set, need to connect first')

    def baud(self):
        return self._baud

    def con(self, scope=None):
        if scope is None or not hasattr(scope, "qtadc"):
            Warning(
                "You need a scope with OpenADC connected to use this Target")

        if hasattr(scope, 'qtadc'):
            ser = scope.qtadc.ser
        else:
            ser = scope._cwusb
        self.cwlite_usart = CWL_USART(ser)
        self.cwlite_usart.init(baud=self._baud)

    def hardware_inWaiting(self):
        bwait = self.cwlite_usart.inWaiting()
        if bwait == 127:
            logging.warning(
                'SAM3U Serial buffers OVERRUN - data loss has occurred.')
        return bwait

    def hardware_write(self, string):
        self.cwlite_usart.write(string)

    def hardware_read(self, num, timeout=250):
        return self.cwlite_usart.read(num, timeout)
Exemplo n.º 4
0
            except IOError:
                xmega.enablePDI(False)
                xmega.enablePDI(True)

            fakedata = [i & 0xff for i in range(0, 2048)]
            print("Programming FLASH Memory")
            xmega.writeMemory(0x0800000, fakedata, memname="flash")

            print("Verifying")
            test = xmega.readMemory(0x0800000, 512)

            print(test)

        except TypeError as e:
            print(str(e))

        except IOError as e:
            print(str(e))

        xmega.enablePDI(False)

    print("Let's Rock and Roll baby")

    sertest = True

    if sertest:
        usart.init()
        usart.write("hello\n")
        time.sleep(0.1)
        print(usart.read())
Exemplo n.º 5
0
class SerialContext(Context):
    '''Base context for targets that need serial communications.
    
    UART is the only IO CWLite has, so you probably need this.
    
    This discards the chipwhisperer library's target system,
    as I've found it's a little obtuse to work with unless your
    target is already made by NewAE, which it won't be unless you're
    doing exercises. This just gives you some serial read/write methods
    and you can do what you want. Easy.

    See https://github.com/newaetech/chipwhisperer/blob/4fdaf07d7c573b5b78109f66e964e0217ae6b6d0/software/chipwhisperer/capture/targets/simpleserial_readers/cwlite.py
    for how the USB-serial interface is implemented in the chipwhisperer library.
    '''
    def __init__(self, scope, baudrate, stopbits=1, parity="none"):
        '''
        up to 250000 baud is supported
        stopbits can be 1, 1.5, or 2
        parity can be one of "none","odd","even","mark","space
        '''
        super().__init__(scope)

        # TODO: sanity check these
        self.baudrate = baudrate
        self.stopbits = stopbits
        self.parity = parity

        self.serial = USART(self.scope._getNAEUSB())
        self.serial.init(baudrate, stopbits, parity)

    def read(self, n_chars, timeout=250):
        '''Read `n_chars` over UART.
        
        Timeout isn't necessarily a time value, just an indicator
        that it will wait a while for data to show up.
        
        If n_chars = 0, all data present is returned.
        This will return data in a list, so if there is no data you will receive an empty list.
        '''
        return bytes(self.serial.read(n_chars, timeout))

    def write(self, data):
        '''Write `data` over UART.
        
        Data can be a bytestring or normal string.
        If it's a normal string, it will be encoded as latin-1.
        '''
        self.serial.write(data)

    def flush(self):
        '''Delete all data from the UART Rx buffer.'''
        self.serial.flush()

    def test_setup(self):
        '''Called by the search strategy before an iteration should start.
        
        You can put device setup things here, like resetting and initializing state
        especially if they don't need to happen every iteration.
        '''
        pass

    def test_one(self):
        '''Called by the search strategy when it is time to do a test.
        
        You can put all of your logic here if it's simple enough.
        '''
        pass

    def test_teardown(self):
        '''Called by the search strategy after the test is performed and processed.
        
        You can put device teardown things here, like serial buffer flushing.
        '''
        pass