Hi,
I am trying to use the HW True Random Number Generation (TRNG) on RA6T2.
I pulled in the Mbed TLS (Crypto Only) stack using the FSP Configurator in E2studio. This has a lot of configuration which I find hard to understand, but I set it up so it appears to be happy. But if I try calling psa_crypto_init(), the function hangs The code where it hangs appears to have been obfusticated: there is a loop in HW_SCE_func100 which is stuck polling a register SCE->REG_104H_b.B31.
What I really need is some guidance / example code on how to set this up. But I find that GitHub - renesas/ra-fsp-examples: Example projects for Renesas RA MCU family does not have any mbed_crypto example for this processor, or for other very similar processors.
Does this software stack work on the RA6T2 processor, and if not, how can I use the TRNG functionality?
Thanks,
Chris
Hello Chris,If you only want to use the TRNG you could use the following procedure, which is quite simple.At first, include the r_sce5b_ra6 component from the Components tab of the FSP configuration panel.Then, add the following lines in your main app:
fsp_err_t HW_SCE_McuSpecificInit(void);
fsp_err_t HW_SCE_RNG_Read (uint32_t * OutData_Text);
void hal_entry (void)
{
fsp_err_t err;
uint32_t trngNumber[4];
err=HW_SCE_McuSpecificInit();
while (1)
err = HW_SCE_RNG_Read(trngNumber);
if(err != FSP_SUCCESS)
__BKPT(0);
}
Hope I could help you.Thank you,Panos
Thanks very much Panos, that's very helpful and seems to work. But can you advise where I might find documentation for the API to this r_sce5b_ra6 component? The functions seem to be declared in header files suffixed _private, and I can't find any documentation as to what they do?
I can see that the TRNG access is a very simple API, but we may want to access some of the other SCE5B hardware functionality.
Hello Chris,This app note describe the SCE capabilities.Unfortunately, a more detailed documentation on how to use the r_sce5b_ra6 is not currently available. You could dig into the files of this module and get more info from the short comment description, which is not the most convenient way.Please feel free to post a question in case you need further assistance.Thank you,Panos
It is not fit for purpose, frankly. I don't see any "short comment description", in fact, quite the opposite. HW_SCE_RNG_Read() calls HW_SCE_GenerateRandomNumberSub(), which is an obfusticated function: all the variables have meaningless names, and they access registers called REG_100H, REG_104H etc.
So please tell me, how did you know to allocate 16 bytes for trngNumber? An undocumented function which writes 16 bytes into a 32-bit pointer seems to be a "trap for the unwary", to say the least!