Skip to content

Commit 9587b1d

Browse files
aescolaranangl
authored andcommitted
nrfx: cracen: align to nrf54lm20a
Support the new HW IP version included in the 54LM20 and newer devices Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 8b04943 commit 9587b1d

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

nrfx/drivers/src/nrfx_cracen.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@
4242
#include <soc/nrfx_coredep.h>
4343

4444
/* TRNG HW chosen configuration options */
45+
#if defined(NRF54L15_XXAA) || defined(NRF54L10_XXAA) || defined(NRF54L05_XXAA)
4546
#define TRNG_CLK_DIV 0
47+
#else
48+
#define TRNG_CLK_DIV 1
49+
#endif
4650
#define TRNG_OFF_TIMER_VAL 0
4751
#define TRNG_INIT_WAIT_VAL 512
4852
#define TRNG_NUMBER_128BIT_BLOCKS 4
53+
#if NRF_CRACEN_RNG_HAS_BLENDING
54+
#define TRNG_BLENDING_METHOD NRF_CRACEN_RNG_BLENDINGMETHOD_CONCATENATION
55+
#endif
4956

5057
#define TRNG_CONDITIONING_KEY_SIZE 4 /* Size of the conditioning key: 4 words, 16 bytes */
5158

@@ -89,14 +96,19 @@ static void trng_init(void)
8996
nrf_cracen_rng_control_set(NRF_CRACENCORE, &control_reset);
9097

9198
/* Change from configuration defaults to what we prefer: */
99+
#if NRF_CRACEN_RNG_HAS_IDLETIMER
92100
nrf_cracen_rng_off_timer_set(NRF_CRACENCORE, TRNG_OFF_TIMER_VAL);
101+
#endif
93102
nrf_cracen_rng_clk_div_set(NRF_CRACENCORE, TRNG_CLK_DIV);
94103
nrf_cracen_rng_init_wait_val_set(NRF_CRACENCORE, TRNG_INIT_WAIT_VAL);
95104

96105
/* Configure the control register and enable */
97106
static const nrf_cracen_rng_control_t control_enable = {
98107
.enable = true,
99108
.number_128_blocks = TRNG_NUMBER_128BIT_BLOCKS,
109+
#if NRF_CRACEN_RNG_HAS_BLENDING
110+
.blending_method = TRNG_BLENDING_METHOD,
111+
#endif
100112
};
101113

102114
nrf_cracen_rng_control_set(NRF_CRACENCORE, &control_enable);

nrfx/hal/nrf_cracen_rng.h

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,41 @@ extern "C" {
4848
* Random Generator (RNG) peripheral.
4949
*/
5050

51+
#if defined(CRACENCORE_RNGCONTROL_SWOFFTMRVAL_ResetValue) || defined(__NRFX_DOXYGEN__)
52+
/** @brief Symbol indicating whether the TRNG FSM has an idle timer */
53+
#define NRF_CRACEN_RNG_HAS_IDLETIMER 1
54+
#else
55+
#define NRF_CRACEN_RNG_HAS_IDLETIMER 0
56+
#endif
57+
58+
#if defined(CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_Pos) || defined(__NRFX_DOXYGEN__)
59+
/** @brief Symbol indicating whether the TRNG has entropy blending */
60+
#define NRF_CRACEN_RNG_HAS_BLENDING 1
61+
#else
62+
#define NRF_CRACEN_RNG_HAS_BLENDING 0
63+
#endif
64+
65+
#if NRF_CRACEN_RNG_HAS_BLENDING
66+
/** @brief CRACEN entropy blending methods */
67+
typedef enum
68+
{
69+
NRF_CRACEN_RNG_BLENDINGMETHOD_CONCATENATION = CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_CONCATENATION, /**< Collate all rings oscillators outputs */
70+
NRF_CRACEN_RNG_BLENDINGMETHOD_XORLEVEL1 = CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_XORLEVEL1, /**< XOR bits inside each ring oscillator set */
71+
NRF_CRACEN_RNG_BLENDINGMETHOD_XORLEVEL2 = CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_XORLEVEL2, /**< Also XOR bits in-between ring oscillator sets */
72+
NRF_CRACEN_RNG_BLENDINGMETHOD_VONNEUMANN = CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_VONNEUMANN, /**< VON-NEUMANN debiasing */
73+
} nrf_cracen_rng_blending_methods_t;
74+
#endif
75+
5176
/** @brief CRACEN random generator configuration */
5277
typedef struct
5378
{
54-
bool enable; /**< Enable the RNG peripheral */
55-
bool fifo_full_int_en; /**< Enable FIFO full interrupt */
56-
bool soft_reset; /**< Soft reset the RNG peripheral */
57-
uint8_t number_128_blocks; /**< Number of 128bit blocks used for AES conditioning. Must be at least 1 */
79+
bool enable; /**< Enable the RNG peripheral */
80+
bool fifo_full_int_en; /**< Enable FIFO full interrupt */
81+
bool soft_reset; /**< Soft reset the RNG peripheral */
82+
uint8_t number_128_blocks; /**< Number of 128bit blocks used for AES conditioning. Must be at least 1 */
83+
#if NRF_CRACEN_RNG_HAS_BLENDING
84+
nrf_cracen_rng_blending_methods_t blending_method; /**< Which blending method to use */
85+
#endif
5886
} nrf_cracen_rng_control_t;
5987

6088
/** @brief CRACEN random generator FSM state */
@@ -63,7 +91,9 @@ typedef enum
6391
NRF_CRACEN_RNG_FSM_STATE_RESET = CRACENCORE_RNGCONTROL_STATUS_STATE_RESET, /**< RNG is not started */
6492
NRF_CRACEN_RNG_FSM_STATE_STARTUP = CRACENCORE_RNGCONTROL_STATUS_STATE_STARTUP, /**< RNG is starting */
6593
NRF_CRACEN_RNG_FSM_STATE_IDLE_READY = CRACENCORE_RNGCONTROL_STATUS_STATE_IDLERON, /**< RNG is idle, and ready to produce more data */
94+
#if NRF_CRACEN_RNG_HAS_IDLETIMER
6695
NRF_CRACEN_RNG_FSM_STATE_IDLE_STANDBY = CRACENCORE_RNGCONTROL_STATUS_STATE_IDLEROFF, /**< RNG is idle, with the ring oscillators off */
96+
#endif
6797
NRF_CRACEN_RNG_FSM_STATE_FILL_FIFO = CRACENCORE_RNGCONTROL_STATUS_STATE_FILLFIFO, /**< RNG is filling the FIFO with entropy */
6898
NRF_CRACEN_RNG_FSM_STATE_ERROR = CRACENCORE_RNGCONTROL_STATUS_STATE_ERROR, /**< RNG has halted on an error. Reset is needed */
6999
} nrf_cracen_rng_fsm_state_t;
@@ -119,6 +149,7 @@ nrf_cracen_rng_fsm_state_t nrf_cracen_rng_fsm_state_get(NRF_CRACENCORE_Type cons
119149
NRF_STATIC_INLINE void nrf_cracen_rng_init_wait_val_set(NRF_CRACENCORE_Type * p_reg,
120150
uint16_t value);
121151

152+
#if NRF_CRACEN_RNG_HAS_IDLETIMER
122153
/**
123154
* @brief Function for setting the switch off timer value
124155
*
@@ -127,6 +158,7 @@ NRF_STATIC_INLINE void nrf_cracen_rng_init_wait_val_set(NRF_CRACENCORE_Type * p_
127158
*/
128159
NRF_STATIC_INLINE void nrf_cracen_rng_off_timer_set(NRF_CRACENCORE_Type * p_reg,
129160
uint16_t value);
161+
#endif
130162

131163
/**
132164
* @brief Function for setting the entropy subsampling rate register
@@ -137,7 +169,7 @@ NRF_STATIC_INLINE void nrf_cracen_rng_off_timer_set(NRF_CRACENCORE_Type * p_reg,
137169
* @param[in] value Value to be written in the register.
138170
*/
139171
NRF_STATIC_INLINE void nrf_cracen_rng_clk_div_set(NRF_CRACENCORE_Type * p_reg,
140-
uint8_t value);
172+
uint16_t value);
141173

