HAL RNG Use Cases

User application starting a driver

@startuml
hide footbox
' To add a number by line
'autonumber

' Fix order of each column
skinparam ParticipantPadding 40

participant "User Application" as part1
participant "Driver RNG" as part2
participant "System" as part3

activate part1

group #9898fb Initializes the Flash interface and the Systick
part1->part3 : HAL_Init()
activate part3
part3 --> part1
deactivate part3
end

group #lightsalmon Configure the system clock
part1->part3 : SystemClock_Config()
activate part3
part3 --> part1
deactivate part3
end

group #lightblue Initialize RNG peripheral
part1->part2 ++ : HAL_RNG_Init()
note right: One instance available : \n- HAL_RNG \n enabled when USE_RNG_CLK_ENABLE_MODEL \n is set to HAL_CLK_ENABLE_PERIPH_ONLY

part2 --> part1

part1->part2 : - RNG HW Initialization\n- NVIC configuration for RNG interrupts
part2 --> part1
end

@enduml

Called functions:

User application generate random numbers with GermanBSI candidate configuration in polling mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group  #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetCandidateGermanBSIConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in polling mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
note right : N x 32-bit random numbers generated
deactivate "HAL RNG Driver"
end

@enduml

Called functions:

User application generate random numbers with GermanBSI candidate configuration in interrupt mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetCandidateGermanBSIConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in interrupt mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber_IT()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
"IRQHandler" <-: Interrupt
"IRQHandler"->"HAL RNG Driver": HAL_RNG_IRQHandler()
"HAL RNG Driver" --> "User Application" : HAL_RNG_GenerationCpltCallback()
note left: N x 32-bit random numbers
end

@enduml

Called functions:

User application generate random numbers with customized configuration in polling mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in polling mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
note right: N x 32-bit random numbers
deactivate "HAL RNG Driver"
end

@enduml

Called functions:

User application generate random numbers with customized configuration in interrupt mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in interrupt mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber_IT()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
"IRQHandler" <-: Interrupt
"IRQHandler"->"HAL RNG Driver": HAL_RNG_IRQHandler()
"HAL RNG Driver" --> "User Application" : HAL_RNG_GenerationCpltCallback()
note right : 32-bit random number
end

@enduml

Called functions:

User application recover a seed error when occured in polling mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" :  HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in polling mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_ERROR (Seed error occured)
deactivate "HAL RNG Driver"
end

group #red Recover the seed error
"User Application"->"HAL RNG Driver" : HAL_RNG_RecoverSeedError()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen restart random number generations
"User Application"->"HAL RNG Driver" :  HAL_RNG_GenerateRandomNumber()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
note right : N x 32-bit random numbers
deactivate "HAL RNG Driver"
end

@enduml

Called functions:

User application recover a seed error when occured in interrupt mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group  #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetCertifiedNISTConfig() or \nHAL_RNG_SetCandidateNISTConfig() or \nHAL_RNG_SetCandidateGermanBSIConfig() or \nHAL_RNG_SetConfig()
activate "HAL RNG Driver"

"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightblue RNG additional health tests (optional) Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetHealthFactorConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" :  HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in polling mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
note right : N x 32-bit random numbers generated
deactivate "HAL RNG Driver"
end

@enduml

Called functions:

User application setting additional health tests in polling mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group  #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetCertifiedNISTConfig() or \nHAL_RNG_SetCandidateNISTConfig() or \nHAL_RNG_SetCandidateGermanBSIConfig() or \nHAL_RNG_SetConfig()
activate "HAL RNG Driver"

"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightblue RNG additional health tests (optional) Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetHealthFactorConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" :  HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in interrupt mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber_IT()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
"IRQHandler" <-: Interrupt
"IRQHandler"->"HAL RNG Driver": HAL_RNG_IRQHandler()
"HAL RNG Driver" --> "User Application" : HAL_RNG_GenerationCpltCallback()
note right : 32-bit random number
end

@enduml

Called functions:

User application setting additional health tests in interrupt mode

@startuml
group #lightblue RNG Initialization
"User Application"->"HAL RNG Driver" : HAL_RNG_Init()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #tomato RNG Configuration
"User Application"->"HAL RNG Driver" : HAL_RNG_SetConfig()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Random number generation in interrupt mode
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber_IT()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
"IRQHandler" <-: Interrupt
"IRQHandler"->"HAL RNG Driver": HAL_RNG_IRQHandler()
note left : HAL_ERROR: seed error detected
end

group #red Seed error recovery
"HAL RNG Driver" --> "User Application" : HAL_RNG_ErrorCallback()
"User Application"->"HAL RNG Driver" : HAL_RNG_RecoverSeedError()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
end

group #lightgreen Start a new process
"User Application"->"HAL RNG Driver" : HAL_RNG_GenerateRandomNumber_IT()
activate "HAL RNG Driver"
"HAL RNG Driver"-->"User Application" : HAL_OK
deactivate "HAL RNG Driver"
"IRQHandler" <-: Interrupt
"IRQHandler"-> "HAL RNG Driver" : HAL_RNG_IRQHandler()
note left : HAL_OK: N x 32-bit random numbers generated
"HAL RNG Driver" --> "User Application" : HAL_RNG_GenerationCpltCallback()
end

@enduml

Called functions: