Page 1 of 1

Read registers using C code?

Posted: Sun Apr 21, 2019 5:39 pm
by skxo66
Hello,

I would like to read back the key once I finished my crypto computation.
Do you know, please, how I can read back the value of the AES stored into the registers AES_KEY_0_REG ~ AES_KEY_3_REG (0x3ff01010-0x3ff0101C), once the set_key has been processed?
The reference manual shows Access R/W for these registers.

I have tried different code in arduino core such as:
Serial.print("K=");
for (int i = 0; i < 4; i++) {
char str[6];
keyreg= *((volatile uint32_t *) (0x3ff01010+0x4*i));
sprintf(str, "%04x", (int)keyreg);
Serial.print(str);
}
But no success. As I see is all 0. Did I make a mistake?
I have also tried REG_READ function defined into soc.h but not compilation fails...

If someone has a code example, it would be perfect, even if it is not for these specific registers.
Regards
sk

Re: Read registers using C code?

Posted: Tue Apr 23, 2019 1:13 am
by ESP_igrr
For these registers you should use DPORT_REG_READ macro. If you still have a compilation error when using DPORT_REG_READ, please post the error here.
If all the registers of a peripheral read back as 0, then it might mean that you haven't enabled clock for the peripheral and taken it out of reset. See periph_module_enable and periph_module_reset functions.

Re: mbedtls_aes_crypt_ecb VS mbed_internal_aes_encrypt ESP32

Posted: Tue Apr 23, 2019 9:43 am
by esp_Hemal
Hi SK,

It's a documentation error. The AES_KEY registers are WRITE ONLY and hence will always return 0 when read

As suggested on other thread in general the dport registers should be read with DPORT_REG_READ()

Re: mbedtls_aes_crypt_ecb VS mbed_internal_aes_encrypt ESP32

Posted: Tue Apr 23, 2019 6:09 pm
by skxo66
Hello esp_hermal,

thanks for your explanation.
It makes sense these registers are set to write only for real :-) and not RW.

Regards
sk

Re: Read registers using C code?

Posted: Tue Apr 23, 2019 6:40 pm
by fly135
READ_REG works for me for reading EFUSE_BLK3_RDATA6_REG. I'm using it in a CPP file, but doubt that would make it compile better than C. Since you didn't bother to list the compile error, you won't get much help here. But I'm guessing it's a missing header include.

Or maybe those registers require you to use the PORT command as described above.

John A

Re: Read registers using C code?

Posted: Tue Apr 23, 2019 11:56 pm
by ESP_Angus
Moderator's note: This question was asked in two places and I've merged the responses here. If replies seem to not make sense, this is because not all of the posts were originally in this thread.

Re: Read registers using C code?

Posted: Sat Apr 27, 2019 3:46 am
by skxo66
Hi,

thanks you all for your remarks.
I will try what you are pointing and keep you updated.

Regards
sk