Problems in SimpleSerial of project

I am now using CW-Lite and CW308-STM32F3 board to do a new project. In my project, I want to read from the fireware using target.simpleserial_read().When I doing the first simpleserial reading command target.simpleserial_read('r', 32), I can get the information from the firmware well. However, the second one return a error:

WARNING:ChipWhisperer Target:Read timed out

and with no responses. I add some time.sleep()here but still don’t work.

Python part:


Firmware:
image
image

Hi,

Does the target ever become responsive after the 'e' command? Can you retry the 's' command after waiting a while and have it work? If not, I’d guess your target is probably becoming unresponsive after the 'e' command.

Alex

Hi,

I tried two ‘s’ command after 5s using time.sleep(5) and found it working well. I can get what I want with 32 bytes seed from target. However, as I changing the firmware with simpleserial_put('r',128, pk), i.e. more bytes for reading, the PC can read the first response and return the information, and the second one return:


image

Because the pk contains 800 bytes in total, so I am guessing maybe I have to read all 800 bytes before the second's' command? It may take a long time for reading?

Also I tried two simpleserial_put() in firmware for reading the more pk but still return:


image
I find that it only get 61 byte not 128 bytes from the second simpleserial_put(), So I am guessing is the buffer can only hold not more than 192 bytes no matter how many simpleserial_put() I used? If I want to read the whole 800 bytes, how can I deal with that?

Magnolia

What’s more, how can I figure out whether the target become responsive? Is it fine to use simpleserial_wait_ack()?

Magnolia

You’ll need to do a separate transmission for each 128 bytes. Something like this should work:

uint8_t get_seed(uint8_t cmd, uint8_t scmd, uint8_t len, uint8_t *buf)
{
    for (uint8_t i = 0; i < 32; i++) seed[i] = buf[i];
    crypto_kem_keypair(seed, pk, sk_a);
    return 0x00;
}

uint8_t tx_pk(uint8_t cmd, uint8_t scmd, uint8_t len, uint8_t *buf)
{
    if (scmd > 7) return 0x10;
    simpleserial_put('r', 100, pk+(100*scmd));
    return 0x00;
}

You can then call add tk_pk() as a simpleserial command and call it 8 times with incrementing scmd to get your full buffer back.

Alex

Hi Alex,

Your solution give me a lot of help! But still I have some problem when reading the data. I got

image
‘t’ command here refer to tx_pk function.

I always got this error and sometimes I got

WARNING:ChipWhisperer Target:Unexpected frame byte in CWbytearray(b’05 65 01 01 d6 00 05 65 01 01 d6 00 05 65 01 01 d6 00 05 65 01 01 d6 00 05 65 01 01 d6 00 05 65 01 01 d6 00 05’)

Can you tell me why this unexpected frame byte warning comes and about read time out error?

Magnolia

This happens because you’re not reading the ack packet from the 's' command. SimpleSerial commands always send back an ack packet to let you know that the command has finished and to report any errors (https://chipwhisperer.readthedocs.io/en/latest/simpleserial.html#simpleserial-v2-1). Try doing a target.simpleserial_wait_ack() after time.sleep(5). It looks like you’re getting an invalid command error, which indicates that the command you’re trying to call hasn’t been added via simpleserial_addcmd().

Alex

I trid adding a target.simpleserial_wait_ack() after time.sleep(5) and return a error of read time out and device did not ack. I then tried the 'hello' and print(target.read()) but failed to print after the boot. I really don’t know what’s wrong here.
265589704250039861
455792765712749134

Magnolia

Hi

I learned a lot from your answers.But I ran into problems when I operated on my own.
If i want to separate transmission for each 128 bytes in simpleserial V1 and 1632 bytes in total.
The callback function did not have scmd parameter.
Please tell me what should I do.

Ssx

Yeah simpleserial v1 doesn’t have scmd. You’ll have to figure your own method of indexing the data to send back.

Alex