Skip to content

Commit f9ee683

Browse files
authored
Merge pull request #2611 from adustm/STM32_entropy
STM32 hw entropy
2 parents f5fb485 + 7bb6117 commit f9ee683

File tree

8 files changed

+39
-88
lines changed

8 files changed

+39
-88
lines changed

targets/TARGET_STM/TARGET_STM32F4/trng_api.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

targets/TARGET_STM/TARGET_STM32L0/TARGET_DISCO_L053C8/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ struct i2c_s {
8484
I2CName i2c;
8585
};
8686

87+
struct trng_s {
88+
RNG_HandleTypeDef handle;
89+
};
90+
8791
#include "common_objects.h"
8892
#include "gpio_object.h"
8993

targets/TARGET_STM/TARGET_STM32L0/TARGET_NUCLEO_L073RZ/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ struct i2c_s {
8484
I2CName i2c;
8585
};
8686

87+
struct trng_s {
88+
RNG_HandleTypeDef handle;
89+
};
90+
8791
#include "common_objects.h"
8892
#include "gpio_object.h"
8993

targets/TARGET_STM/TARGET_STM32L4/TARGET_DISCO_L476VG/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ struct can_s {
9090
int index;
9191
};
9292

93+
struct trng_s {
94+
RNG_HandleTypeDef handle;
95+
};
96+
9397
#include "common_objects.h"
9498
#include "gpio_object.h"
9599

targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L432KC/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ struct can_s {
9090
int index;
9191
};
9292

93+
struct trng_s {
94+
RNG_HandleTypeDef handle;
95+
};
96+
9397
#include "gpio_object.h"
9498
#include "common_objects.h"
9599

targets/TARGET_STM/TARGET_STM32L4/TARGET_NUCLEO_L476RG/objects.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ struct can_s {
9090
int index;
9191
};
9292

93+
struct trng_s {
94+
RNG_HandleTypeDef handle;
95+
};
96+
9397
#include "common_objects.h"
9498
#include "gpio_object.h"
9599

targets/TARGET_STM/TARGET_STM32F7/trng_api.c renamed to targets/TARGET_STM/trng_api.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Hardware entropy collector for the STM32F7 family
2+
* Hardware entropy collector for the STM32 families
33
*
44
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
55
* SPDX-License-Identifier: Apache-2.0
@@ -26,6 +26,7 @@
2626

2727
/** trng_get_byte
2828
* @brief Get one byte of entropy from the RNG, assuming it is up and running.
29+
* @param obj TRNG obj
2930
* @param pointer to the hardware generated random byte.
3031
*/
3132
static void trng_get_byte(trng_t *obj, unsigned char *byte )
@@ -35,13 +36,25 @@ static void trng_get_byte(trng_t *obj, unsigned char *byte )
3536

3637
void trng_init(trng_t *obj)
3738
{
39+
#if defined(TARGET_STM32L4)
40+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
41+
42+
/*Select PLLQ output as RNG clock source */
43+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RNG;
44+
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLL;
45+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
46+
#endif
47+
3848
/* RNG Peripheral clock enable */
3949
__HAL_RCC_RNG_CLK_ENABLE();
4050

4151
/* Initialize RNG instance */
4252
obj->handle.Instance = RNG;
4353
HAL_RNG_Init(&obj->handle);
4454

55+
/* first random number generated after setting the RNGEN bit should not be used */
56+
HAL_RNG_GetRandomNumber(&obj->handle);
57+
4558
}
4659

4760
void trng_free(trng_t *obj)

targets/targets.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,11 +915,11 @@
915915
"supported_form_factors": ["ARDUINO", "MORPHO"],
916916
"core": "Cortex-M0+",
917917
"default_toolchain": "ARM",
918-
"extra_labels": ["STM", "STM32L0", "STM32L073RZ"],
918+
"extra_labels": ["STM", "STM32L0", "STM32L073RZ", "STM32L073xx"],
919919
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
920920
"inherits": ["Target"],
921921
"detect_code": ["0760"],
922-
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
922+
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
923923
"release_versions": ["2", "5"],
924924
"device_name": "STM32L073RZ"
925925
},
@@ -943,7 +943,7 @@
943943
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
944944
"inherits": ["Target"],
945945
"detect_code": ["0770"],
946-
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "CAN", "STDIO_MESSAGES"],
946+
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "CAN", "STDIO_MESSAGES", "TRNG"],
947947
"release_versions": ["2", "5"],
948948
"device_name" : "STM32L432KC"
949949
},
@@ -955,7 +955,7 @@
955955
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
956956
"inherits": ["Target"],
957957
"detect_code": ["0765"],
958-
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
958+
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
959959
"release_versions": ["2", "5"],
960960
"device_name": "stm32l476rg"
961961
},
@@ -1100,7 +1100,7 @@
11001100
"extra_labels": ["STM", "STM32L4", "STM32L476VG"],
11011101
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
11021102
"detect_code": ["0820"],
1103-
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
1103+
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
11041104
"release_versions": ["2", "5"],
11051105
"device_name": "stm32l476vg"
11061106
},

0 commit comments

Comments
 (0)