Skip to content

Commit ff29b04

Browse files
csanchezdllxiaoxiang781216
authored andcommitted
arch/arm/src/stm32h5: add support for HW RNG.
Driver copied from stm32f7, which includes CEIS/SEIS clearing per reference manual. Signed-off-by: Carlos Sanchez <carlossanchez@geotab.com>
1 parent 2554d21 commit ff29b04

7 files changed

Lines changed: 431 additions & 2 deletions

File tree

arch/arm/src/stm32h5/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ if(CONFIG_STM32H5_FDCAN_CHARDRIVER)
6868
list(APPEND SRCS stm32_fdcan.c)
6969
endif()
7070

71+
if(CONFIG_STM32H5_RNG)
72+
list(APPEND SRCS stm32_rng.c)
73+
endif()
74+
7175
if(CONFIG_STM32H5_ICACHE)
7276
list(APPEND SRCS stm32_icache.c)
7377
endif()

arch/arm/src/stm32h5/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ config STM32H5_ADC2
356356
default n
357357
select STM32H5_ADC
358358

359+
config STM32H5_RNG
360+
bool "RNG"
361+
default n
362+
select ARCH_HAVE_RNG
363+
359364
config STM32H5_DMA1
360365
bool "DMA1"
361366
default n

arch/arm/src/stm32h5/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ ifeq ($(CONFIG_STM32H5_FDCAN_CHARDRIVER),y)
6464
CHIP_CSRCS += stm32_fdcan.c
6565
endif
6666

67+
ifeq ($(CONFIG_STM32H5_RNG),y)
68+
CHIP_CSRCS += stm32_rng.c
69+
endif
70+
6771
ifeq ($(CONFIG_STM32H5_ICACHE),y)
6872
CHIP_CSRCS += stm32_icache.c
6973
endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/****************************************************************************
2+
* arch/arm/src/stm32h5/hardware/stm32_rng.h
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Licensed to the Apache Software Foundation (ASF) under one or more
7+
* contributor license agreements. See the NOTICE file distributed with
8+
* this work for additional information regarding copyright ownership. The
9+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance with the
11+
* License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
* License for the specific language governing permissions and limitations
19+
* under the License.
20+
*
21+
****************************************************************************/
22+
23+
#ifndef __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_RNG_H
24+
#define __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_RNG_H
25+
26+
/****************************************************************************
27+
* Included Files
28+
****************************************************************************/
29+
30+
#include <nuttx/config.h>
31+
#include "chip.h"
32+
33+
/****************************************************************************
34+
* Pre-processor Definitions
35+
****************************************************************************/
36+
37+
/* Register Offsets *********************************************************/
38+
39+
#define STM32_RNG_CR_OFFSET 0x0000 /* RNG Control Register */
40+
#define STM32_RNG_SR_OFFSET 0x0004 /* RNG Status Register */
41+
#define STM32_RNG_DR_OFFSET 0x0008 /* RNG Data Register */
42+
43+
/* Register Addresses *******************************************************/
44+
45+
#define STM32_RNG_CR (STM32_RNG_BASE+STM32_RNG_CR_OFFSET)
46+
#define STM32_RNG_SR (STM32_RNG_BASE+STM32_RNG_SR_OFFSET)
47+
#define STM32_RNG_DR (STM32_RNG_BASE+STM32_RNG_DR_OFFSET)
48+
49+
/* Register Bitfield Definitions ********************************************/
50+
51+
/* RNG Control Register */
52+
53+
#define RNG_CR_RNGEN (1 << 2) /* Bit 2: RNG enable */
54+
#define RNG_CR_IE (1 << 3) /* Bit 3: Interrupt enable */
55+
56+
/* RNG Status Register */
57+
58+
#define RNG_SR_DRDY (1 << 0) /* Bit 0: Data ready */
59+
#define RNG_SR_CECS (1 << 1) /* Bit 1: Clock error current status */
60+
#define RNG_SR_SECS (1 << 2) /* Bit 2: Seed error current status */
61+
#define RNG_SR_CEIS (1 << 5) /* Bit 5: Clock error interrupt status */
62+
#define RNG_SR_SEIS (1 << 6) /* Bit 6: Seed error interrupt status */
63+
64+
#endif /* __ARCH_ARM_SRC_STM32H5_HARDWARE_STM32_RNG_H */

0 commit comments

Comments
 (0)