Skip to content

Commit ecf795f

Browse files
HoZHeldkalowsk
authored andcommitted
drivers: bluetooth: hci: Use TRNG peripheral for BLE purpose on WB0x
Call entropy APIs to use TRNG peripheral on STM32WB0x devices for BLE purposes. Enable RNG node on Nucleo-WB0x boards. Remove RNG initialization as it's done in the entropy driver. Signed-off-by: Ali Hozhabri <[email protected]>
1 parent df70041 commit ecf795f

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

boards/st/nucleo_wb05kz/nucleo_wb05kz.dts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
zephyr,sram = &sram0;
2525
zephyr,flash = &flash0;
2626
zephyr,bt-c2h-uart = &usart1;
27+
zephyr,entropy = &rng;
2728
};
2829

2930
leds: leds {
@@ -167,6 +168,10 @@
167168
};
168169
};
169170

171+
&rng {
172+
status = "okay";
173+
};
174+
170175
&flash0 {
171176
partitions {
172177
compatible = "fixed-partitions";

boards/st/nucleo_wb07cc/nucleo_wb07cc.dts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
zephyr,sram = &sram0;
2525
zephyr,flash = &flash0;
2626
zephyr,bt-c2h-uart = &usart1;
27+
zephyr,entropy = &rng;
2728
};
2829

2930
leds: leds {
@@ -164,6 +165,10 @@
164165
};
165166
};
166167

168+
&rng {
169+
status = "okay";
170+
};
171+
167172
&flash0 {
168173
partitions {
169174
compatible = "fixed-partitions";

boards/st/nucleo_wb09ke/nucleo_wb09ke.dts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
zephyr,sram = &sram0;
2525
zephyr,flash = &flash0;
2626
zephyr,bt-c2h-uart = &usart1;
27+
zephyr,entropy = &rng;
2728
};
2829

2930
leds: leds {
@@ -166,6 +167,10 @@
166167
};
167168
};
168169

170+
&rng {
171+
status = "okay";
172+
};
173+
169174
&flash0 {
170175
partitions {
171176
compatible = "fixed-partitions";

drivers/bluetooth/hci/hci_stm32wb0.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <zephyr/sys/byteorder.h>
1111
#include <zephyr/bluetooth/hci_types.h>
1212
#include <zephyr/drivers/bluetooth.h>
13+
#include <zephyr/drivers/entropy.h>
1314
#include "bleplat_cntr.h"
1415
#include "ble_stack.h"
1516
#include "stm32wb0x_hal_radio_timer.h"
@@ -20,7 +21,6 @@
2021
#include "dm_alloc.h"
2122
#include "aci_adv_nwk.h"
2223
#include "app_common.h"
23-
#include "hw_rng.h"
2424
#include "hw_aes.h"
2525
#include "hw_pka.h"
2626

@@ -301,6 +301,30 @@ static void ble_isr_installer(void)
301301
IRQ_CONNECT(PKA_IRQn, PKA_PRIO, _PKA_IRQHandler, NULL, PKA_FLAGS);
302302
}
303303

304+
static void rng_get_random(void *num, size_t size)
305+
{
306+
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
307+
int res;
308+
309+
/* try to allocate from pool */
310+
res = entropy_get_entropy_isr(dev, (uint8_t *)num, size, !ENTROPY_BUSYWAIT);
311+
if (res != size) {
312+
/* Not enough available random numbers, so it falls back to polling */
313+
entropy_get_entropy_isr(dev, (uint8_t *)num, size, ENTROPY_BUSYWAIT);
314+
}
315+
}
316+
317+
/* BLEPLAT_RngGetRandomXX definitions are needed for the BLE library. */
318+
void BLEPLAT_RngGetRandom16(uint16_t *num)
319+
{
320+
rng_get_random(num, sizeof(*num));
321+
}
322+
323+
void BLEPLAT_RngGetRandom32(uint32_t *num)
324+
{
325+
rng_get_random(num, sizeof(*num));
326+
}
327+
304328
static struct net_buf *get_rx(uint8_t *msg)
305329
{
306330
bool discardable = false;
@@ -465,7 +489,6 @@ static int bt_hci_stm32wb0_open(const struct device *dev, bt_hci_recv_t recv)
465489
HAL_RADIO_Init(&hradio);
466490
HAL_RADIO_TIMER_Init(&VTIMER_InitStruct);
467491

468-
HW_RNG_Init();
469492
HW_AES_Init();
470493
hpka.Instance = PKA;
471494
HAL_PKA_Init(&hpka);

0 commit comments

Comments
 (0)