Skip to content

STM32 hw entropy #2611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 0 additions & 82 deletions targets/TARGET_STM/TARGET_STM32F4/trng_api.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct i2c_s {
I2CName i2c;
};

struct trng_s {
RNG_HandleTypeDef handle;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct i2c_s {
I2CName i2c;
};

struct trng_s {
RNG_HandleTypeDef handle;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct can_s {
int index;
};

struct trng_s {
RNG_HandleTypeDef handle;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct can_s {
int index;
};

struct trng_s {
RNG_HandleTypeDef handle;
};

#include "gpio_object.h"
#include "common_objects.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct can_s {
int index;
};

struct trng_s {
RNG_HandleTypeDef handle;
};

#include "common_objects.h"
#include "gpio_object.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Hardware entropy collector for the STM32F7 family
* Hardware entropy collector for the STM32 families
*
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
Expand All @@ -26,6 +26,7 @@

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

void trng_init(trng_t *obj)
{
#if defined(TARGET_STM32L4)
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;

/*Select PLLQ output as RNG clock source */
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RNG;
PeriphClkInitStruct.RngClockSelection = RCC_RNGCLKSOURCE_PLL;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
#endif

/* RNG Peripheral clock enable */
__HAL_RCC_RNG_CLK_ENABLE();

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

/* first random number generated after setting the RNGEN bit should not be used */
HAL_RNG_GetRandomNumber(&obj->handle);

}

void trng_free(trng_t *obj)
Expand Down
10 changes: 5 additions & 5 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,11 +915,11 @@
"supported_form_factors": ["ARDUINO", "MORPHO"],
"core": "Cortex-M0+",
"default_toolchain": "ARM",
"extra_labels": ["STM", "STM32L0", "STM32L073RZ"],
"extra_labels": ["STM", "STM32L0", "STM32L073RZ", "STM32L073xx"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
"inherits": ["Target"],
"detect_code": ["0760"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
"release_versions": ["2", "5"],
"device_name": "STM32L073RZ"
},
Expand All @@ -943,7 +943,7 @@
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
"inherits": ["Target"],
"detect_code": ["0770"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "CAN", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "CAN", "STDIO_MESSAGES", "TRNG"],
"release_versions": ["2", "5"],
"device_name" : "STM32L432KC"
},
Expand All @@ -955,7 +955,7 @@
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
"inherits": ["Target"],
"detect_code": ["0765"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"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"],
"release_versions": ["2", "5"],
"device_name": "stm32l476rg"
},
Expand Down Expand Up @@ -1100,7 +1100,7 @@
"extra_labels": ["STM", "STM32L4", "STM32L476VG"],
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
"detect_code": ["0820"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES"],
"device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "STDIO_MESSAGES", "TRNG"],
"release_versions": ["2", "5"],
"device_name": "stm32l476vg"
},
Expand Down