I'm beginner in embedded developent, and I'm using board STM32F417VGx
There are troubles with getting RNG to work
I tried to do it either with wrighting values directly to registers and with CMSIS Peripheral Libraty fuctions.
So, my code:
int main() {
SystemInit(); /* Initialize clocks */
Init_GPIO(); /* Initialize LED's pins */
Init_RNG(); /* Initialize RNG */
RCC_ClocksTypeDef clocks;
RCC_GetClocksFreq(&clocks); /* Check clocks */
/* All clocks are 16 MHz (F42400) */
while(1) {
unsigned rdiode = randomRange(0, 3);
toggleDiode(GPIOD, DIODES[rdiode]);
soft_delay(1000000);
}
}
InitRNG():
void Init_RNG() {
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
RNG_Cmd(ENABLE);
}
randomRange(uint, uint):
uint32_t randomRange(uint32_t low, uint32_t int high){
while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
return RNG_GetRandomNumber() % (high-low) + low;
}
And it hangs on while(RNG_GetFlagStatus(RNG_FLAG_DRDY) == RESET);
CEIS in RNG_SR is 0x1, so there is clocking error.
I'd looked everywhere in google, in every tutorial RNG works out-of-box, nobody even cares about checking SEIS and CEIS flags (?_?)
So I know that RNG needs at least 48MHz clock, but I can't find out what clocking source it uses and how to ajust it's clock :C
In stm32f4xx.h I have those clocking values (was recommended in one tutorial), but HSE is external (not on-board) clocking source, isn't it?
#define HSE_VALUE ((uint32_t)8000000)
Aucun commentaire:
Enregistrer un commentaire