Микроконтролери и електроника
http://mcu-bg.com/mcu_site/

STM32 питанки
http://mcu-bg.com/mcu_site/viewtopic.php?f=3&t=18081
Страница 1 от 1

Автор:  TheWizard [ Пон Ное 01, 2021 10:05 am ]
Заглавие:  STM32 питанки

STM32 ... мъча да добавя хард RND поддръжка
обаче нещо май съм пропуснал ... дава ми HAL_RNG_Init() таймаут ?!?!

Код:
#include <stdio.h>
#include <stdlib.h>
#include "stm32wlxx_hal_def.h"
#include "stm32wlxx_hal_rng.h"
#include "stm32wlxx_hal_rcc.h"

void rng_init(void)
{
    __HAL_RCC_RNG_CLK_ENABLE();

#if 0
    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_HandleTypeDef h = {0};
    h.Instance = RNG;

    HAL_StatusTypeDef res = HAL_RNG_DeInit(&h);
    res = HAL_RNG_Init(&h); // <--------------- timeout
    if (HAL_OK == res)
    {
        uint32_t r;
        res = HAL_RNG_GenerateRandomNumber(&h, &r); // discard the first result
        if (HAL_OK == res)
        {
            res = HAL_RNG_GenerateRandomNumber(&h, &r);
            if (HAL_OK == res)
            {
                printf("RND: %lu\n", r);
                srand(r);
            }
            else
            {
                printf("[ERROR] HAL_RNG_GenerateRandomNumber(1) %d, %d\n", (int)res, (int)h.ErrorCode);
            }
        }
        else
        {
            printf("[ERROR] HAL_RNG_GenerateRandomNumber(2) %d, %d\n", (int)res, (int)h.ErrorCode);
        }
    }
    else
    {
        printf("[ERROR] HAL_RNG_Init( %d, %d )\n", (int)res, (int)h.ErrorCode); // <--------------- timeout
    }

    HAL_RNG_DeInit(&h);
    __HAL_RCC_RNG_CLK_DISABLE();
}


Автор:  TheWizard [ Пон Ное 01, 2021 11:43 am ]
Заглавие:  Re: STM32 питанки

намерих го
__HAL_RCC_RNG_CONFIG( селект клок );

Страница 1 от 1 Часовете са според зоната UTC + 2 часа [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/