This repository was archived by the owner on Mar 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-8
lines changed Expand file tree Collapse file tree 3 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -458,8 +458,7 @@ int main(void) {
458
458
#endif
459
459
460
460
#if MICROPY_HW_ENABLE_RNG
461
- // RNG
462
- rng_init ();
461
+ rng_init0 ();
463
462
#endif
464
463
465
464
#if MICROPY_HW_ENABLE_TIMER
Original file line number Diff line number Diff line change
1
+ #include <string.h>
2
+
1
3
#include "stm32f4xx_hal.h"
2
4
3
5
#include "misc.h"
6
8
#include "obj.h"
7
9
#include "rng.h"
8
10
9
- STATIC RNG_HandleTypeDef RngHandle ;
11
+ #if MICROPY_HW_ENABLE_RNG
12
+
13
+ STATIC RNG_HandleTypeDef RNGHandle = {.Instance = NULL };
14
+
15
+ void rng_init0 (void ) {
16
+ // reset the RNG handle
17
+ memset (& RNGHandle , 0 , sizeof (RNG_HandleTypeDef ));
18
+ RNGHandle .Instance = RNG ;
19
+ }
10
20
11
21
void rng_init (void ) {
12
22
__RNG_CLK_ENABLE ();
13
- RngHandle .Instance = RNG ;
14
- HAL_RNG_Init (& RngHandle );
23
+ HAL_RNG_Init (& RNGHandle );
15
24
}
16
25
17
26
uint32_t rng_get (void ) {
18
- return HAL_RNG_GetRandomNumber (& RngHandle );
27
+ if (RNGHandle .State == HAL_RNG_STATE_RESET ) {
28
+ rng_init ();
29
+ }
30
+ return HAL_RNG_GetRandomNumber (& RNGHandle );
19
31
}
20
32
21
33
STATIC mp_obj_t pyb_rng_get (void ) {
22
- return mp_obj_new_int (HAL_RNG_GetRandomNumber (& RngHandle ) >> 2 );
34
+ if (RNGHandle .State == HAL_RNG_STATE_RESET ) {
35
+ rng_init ();
36
+ }
37
+ return mp_obj_new_int (HAL_RNG_GetRandomNumber (& RNGHandle ) >> 2 );
23
38
}
24
39
25
40
MP_DEFINE_CONST_FUN_OBJ_0 (pyb_rng_get_obj , pyb_rng_get );
41
+
42
+ #endif // MICROPY_HW_ENABLE_RNG
Original file line number Diff line number Diff line change 1
- void rng_init (void );
1
+ void rng_init0 (void );
2
2
uint32_t rng_get (void );
3
3
4
4
MP_DECLARE_CONST_FUN_OBJ (pyb_rng_get_obj );
You can’t perform that action at this time.
0 commit comments