142174
/**
143175
* @brief Function for getting a word from the entropy FIFO
@@ -163,6 +195,10 @@ NRF_STATIC_INLINE void nrf_cracen_rng_control_set(NRF_CRACENCORE_Type *
163195
& CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk)
164196
| ((p_config->soft_reset << CRACENCORE_RNGCONTROL_CONTROL_SOFTRST_Pos)
165197
& CRACENCORE_RNGCONTROL_CONTROL_SOFTRST_Msk)
198+
#if NRF_CRACEN_RNG_HAS_BLENDING
199+
| ((p_config->blending_method << CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_Pos)
200+
& CRACENCORE_RNGCONTROL_CONTROL_BLENDINGMETHOD_Msk)
201+
#endif
166202
| ((p_config->number_128_blocks << CRACENCORE_RNGCONTROL_CONTROL_NB128BITBLOCKS_Pos)
167203
& CRACENCORE_RNGCONTROL_CONTROL_NB128BITBLOCKS_Msk);
168204
}
@@ -189,19 +225,29 @@ nrf_cracen_rng_fsm_state_t nrf_cracen_rng_fsm_state_get(NRF_CRACENCORE_Type cons
189225
NRF_STATIC_INLINE void nrf_cracen_rng_init_wait_val_set(NRF_CRACENCORE_Type * p_reg,
190226
uint16_t value)
191227
{
228+
#if defined(CRACENCORE_RNGCONTROL_INITWAITVAL_ResetValue)
192229
p_reg->RNGCONTROL.INITWAITVAL = value;
230+
#else
231+
p_reg->RNGCONTROL.WARMUPPERIOD = value;
232+
#endif
193233
}
194234

235+
#if NRF_CRACEN_RNG_HAS_IDLETIMER
195236
NRF_STATIC_INLINE void nrf_cracen_rng_off_timer_set(NRF_CRACENCORE_Type * p_reg,
196237
uint16_t value)
197238
{
198239
p_reg->RNGCONTROL.SWOFFTMRVAL = value;
199240
}
241+
#endif
200242

201243
NRF_STATIC_INLINE void nrf_cracen_rng_clk_div_set(NRF_CRACENCORE_Type * p_reg,
202-
uint8_t value)
244+
uint16_t value)
203245
{
246+
#if defined(CRACENCORE_RNGCONTROL_CLKDIV_ResetValue)
204247
p_reg->RNGCONTROL.CLKDIV = value;
248+
#else
249+
p_reg->RNGCONTROL.SAMPLINGPERIOD = value;
250+
#endif
205251
}
206252

207253
NRF_STATIC_INLINE uint32_t nrf_cracen_rng_fifo_get(NRF_CRACENCORE_Type const * p_reg)

0 commit comments

Comments
 (0)