Example #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}
        ])

    @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)
Example #2
0
    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 __init__(self):
        self._cwusb = NAEUSB()

        # Connect required modules up here
        self.fpga = FPGA(self._cwusb)
        self.xmega = XMEGAPDI(self._cwusb)
        self.avr = AVRISP(self._cwusb)
        self.usart = USART(self._cwusb)

        self.getParams().addChildren([{
            'name':
            "CW-Lite XMEGA Programmer",
            'tip':
            "Open XMEGA Programmer (ChipWhisperer-Lite Only)",
            'type':
            "menu",
            "action":
            lambda _: self.getCwliteXMEGA().show()
        }, {
            'name':
            "CW-Lite AVR Programmer",
            'tip':
            "Open AVR Programmer (ChipWhisperer-Lite Only)",
            'type':
            "menu",
            "action":
            lambda _: self.getCwliteAVR().show()
        }])
Example #4
0
    def __init__(self):
        ScopeTemplate.__init__(self)
        self._is_connected = False

        self.params.init()

        self._cwusb = NAEUSB()
        self.ser = self._cwusb
        self.scopetype = self
        self.dev = self

        self.xmega = XMEGAPDI(self._cwusb)
        self.avr = AVRISP(self._cwusb)
        self.usart = USART(self._cwusb)
        self.serialstm32f = STM32FSerial(cwserial=self.usart)
        self.serialstm32f.scope = self
        self.io = GPIOSettings(self._cwusb)
        self.adc = ADCSettings(self._cwusb)
        self.glitch = GlitchSettings(self._cwusb)
        self._timeout = 2

        self._lasttrace = None

        self.getParams().addChildren([
            {'name':"CW-Lite XMEGA Programmer", 'tip':"Open XMEGA Programmer (ChipWhisperer-Lite Only)", 'type':"menu", "action":lambda _:self.getCwliteXMEGA().show()},
            {'name':"CW-Lite AVR Programmer", 'tip':"Open AVR Programmer (ChipWhisperer-Lite Only)", 'type':"menu", "action":lambda _:self.getCwliteAVR().show()},
            {'name':'Serial STM32F Programmer', 'tip':"Open STM32F Programmer (Serial/ChipWhisperer)", 'type':"menu", "action":lambda _:self.getSerialSTM32F().show()}
        ])

        self.disable_newattr()
Example #5
0
    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)
Example #6
0
    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)
    def __init__(self):
        self._cwusb = NAEUSB()

        # Connect required modules up here
        self.fpga = FPGA(self._cwusb)
        self.xmega = XMEGAPDI(self._cwusb)
        self.avr = AVRISP(self._cwusb)
        self.usart = USART(self._cwusb)
        self.serialstm32f = STM32FSerial(cwserial=self.usart, cwapi=None)
Example #8
0
    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)
Example #9
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)
Example #10
0
    def __init__(self):
        ScopeTemplate.__init__(self)
        self._is_connected = False

        self._cwusb = NAEUSB()
        self.ser = self._cwusb
        self.scopetype = self
        self.dev = self

        self.xmega = XMEGAPDI(self._cwusb)
        self.avr = AVRISP(self._cwusb)
        self.usart = USART(self._cwusb)
        self.serialstm32f = STM32FSerial(cwserial=self.usart)
        self.serialstm32f.scope = self
        self.io = GPIOSettings(self._cwusb)
        self.adc = ADCSettings(self._cwusb)
        self.glitch = GlitchSettings(self._cwusb)
        self._timeout = 2

        self._lasttrace = None

        self.disable_newattr()
Example #11
0
    def __init__(self):
        self._cwusb = NAEUSB()

        # Connect required modules up here
        self.fpga = FPGA(self._cwusb)
        self.xmega = XMEGAPDI(self._cwusb)
        self.avr = AVRISP(self._cwusb)
        self.usart = USART(self._cwusb)
        self.serialstm32f = STM32FSerial(cwserial=self.usart,
                                         cwapi=CWCoreAPI.getInstance())

        self.getParams().addChildren([{
            'name':
            "CW-Lite XMEGA Programmer",
            'tip':
            "Open XMEGA Programmer (ChipWhisperer-Lite Only)",
            'type':
            "menu",
            "action":
            lambda _: self.getCwliteXMEGA().show()
        }, {
            'name':
            "CW-Lite AVR Programmer",
            'tip':
            "Open AVR Programmer (ChipWhisperer-Lite Only)",
            'type':
            "menu",
            "action":
            lambda _: self.getCwliteAVR().show()
        }, {
            'name':
            'Serial STM32F Programmer',
            'tip':
            "Open STM32F Programmer (Serial/ChipWhisperer)",
            'type':
            "menu",
            "action":
            lambda _: self.getSerialSTM32F().show()
        }])
Example #12
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)
Example #13
0

if __name__ == '__main__':
    from chipwhisperer.hardware.naeusb.fpga import FPGA
    from chipwhisperer.hardware.naeusb.programmer_avr import AVRISP
    from chipwhisperer.hardware.naeusb.programmer_xmega import XMEGAPDI, supported_xmega
    from chipwhisperer.hardware.naeusb.serial import USART

    cwtestusb = NAEUSB()
    cwtestusb.con()

    #Connect required modules up here
    fpga = FPGA(cwtestusb)
    xmega = XMEGAPDI(cwtestusb)
    avr = AVRISP(cwtestusb)
    usart = USART(cwtestusb)

    force = True
    if fpga.isFPGAProgrammed() == False or force:
        from datetime import datetime
        starttime = datetime.now()
        fpga.FPGAProgram(
            open(
                r"C:\E\Documents\academic\sidechannel\chipwhisperer\hardware\capture\chipwhisperer-lite\hdl\cwlite_ise\cwlite_interface.bit",
                "rb"))
        # fpga.FPGAProgram(open(r"C:\Users\colin\dropbox\engineering\git_repos\CW305_ArtixTarget\temp\artix7test\artix7test.runs\impl_1\cw305_top.bit", "rb"))
        # fpga.FPGAProgram(open(r"C:\E\Documents\academic\sidechannel\chipwhisperer\hardware\api\chipwhisperer-lite\hdl\cwlite_ise_spifake\cwlite_interface.bit", "rb"))
        stoptime = datetime.now()
        print("FPGA Config time: %s" % str(stoptime - starttime))

    # print fpga.cmdReadMem(10, 6)
Example #14
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