HAL_ChibiOS: enable RNG only for H7 based boards off for the rest by default

This commit is contained in:
bugobliterator 2021-10-06 12:00:38 +05:30 committed by Andrew Tridgell
parent fc4d59c5a4
commit f298ea406e
5 changed files with 13 additions and 6 deletions

View File

@ -610,7 +610,7 @@ void Util::uart_info(ExpandingString &str)
*/
bool Util::get_random_vals(uint8_t* data, size_t size)
{
#ifdef RNG
#if HAL_USE_HW_RNG && defined(RNG)
size_t true_random_vals = stm32_rand_generate_nonblocking(data, size);
if (true_random_vals == size) {
return true;
@ -638,7 +638,7 @@ bool Util::get_random_vals(uint8_t* data, size_t size)
*/
bool Util::get_true_random_vals(uint8_t* data, size_t size, uint32_t timeout_us)
{
#ifdef RNG
#if HAL_USE_HW_RNG && defined(RNG)
if (stm32_rand_generate_blocking(data, size, timeout_us)) {
return true;
} else {

View File

@ -255,7 +255,7 @@ void __late_init(void) {
/*
* Initialize RNG
*/
#ifdef RNG
#if HAL_USE_HW_RNG && defined(RNG)
rccEnableAHB2(RCC_AHB2ENR_RNGEN, 0);
RNG->CR |= RNG_CR_IE;
RNG->CR |= RNG_CR_RNGEN;

View File

@ -480,7 +480,7 @@ uint32_t stack_free(void *stack_base)
}
#endif
#ifdef RNG
#if HAL_USE_HW_RNG && defined(RNG)
static bool stm32_rand_generate(uint32_t *val)
{
uint32_t error_bits = 0;
@ -548,4 +548,4 @@ unsigned int stm32_rand_generate_nonblocking(unsigned char* output, unsigned int
return i;
}
#endif // #ifdef RNG
#endif // #if HAL_USE_HW_RNG && defined(RNG)

View File

@ -132,7 +132,7 @@ uint32_t stack_free(void *stack_base);
* Generates a block of random values, returns total values generated
* if nonblocking, for blocking returns if successful or not
*/
#ifdef RNG
#if HAL_USE_HW_RNG && defined(RNG)
bool stm32_rand_generate_blocking(unsigned char* output, unsigned int sz, uint32_t timeout_us);
unsigned int stm32_rand_generate_nonblocking(unsigned char* output, unsigned int sz);
#endif

View File

@ -737,6 +737,13 @@ def write_mcu_config(f):
for d in defines.keys():
v = defines[d]
f.write("#ifndef %s\n#define %s %s\n#endif\n" % (d, d, v))
else:
defines = {}
# enable RNG for all H7 chips
if mcu_series.startswith("STM32H7") and 'HAL_USE_HW_RNG' not in defines.keys():
f.write("#define HAL_USE_HW_RNG TRUE\n")
elif 'HAL_USE_HW_RNG' not in defines.keys():
f.write("#define HAL_USE_HW_RNG FALSE\n")
if get_config('PROCESS_STACK', required=False):
env_vars['PROCESS_STACK'] = get_config('PROCESS_STACK')