CWLite trace capturing outside Jupyter


#1

Hi,

I’m using CW5 and the CWLite with XMEGA hardware. I get to run the tutorials in Jupyter, but I would like to do the data collection and analysis in a different Python environment (I decided on PyCharm). I’m quite new to this, both the CW as well as Python, so this might easily be a rookie mistake. I’m also running Windows 10. I run the following bash code and it compiles fine:

cd /cygdrive/c/chipwhisperer/hardware/victims/firmware/simpleserial-aes
make PLATFORM=“CWLITEXMEGA” CRYPTO_TARGET=“AVRCRYPTOLIB”’

My Python code looks like this:

SCOPETYPE = “OPENADC”
PLATFORM = “CWLITEXMEGA”
CRYPTO_TARGET = “AVRCRYPTOLIB”
num_traces = 50
CHECK_CORR = False

import chipwhisperer as cw
scope = cw.scope()
target = cw.target(scope)

if “STM” in PLATFORM or PLATFORM == “CWLITEARM” or PLATFORM == “CWNANO”:
prog = cw.programmers.STM32FProgrammer
elif PLATFORM == “CW303” or PLATFORM == “CWLITEXMEGA”:
prog = cw.programmers.XMEGAProgrammer
else:
prog = None

import time
time.sleep(0.05)
scope.default_setup()
def reset_target(scope):
if PLATFORM == “CW303” or PLATFORM == “CWLITEXMEGA”:
scope.io.pdic = ‘low’
time.sleep(0.05)
scope.io.pdic = ‘high_z’ #XMEGA doesn’t like pdic driven high
time.sleep(0.05)
else:
scope.io.nrst = ‘low’
time.sleep(0.05)
scope.io.nrst = ‘high’
time.sleep(0.05)

fw_path = “c:/chipwhisperer/hardware/victims/firmware/simpleserial-aes/simpleserial-aes-{}.hex”.format(PLATFORM)
cw.program_target(scope, prog, fw_path)
project = cw.create_project(“c:/CW_projects/Tutorial_B5”, overwrite = True)

from tqdm import tnrange
ktp = cw.ktp.Basic()

for i in tnrange(num_traces, desc=‘Capturing traces’):
key, text = ktp.next() # manual creation of a key, text pair can be substituted here
trace = cw.capture_trace(scope, target, text, key)
if trace is None:
continue
project.traces.append(trace)

It seems to be running fine since I get this response from the PyCharm IDE:

C:\PycharmProjects\CW_AES_1\venv\Scripts\python.exe C:/PycharmProjects/CW_AES_1/venv/DataCapture.py
XMEGA Programming flash…
XMEGA Reading flash…
Verified flash OK, 3471 bytes
HBox(children=(IntProgress(value=0, description=‘Capturing traces’, max=50, style=ProgressStyle(description_width=‘initial’)), HTML(value=’’)))

Process finished with exit code 0

The problem is that the “traces” folder is empty. Any obvious reasons for this?

Thanks!


#2

Sorry that my code formatting ended up like that, this is my first time using the forum.


#3

Hi,

You can format code on the forum with markdown, i.e. triple-backticks for code blocks.
I haven’t used Pycharm, maybe someone else has?
Best guess is that you’re missing a project.save(), which should exist in the tutorial you copied the code from :wink:

Strong recommend against ditching Jupyter, especially if you’re new to Python. Jupyter makes it a lot easier to follow the tutorials, understand them, and tweak them.

Jean-Pierre


#4

Ah perfect. Saving the project did the trick :wink: