@@ -15,7 +15,7 @@ use crate::time::Hertz;
15
15
16
16
#[ derive( Debug ) ]
17
17
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
18
- pub enum ErrorKind {
18
+ pub enum Error {
19
19
///Note: The clock error has no impact on generated random numbers that is the application can still read the RNG_DR register
20
20
ClockError = 0 ,
21
21
SeedError = 1 ,
@@ -33,7 +33,7 @@ fn kernel_clk_unwrap(prec: rec::Rng, clocks: &CoreClocks) -> Hertz {
33
33
clocks. hsi48_ck ( ) . expect ( "RNG: HSI48 must be enabled" )
34
34
}
35
35
RngClkSel :: Pll1Q => {
36
- clocks. pll1_q_ck ( ) . expect ( "RNG: PLL1_Q must be enabled" )
36
+ clocks. pll1 ( ) . q_ck ( ) . expect ( "RNG: PLL1_Q must be enabled" )
37
37
}
38
38
RngClkSel :: Lse => unimplemented ! ( ) ,
39
39
RngClkSel :: Lsi => clocks. lsi_ck ( ) . expect ( "RNG: LSI must be enabled" ) ,
@@ -59,8 +59,10 @@ fn setup_clocks(prec: rec::Rng, clocks: &CoreClocks) -> Hertz {
59
59
feature = "stm32h573" ,
60
60
) ) ]
61
61
62
- /// This uses the register values specified in AN4230 but have not
63
- /// performed the verification (buyer beware, users can/should do their own verification)
62
+ /// Note:
63
+ /// This uses the register values specified in AN4230 but verification
64
+ /// using this HAL has not been performed. Users can/should do their
65
+ /// own verification or request documentation from ST directly.
64
66
/// Requires RNG to be disabled since some register values can only be written when RNGEN = 0
65
67
pub trait RngNist {
66
68
fn rng_nist_st_an4230 ( self , prec : rec:: Rng , clocks : & CoreClocks ) -> Rng ;
@@ -72,8 +74,10 @@ pub trait RngNist {
72
74
feature = "stm32h573"
73
75
) ) ]
74
76
impl RngNist for RNG {
75
- /// This uses the register values specified in AN4230 but have not
76
- /// performed the verification (buyer beware, users can/should do their own verification)
77
+ /// Note:
78
+ /// This uses the register values specified in AN4230 but verification
79
+ /// using this HAL has not been performed. Users can/should do their
80
+ /// own verification or request documentation from ST directly.
77
81
/// Requires RNG to be disabled since some register values can only be written when RNGEN = 0
78
82
fn rng_nist_st_an4230 ( self , prec : rec:: Rng , clocks : & CoreClocks ) -> Rng {
79
83
let rng_clk = setup_clocks ( prec, clocks) ;
@@ -137,7 +141,9 @@ impl RngExt for RNG {
137
141
self . htcr ( ) . write ( |w| unsafe { w. bits ( 0xAAC7 ) } ) ;
138
142
139
143
// Set noise source control register
140
- #[ cfg( not( feature = "stm32h503" ) ) ] // Not available on H503
144
+ // Note:
145
+ // This is currently not available in the PAC or SVD for H503 but is planned to be added
146
+ #[ cfg( not( feature = "stm32h503" ) ) ]
141
147
self . nscr ( ) . write ( |w| unsafe { w. bits ( 0x0003FFFF ) } ) ;
142
148
143
149
// Configuration done, reset CONDRST, its value goes to 0 when the reset process is
@@ -197,8 +203,8 @@ impl RngExt for RNG {
197
203
}
198
204
199
205
pub trait RngCore < W > {
200
- fn gen ( & mut self ) -> Result < W , ErrorKind > ;
201
- fn fill ( & mut self , dest : & mut [ W ] ) -> Result < ( ) , ErrorKind > ;
206
+ fn gen ( & mut self ) -> Result < W , Error > ;
207
+ fn fill ( & mut self , dest : & mut [ W ] ) -> Result < ( ) , Error > ;
202
208
}
203
209
204
210
pub struct Rng {
@@ -207,17 +213,17 @@ pub struct Rng {
207
213
208
214
impl Rng {
209
215
/// Returns 32 bits of randomness, or error
210
- pub fn value ( & mut self ) -> Result < u32 , ErrorKind > {
216
+ pub fn value ( & mut self ) -> Result < u32 , Error > {
211
217
nb:: block!( self . nb_value( ) )
212
218
}
213
219
214
220
/// Returns 32 bits of randomness, or error
215
- pub fn nb_value ( & mut self ) -> nb:: Result < u32 , ErrorKind > {
221
+ pub fn nb_value ( & mut self ) -> nb:: Result < u32 , Error > {
216
222
let status = self . rb . sr ( ) . read ( ) ;
217
223
if status. cecs ( ) . bit ( ) {
218
- Err ( nb:: Error :: Other ( ErrorKind :: ClockError ) )
224
+ Err ( nb:: Error :: Other ( Error :: ClockError ) )
219
225
} else if status. secs ( ) . bit ( ) {
220
- Err ( nb:: Error :: Other ( ErrorKind :: SeedError ) )
226
+ Err ( nb:: Error :: Other ( Error :: SeedError ) )
221
227
} else if status. drdy ( ) . bit ( ) {
222
228
Ok ( self . rb . dr ( ) . read ( ) . rndata ( ) . bits ( ) )
223
229
} else {
@@ -253,13 +259,13 @@ macro_rules! rng_core {
253
259
$(
254
260
impl RngCore <$type> for Rng {
255
261
/// Returns a single element with random value, or error
256
- fn gen ( & mut self ) -> Result <$type, ErrorKind > {
262
+ fn gen ( & mut self ) -> Result <$type, Error > {
257
263
let val = self . value( ) ?;
258
264
Ok ( val as $type)
259
265
}
260
266
261
267
/// Fills buffer with random values, or return error
262
- fn fill( & mut self , buffer: & mut [ $type] ) -> Result <( ) , ErrorKind > {
268
+ fn fill( & mut self , buffer: & mut [ $type] ) -> Result <( ) , Error > {
263
269
const BATCH_SIZE : usize = mem:: size_of:: <u32 >( ) / mem:: size_of:: <$type>( ) ;
264
270
let mut i = 0_usize ;
265
271
while i < buffer. len( ) {
@@ -285,7 +291,7 @@ macro_rules! rng_core_large {
285
291
( $( $type: ty) ,+) => {
286
292
$(
287
293
impl RngCore <$type> for Rng {
288
- fn gen ( & mut self ) -> Result <$type, ErrorKind > {
294
+ fn gen ( & mut self ) -> Result <$type, Error > {
289
295
const WORDS : usize = mem:: size_of:: <$type>( ) / mem:: size_of:: <u32 >( ) ;
290
296
let mut res: $type = 0 ;
291
297
@@ -296,7 +302,7 @@ macro_rules! rng_core_large {
296
302
Ok ( res)
297
303
}
298
304
299
- fn fill( & mut self , dest: & mut [ $type] ) -> Result <( ) , ErrorKind > {
305
+ fn fill( & mut self , dest: & mut [ $type] ) -> Result <( ) , Error > {
300
306
let len = dest. len( ) * ( mem:: size_of:: <$type>( ) / mem:: size_of:: <u32 >( ) ) ;
301
307
let ptr = dest. as_mut_ptr( ) as * mut u32 ;
302
308
let slice_u32 = unsafe { core:: slice:: from_raw_parts_mut( ptr, len) } ;
@@ -311,12 +317,12 @@ macro_rules! rng_core_transmute {
311
317
( $( $type: ty = $from: ty) ,+) => {
312
318
$(
313
319
impl RngCore <$type> for Rng {
314
- fn gen ( & mut self ) -> Result <$type, ErrorKind > {
320
+ fn gen ( & mut self ) -> Result <$type, Error > {
315
321
let num = <Self as RngCore <$from>>:: gen ( self ) ?;
316
322
Ok ( unsafe { mem:: transmute:: <$from, $type>( num) } )
317
323
}
318
324
319
- fn fill( & mut self , dest: & mut [ $type] ) -> Result <( ) , ErrorKind > {
325
+ fn fill( & mut self , dest: & mut [ $type] ) -> Result <( ) , Error > {
320
326
let unsigned_slice = unsafe { mem:: transmute:: <& mut [ $type] , & mut [ $from] >( dest) } ;
321
327
<Self as RngCore <$from>>:: fill( self , unsigned_slice)
322
328
}
0 commit comments