mirror of https://github.com/ARMmbed/mbed-os.git
commit
f9ee683fa7
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* Hardware entropy collector for the STM32F4 family
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
* not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(DEVICE_TRNG)
|
|
||||||
|
|
||||||
#if defined(TARGET_STM32F405xx) || defined(TARGET_STM32F415xx) || defined(TARGET_STM32F407xx) || defined(TARGET_STM32F417xx) ||\
|
|
||||||
defined(TARGET_STM32F427xx) || defined(TARGET_STM32F437xx) || defined(TARGET_STM32F429xx) || defined(TARGET_STM32F439xx) ||\
|
|
||||||
defined(TARGET_STM32F410Tx) || defined(TARGET_STM32F410Cx) || defined(TARGET_STM32F410Rx) || defined(TARGET_STM32F469xx) ||\
|
|
||||||
defined(TARGET_STM32F479xx)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "trng_api.h"
|
|
||||||
|
|
||||||
/** 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 )
|
|
||||||
{
|
|
||||||
*byte = (unsigned char)HAL_RNG_GetRandomNumber(&obj->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void trng_init(trng_t *obj)
|
|
||||||
{
|
|
||||||
/* RNG Peripheral clock enable */
|
|
||||||
__HAL_RCC_RNG_CLK_ENABLE();
|
|
||||||
|
|
||||||
/* Initialize RNG instance */
|
|
||||||
obj->handle.Instance = RNG;
|
|
||||||
HAL_RNG_Init(&obj->handle);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void trng_free(trng_t *obj)
|
|
||||||
{
|
|
||||||
/*Disable the RNG peripheral */
|
|
||||||
HAL_RNG_DeInit(&obj->handle);
|
|
||||||
/* RNG Peripheral clock disable - assume we're the only users of RNG */
|
|
||||||
__HAL_RCC_RNG_CLK_DISABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Get Random byte */
|
|
||||||
for( uint32_t i = 0; i < length; i++ ){
|
|
||||||
trng_get_byte(obj, output + i );
|
|
||||||
}
|
|
||||||
|
|
||||||
*output_length = length;
|
|
||||||
/* Just be extra sure that we didn't do it wrong */
|
|
||||||
if( ( __HAL_RNG_GET_FLAG(&obj->handle, (RNG_FLAG_CECS | RNG_FLAG_SECS)) ) != 0 ) {
|
|
||||||
ret = -1;
|
|
||||||
} else {
|
|
||||||
ret = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return( ret );
|
|
||||||
}
|
|
||||||
#endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\
|
|
||||||
STM32F429xx || STM32F439xx || STM32F410xx || STM32F469xx || STM32F479xx */
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -84,6 +84,10 @@ struct i2c_s {
|
||||||
I2CName i2c;
|
I2CName i2c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct trng_s {
|
||||||
|
RNG_HandleTypeDef handle;
|
||||||
|
};
|
||||||
|
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,10 @@ struct i2c_s {
|
||||||
I2CName i2c;
|
I2CName i2c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct trng_s {
|
||||||
|
RNG_HandleTypeDef handle;
|
||||||
|
};
|
||||||
|
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,10 @@ struct can_s {
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct trng_s {
|
||||||
|
RNG_HandleTypeDef handle;
|
||||||
|
};
|
||||||
|
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,10 @@ struct can_s {
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct trng_s {
|
||||||
|
RNG_HandleTypeDef handle;
|
||||||
|
};
|
||||||
|
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,10 @@ struct can_s {
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct trng_s {
|
||||||
|
RNG_HandleTypeDef handle;
|
||||||
|
};
|
||||||
|
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
#include "gpio_object.h"
|
#include "gpio_object.h"
|
||||||
|
|
||||||
|
|
|
@ -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
|
* Copyright (C) 2006-2016, ARM Limited, All Rights Reserved
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
/** trng_get_byte
|
/** trng_get_byte
|
||||||
* @brief Get one byte of entropy from the RNG, assuming it is up and running.
|
* @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.
|
* @param pointer to the hardware generated random byte.
|
||||||
*/
|
*/
|
||||||
static void trng_get_byte(trng_t *obj, unsigned char *byte )
|
static void trng_get_byte(trng_t *obj, unsigned char *byte )
|
||||||
|
@ -35,6 +36,15 @@ static void trng_get_byte(trng_t *obj, unsigned char *byte )
|
||||||
|
|
||||||
void trng_init(trng_t *obj)
|
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 */
|
/* RNG Peripheral clock enable */
|
||||||
__HAL_RCC_RNG_CLK_ENABLE();
|
__HAL_RCC_RNG_CLK_ENABLE();
|
||||||
|
|
||||||
|
@ -42,6 +52,9 @@ void trng_init(trng_t *obj)
|
||||||
obj->handle.Instance = RNG;
|
obj->handle.Instance = RNG;
|
||||||
HAL_RNG_Init(&obj->handle);
|
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)
|
void trng_free(trng_t *obj)
|
|
@ -915,11 +915,11 @@
|
||||||
"supported_form_factors": ["ARDUINO", "MORPHO"],
|
"supported_form_factors": ["ARDUINO", "MORPHO"],
|
||||||
"core": "Cortex-M0+",
|
"core": "Cortex-M0+",
|
||||||
"default_toolchain": "ARM",
|
"default_toolchain": "ARM",
|
||||||
"extra_labels": ["STM", "STM32L0", "STM32L073RZ"],
|
"extra_labels": ["STM", "STM32L0", "STM32L073RZ", "STM32L073xx"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
"supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
|
||||||
"inherits": ["Target"],
|
"inherits": ["Target"],
|
||||||
"detect_code": ["0760"],
|
"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"],
|
"release_versions": ["2", "5"],
|
||||||
"device_name": "STM32L073RZ"
|
"device_name": "STM32L073RZ"
|
||||||
},
|
},
|
||||||
|
@ -943,7 +943,7 @@
|
||||||
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
||||||
"inherits": ["Target"],
|
"inherits": ["Target"],
|
||||||
"detect_code": ["0770"],
|
"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"],
|
"release_versions": ["2", "5"],
|
||||||
"device_name" : "STM32L432KC"
|
"device_name" : "STM32L432KC"
|
||||||
},
|
},
|
||||||
|
@ -955,7 +955,7 @@
|
||||||
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
||||||
"inherits": ["Target"],
|
"inherits": ["Target"],
|
||||||
"detect_code": ["0765"],
|
"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"],
|
"release_versions": ["2", "5"],
|
||||||
"device_name": "stm32l476rg"
|
"device_name": "stm32l476rg"
|
||||||
},
|
},
|
||||||
|
@ -1100,7 +1100,7 @@
|
||||||
"extra_labels": ["STM", "STM32L4", "STM32L476VG"],
|
"extra_labels": ["STM", "STM32L4", "STM32L476VG"],
|
||||||
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
"supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
|
||||||
"detect_code": ["0820"],
|
"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"],
|
"release_versions": ["2", "5"],
|
||||||
"device_name": "stm32l476vg"
|
"device_name": "stm32l476vg"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue