Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 362dd00

Browse files
committed
Portenta C33 UNO R4 minima UNO R4 WiFi allow usage of TRNG
1 parent 1564d0a commit 362dd00

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

‎cores/arduino/WMath.cpp‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,47 @@
2323

2424
extern "C" {
2525
#include <stdlib.h>
26+
#include "common_data.h"
2627
}
2728

29+
#if defined (ARDUINO_PORTENTA_C33)
30+
#define SCE_TRNG_SUPPORT 1
31+
static long trng()
32+
{
33+
uint32_t value[4];
34+
if (R_SCE_Open(&sce_ctrl, &sce_cfg) != FSP_SUCCESS)
35+
return -1;
36+
R_SCE_RandomNumberGenerate(value);
37+
R_SCE_Close(&sce_ctrl);
38+
return (long)value[0] >= 0 ? value[0] : -value[0];
39+
}
40+
#endif
41+
42+
#if defined(ARDUINO_UNOR4_WIFI) || defined(ARDUINO_UNOR4_MINIMA)
43+
#define SCE_TRNG_SUPPORT 1
44+
extern "C" {
45+
fsp_err_t HW_SCE_McuSpecificInit(void);
46+
fsp_err_t HW_SCE_RNG_Read(uint32_t * OutData_Text);
47+
}
48+
static long trng()
49+
{
50+
uint32_t value[4];
51+
if (HW_SCE_McuSpecificInit() != FSP_SUCCESS)
52+
return -1;
53+
HW_SCE_RNG_Read(value);
54+
return (long)value[0] >= 0 ? value[0] : -value[0];
55+
}
56+
#endif
57+
58+
#if (SCE_TRNG_SUPPORT == 1)
59+
static bool useTRNG = true;
60+
#endif
61+
2862
void randomSeed(unsigned long seed)
2963
{
64+
#if (SCE_TRNG_SUPPORT == 1)
65+
useTRNG = false;
66+
#endif
3067
if (seed != 0) {
3168
srand(seed);
3269
}
@@ -37,6 +74,11 @@ long random(long howbig)
3774
if (howbig == 0) {
3875
return 0;
3976
}
77+
#if (SCE_TRNG_SUPPORT == 1)
78+
if (useTRNG == true) {
79+
return trng() % howbig;
80+
}
81+
#endif
4082
return rand() % howbig;
4183
}
4284

@@ -48,3 +90,5 @@ long random(long howsmall, long howbig)
4890
long diff = howbig - howsmall;
4991
return random(diff) + howsmall;
5092
}
93+
94+
#undef SCE_TRNG_SUPPORT

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /