-
Notifications
You must be signed in to change notification settings - Fork 323
Description
Hi,
as I would like to test my own crypto implementation on the CW, I read the documentation and example on "Custom Firmware on ChipWhisperer Targets" (this file) and tried following the steps and code outlined there as a first example.
However, when I copy the code as-is (for a simpleserial-xor.c and a Makefile) and use a basic Python script to flash the firmware and attempt to capture a trace, I keep getting a Device reported error invalid comand (0x1) error.
I build the firmware with make -j PLATFORM=CW308_STM32F3.
Interestingly, this problem disappears and everything works as expected if I change the letters used for the commands in the simpleserial-xor.c file. For example, if I change the letters for sending a key and plaintext from k and p to i and j, everything works.
I suspect this is due to the automatic translation of p and k commands done in the SimpleSerial2.py simpleserial_write() function.
Is my code failing because simpleserial_write() is not the intended way to communicate with the target when using SimpleSerial version 2.1 and I should rather use send_cmd(), or is there a different reason why I'm seeing this behaviour?
The Python code I am using is this:
import chipwhisperer as cw
def connect_cw(target_type=cw.targets.SimpleSerial):
scope = cw.scope()
target = cw.target(scope, target_type)
return scope, target
def disconnect_cw():
scope.dis()
target.dis()
def reset_target(scope):
scope.io.nrst = 'low'
time.sleep(0.05)
scope.io.nrst = 'high_z'
time.sleep(0.05)
if __name__ == '__main__':
scope, target = connect_cw(cw.targets.SimpleSerial2)
scope.default_setup()
prog = cw.programmers.STM32FProgrammer
reset_target(scope)
cw.program_target(
scope, prog,
"./firmware/simpleserial-xor/simpleserial-xor-CW308_STM32F3.hex"
)
ktp = cw.ktp.Basic()
key, text = ktp.next()
target.flush()
target.simpleserial_write('k', key)
ack = target.simpleserial_wait_ack()
scope.arm()
target.simpleserial_write('p', text)
ret = scope.capture()
if ret:
raise IOError("Timeout during capture.")
else:
print("Capture successful.")
trace = scope.get_last_trace();
print(trace)