66#![ no_std]
77#![ no_main]
88
9+ use components:: hmac_component_static;
910use kernel:: capabilities;
1011use kernel:: component:: Component ;
1112use kernel:: debug:: PanicResources ;
@@ -52,6 +53,11 @@ struct NucleoU545RE {
5253 stm32u545:: tim:: Tim2 < ' static > ,
5354 > ,
5455 > ,
56+ hmac : & ' static capsules_extra:: hmac:: HmacDriver <
57+ ' static ,
58+ stm32u545:: hash:: sha256:: Sha256Adapter < ' static > ,
59+ 32 ,
60+ > ,
5561}
5662
5763impl SyscallDriverLookup for NucleoU545RE {
@@ -64,6 +70,7 @@ impl SyscallDriverLookup for NucleoU545RE {
6470 capsules_core:: led:: DRIVER_NUM => f ( Some ( self . led ) ) ,
6571 capsules_core:: button:: DRIVER_NUM => f ( Some ( self . button ) ) ,
6672 capsules_core:: alarm:: DRIVER_NUM => f ( Some ( self . alarm ) ) ,
73+ capsules_extra:: hmac:: DRIVER_NUM => f ( Some ( self . hmac ) ) ,
6774 _ => f ( None ) ,
6875 }
6976 }
@@ -152,10 +159,17 @@ unsafe fn start() -> (
152159 ) ;
153160 usart1. register ( ) ;
154161
162+ let hash = static_init ! (
163+ stm32u545:: hash:: hash:: Hash <' static >,
164+ stm32u545:: hash:: hash:: Hash :: new( stm32u545:: hash:: regs:: HASH_BASE )
165+ ) ;
166+
167+ hash. register ( ) ;
168+
155169 // Load Peripherals Bundle
156170 let periphs = static_init ! (
157171 stm32u545:: chip:: Stm32u5xxDefaultPeripherals <' static >,
158- stm32u545:: chip:: Stm32u5xxDefaultPeripherals :: new( usart1, exti, dma1)
172+ stm32u545:: chip:: Stm32u5xxDefaultPeripherals :: new( usart1, exti, dma1, hash )
159173 ) ;
160174
161175 // Initialize wiring (DMA, clocks)
@@ -165,6 +179,16 @@ unsafe fn start() -> (
165179 periphs. tim2 . start ( ) ;
166180 set_pin_primary_functions ( periphs) ;
167181
182+ // Create an adapter for the HASH peripheral.
183+ // In this way it is ensured that only one mode is used by the peripheral.
184+ let sha256 = static_init ! (
185+ stm32u545:: hash:: sha256:: Sha256Adapter <' static >,
186+ stm32u545:: hash:: sha256:: Sha256Adapter :: new( hash)
187+ ) ;
188+
189+ // Adapter receives callbacks from the peripheral
190+ let _ = hash. set_sha256_adapter ( sha256) ;
191+
168192 // Kernel and Muxes
169193 let processes = components:: process_array:: ProcessArrayComponent :: new ( )
170194 . finalize ( components:: process_array_component_static!( NUM_PROCS ) ) ;
@@ -233,6 +257,16 @@ unsafe fn start() -> (
233257 )
234258 . finalize ( components:: button_component_static!( stm32u545:: gpio:: Pin ) ) ;
235259
260+ let hmac = components:: hmac:: HmacComponent :: new (
261+ board_kernel,
262+ capsules_extra:: hmac:: DRIVER_NUM ,
263+ sha256,
264+ )
265+ . finalize ( hmac_component_static ! (
266+ stm32u545:: hash:: sha256:: Sha256Adapter <' static >,
267+ 32
268+ ) ) ;
269+
236270 // Platform and Interrupts
237271 let platform = static_init ! (
238272 NucleoU545RE ,
@@ -244,6 +278,7 @@ unsafe fn start() -> (
244278 led,
245279 button,
246280 alarm,
281+ hmac
247282 }
248283 ) ;
249284
0 commit comments