Read registers using C code?

skxo66
Posts: 6
Joined: Wed Oct 18, 2017 6:26 am

Read registers using C code?

Postby skxo66 » Sun Apr 21, 2019 5:39 pm

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

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Read registers using C code?

Postby ESP_igrr » Tue Apr 23, 2019 1:13 am

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.

esp_Hemal
Posts: 8
Joined: Thu Feb 14, 2019 9:44 am

Re: mbedtls_aes_crypt_ecb VS mbed_internal_aes_encrypt ESP32

Postby esp_Hemal » Tue Apr 23, 2019 9:43 am

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()

skxo66
Posts: 6
Joined: Wed Oct 18, 2017 6:26 am

Re: mbedtls_aes_crypt_ecb VS mbed_internal_aes_encrypt ESP32

Postby skxo66 » Tue Apr 23, 2019 6:09 pm

Hello esp_hermal,

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

Regards
sk

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Read registers using C code?

Postby fly135 » Tue Apr 23, 2019 6:40 pm

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

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Read registers using C code?

Postby ESP_Angus » Tue Apr 23, 2019 11:56 pm

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.

skxo66
Posts: 6
Joined: Wed Oct 18, 2017 6:26 am

Re: Read registers using C code?

Postby skxo66 » Sat Apr 27, 2019 3:46 am

Hi,

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

Regards
sk

Who is online

Users browsing this forum: No registered users and 459 guests