ASCON Suite
ascon-trng-stm32.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef ASCON_TRNG_STM32_H
24 #define ASCON_TRNG_STM32_H
25 
26 #if defined(USE_HAL_DRIVER)
27 
28 /* STM32 platform with the HAL libraries. Try to detect the chip family.
29  * Unfortunately there is no single header or define for "STM32 with an RNG".
30  * Patches welcome to extend this list to new STM32 platforms.
31  *
32  * For each chip family we link to the .h file that contains the
33  * up to date list of #define's for that family. Some of them
34  * don't have an RNG which will be caught later when we check for
35  * the HAL_RNG_MODULE_ENABLED define. It is easier to list
36  * everything and not risk missing one.
37  *
38  * The list of defines for each family will need to be updated periodically. */
39 /* https://github.com/STMicroelectronics/STM32CubeF2/blob/master/Drivers/CMSIS/Device/ST/STM32F2xx/Include/stm32f2xx.h */
40 #if defined(STM32F205xx) || defined(STM32F215xx) || defined(STM32F207xx) || \
41  defined(STM32F217xx)
42 #include "stm32f2xx_hal.h"
43 #define ASCON_TRNG_STM32 hrng
44 /* https://github.com/STMicroelectronics/STM32CubeF4/blob/master/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h */
45 #elif defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || \
46  defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || \
47  defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F401xC) || \
48  defined(STM32F401xE) || defined(STM32F410Tx) || defined(STM32F410Cx) || \
49  defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || \
50  defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Cx) || \
51  defined(STM32F412Zx) || defined(STM32F412Rx) || defined(STM32F412Vx) || \
52  defined(STM32F413xx) || defined(STM32F423xx)
53 #include "stm32f4xx_hal.h"
54 #define ASCON_TRNG_STM32 hrng
55 /* https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Drivers/CMSIS/Device/ST/STM32F7xx/Include/stm32f7xx.h */
56 #elif defined(STM32F722xx) || defined(STM32F723xx) || defined(STM32F732xx) || \
57  defined(STM32F733xx) || defined(STM32F756xx) || defined(STM32F746xx) || \
58  defined(STM32F745xx) || defined(STM32F765xx) || defined(STM32F767xx) || \
59  defined(STM32F769xx) || defined(STM32F777xx) || defined(STM32F779xx) || \
60  defined(STM32F730xx) || defined(STM32F750xx)
61 #include "stm32f7xx_hal.h"
62 #define ASCON_TRNG_STM32 hrng
63 /* https://github.com/STMicroelectronics/STM32CubeG0/blob/master/Drivers/CMSIS/Device/ST/STM32G0xx/Include/stm32g0xx.h */
64 #elif defined(STM32G0B1xx) || defined(STM32G0C1xx) || defined(STM32G0B0xx) || \
65  defined(STM32G071xx) || defined(STM32G081xx) || defined(STM32G070xx) || \
66  defined(STM32G031xx) || defined(STM32G041xx) || defined(STM32G030xx) || \
67  defined(STM32G051xx) || defined(STM32G061xx) || defined(STM32G050xx)
68 #include "stm32g0xx_hal.h"
69 #define ASCON_TRNG_STM32 hrng
70 /* https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Drivers/CMSIS/Device/ST/STM32G4xx/Include/stm32g4xx.h */
71 #elif defined(STM32G431xx) || defined(STM32G441xx) || defined(STM32G471xx) || \
72  defined(STM32G473xx) || defined(STM32G483xx) || defined(STM32G474xx) || \
73  defined(STM32G484xx) || defined(STM32G491xx) || defined(STM32G4A1xx) || \
74  defined(STM32GBK1CB)
75 #include "stm32g4xx_hal.h"
76 #define ASCON_TRNG_STM32 hrng
77 /* https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h */
78 #elif defined(STM32H743xx) || defined(STM32H753xx) || defined(STM32H750xx) || \
79  defined(STM32H742xx) || defined(STM32H745xx) || defined(STM32H745xG) || \
80  defined(STM32H755xx) || defined(STM32H747xx) || defined(STM32H747xG) || \
81  defined(STM32H757xx) || defined(STM32H7B0xx) || defined(STM32H7B0xxQ) || \
82  defined(STM32H7A3xx) || defined(STM32H7B3xx) || defined(STM32H7A3xxQ) || \
83  defined(STM32H7B3xxQ) || defined(STM32H735xx) || defined(STM32H733xx) || \
84  defined(STM32H730xx) || defined(STM32H730xxQ) || defined(STM32H725xx) || \
85  defined(STM32H723xx)
86 #include "stm32h7xx_hal.h"
87 #define ASCON_TRNG_STM32 hrng
88 /* https://github.com/STMicroelectronics/STM32CubeL0/blob/master/Drivers/CMSIS/Device/ST/STM32L0xx/Include/stm32l0xx.h */
89 #elif defined(STM32L010xB) || defined(STM32L010x8) || defined(STM32L010x6) || \
90  defined(STM32L010x4) || defined(STM32L011xx) || defined(STM32L021xx) || \
91  defined(STM32L031xx) || defined(STM32L041xx) || defined(STM32L051xx) || \
92  defined(STM32L052xx) || defined(STM32L053xx) || defined(STM32L062xx) || \
93  defined(STM32L063xx) || defined(STM32L071xx) || defined(STM32L072xx) || \
94  defined(STM32L073xx) || defined(STM32L082xx) || defined(STM32L083xx) || \
95  defined(STM32L081xx)
96 #include "stm32l0xx_hal.h"
97 #define ASCON_TRNG_STM32 hrng
98 /* https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h */
99 #elif defined(STM32L412xx) || defined(STM32L422xx) || defined(STM32L431xx) || \
100  defined(STM32L432xx) || defined(STM32L433xx) || defined(STM32L442xx) || \
101  defined(STM32L443xx) || defined(STM32L451xx) || defined(STM32L452xx) || \
102  defined(STM32L462xx) || defined(STM32L471xx) || defined(STM32L475xx) || \
103  defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || \
104  defined(STM32L496xx) || defined(STM32L4A6xx) || defined(STM32L4P5xx) || \
105  defined(STM32L4Q5xx) || defined(STM32L4R5xx) || defined(STM32L4R7xx) || \
106  defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || \
107  defined(STM32L4S9xx)
108 #include "stm32l4xx_hal.h"
109 #define ASCON_TRNG_STM32 hrng
110 /* https://github.com/STMicroelectronics/STM32CubeL5/blob/master/Drivers/CMSIS/Device/ST/STM32L5xx/Include/stm32l5xx.h */
111 #elif defined(STM32L552xx) || defined(STM32L562xx)
112 #include "stm32l5xx_hal.h"
113 #define ASCON_TRNG_STM32 hrng
114 /* https://github.com/STMicroelectronics/STM32CubeWB/blob/master/Drivers/CMSIS/Device/ST/STM32WBxx/Include/stm32wbxx.h */
115 #elif defined(STM32WB55xx) || defined(STM32WB5Mxx) || defined(STM32WB50xx) || \
116  defined(STM32WB35xx) || defined(STM32WB30xx) || defined(STM32WB15xx) || \
117  defined(STM32WB10xx)
118 #include "stm32wbxx_hal.h"
119 #define ASCON_TRNG_STM32 hrng
120 /* https://github.com/STMicroelectronics/STM32CubeWL/blob/main/Drivers/CMSIS/Device/ST/STM32WLxx/Include/stm32wlxx.h */
121 #elif defined(STM32WL55xx) || defined(STM32WLE5xx) || defined(STM32WL54xx) || \
122  defined(STM32WLE4xx) || defined(STM32WL5Mxx)
123 #include "stm32wlxx_hal.h"
124 #define ASCON_TRNG_STM32 hrng
125 /* https://github.com/STMicroelectronics/STM32CubeU5/blob/main/Drivers/CMSIS/Device/ST/STM32U5xx/Include/stm32u5xx.h */
126 #elif defined(STM32U575xx) || defined(STM32U585xx) || defined(STM32U595xx) || \
127  defined(STM32U599xx) || defined(STM32U5A5xx) || defined(STM32U5A9xx)
128 #include "stm32u5xx_hal.h"
129 #define ASCON_TRNG_STM32 hrng
130 /* https://github.com/STMicroelectronics/STM32CubeMP1/blob/master/Drivers/CMSIS/Device/ST/STM32MP1xx/Include/stm32mp1xx.h */
131 #elif defined(STM32MP15xx) || defined(STM32MP157Axx) || \
132  defined(STM32MP157Cxx) || defined(STM32MP157Dxx) || \
133  defined(STM32MP157Fxx) || defined(STM32MP153Axx) || \
134  defined(STM32MP153Cxx) || defined(STM32MP153Dxx) || \
135  defined(STM32MP153Fxx) || defined(STM32MP151Axx) || \
136  defined(STM32MP151Cxx) || defined(STM32MP151Dxx) || \
137  defined(STM32MP151Fxx)
138 #include "stm32mp1xx_hal.h"
139 #define ASCON_TRNG_STM32 hrng1 /* MP1 series has two RNG's, use the first one */
140 #endif
141 
142 #if defined(HAL_RNG_MODULE_ENABLED)
143 #define ASCON_TRNG_STM32_ENABLED 1
144 #else
145 /* Using HAL libraries on STM32, but the RNG has not been selected
146  * in the configuration. Use STM32Cube to fix this and recompile. */
147 #define ASCON_TRNG_NONE 1
148 #define ASCON_TRNG_MIXER 1
149 #endif
150 
151 #endif /* USE_HAL_DRIVER */
152 
153 #endif