Skip to content

Instantly share code, notes, and snippets.

@CreateRemoteThread
Last active November 8, 2019 11:01
Show Gist options
  • Save CreateRemoteThread/31e8d83c16bd626517e3d44758e2f8a9 to your computer and use it in GitHub Desktop.
Save CreateRemoteThread/31e8d83c16bd626517e3d44758e2f8a9 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from __future__ import print_function, division
import time
import logging
import os
from collections import namedtuple
import csv
import numpy as np
import chipwhisperer as cw
from chipwhisperer.capture.api.programmers import XMEGAProgrammer
logging.basicConfig(level=logging.WARN)
scope = cw.scope()
target = cw.target(scope)
scope.glitch.clk_src = 'clkgen'
scope.gain.gain = 45
scope.adc.samples = 3000
scope.adc.offset = 0
scope.adc.basic_mode = "rising_edge"
scope.clock.clkgen_freq = 7370000
scope.clock.adc_src = "clkgen_x4"
scope.trigger.triggers = "tio4"
scope.io.tio1 = "serial_rx"
scope.io.tio2 = "serial_tx"
# scope.io.hs2 = "glitch"
scope.io.hs2 = "clkgen"
scope.glitch.output = "glitch_only"
scope.io.glitch_lp = True
print(scope.io.glitch_lp)
target.go_cmd = ""
target.key_cmd = ""
print("Erase target...")
# program the XMEGA with the built hex file
programmer = XMEGAProgrammer()
programmer.scope = scope
programmer._logging = None
programmer.find()
programmer.erase()
print("Programming...")
programmer.program("glitchsimple.hex", memtype="flash", verify=True)
programmer.close()
scope.glitch.trigger_src = 'ext_single'
scope.glitch.repeat = 55
traces = []
outputs = []
widths = []
offsets = []
Range = namedtuple('Range', ['min', 'max', 'step'])
width_range = Range(20,40, 2)
offset_range = Range(-10,10, 3)
# pew pew pew
scope.glitch.width = width_range.min
target.init()
scope.glitch.ext_offset = 10
while scope.glitch.width < width_range.max:
scope.glitch.offset = offset_range.min
while scope.glitch.offset < offset_range.max:
target.ser.flush()
# reset target.
scope.io.pdic = 'low'
scope.io.pdic = 'high'
scope.arm()
timeout = 1000
while target.isDone() is False and timeout:
timeout -= 1
ime.sleep(0.01)
try:
ret = scope.capture()
if ret:
logging.warning('Timeout happened during acquisition')
except IOError as e:
logging.error('IOError: %s' % str(e))
trace = scope.getLastTrace()
output = target.ser.read(32, timeout=1000)
print("%d:%d:%s" % (scope.glitch.offset,scope.glitch.width,repr(output)))
traces.append(trace)
outputs.append(output)
widths.append(scope.glitch.width)
offsets.append(scope.glitch.width)
scope.glitch.offset += offset_range.step
scope.glitch.width += width_range.step
print('Done')
scope.dis()
target.dis()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment