Skip to content

Commit 20fc8af

Browse files
committed
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. Signed-off-by: Ali Hozhabri <[email protected]>
1 parent 8b934dc commit 20fc8af

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
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 {
@@ -160,6 +161,10 @@
160161
};
161162
};
162163

164+
&rng {
165+
status = "okay";
166+
};
167+
163168
&flash0 {
164169
partitions {
165170
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 {
@@ -157,6 +158,10 @@
157158
};
158159
};
159160

161+
&rng {
162+
status = "okay";
163+
};
164+
160165
&flash0 {
161166
partitions {
162167
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 {
@@ -159,6 +160,10 @@
159160
};
160161
};
161162

163+
&rng {
164+
status = "okay";
165+
};
166+
162167
&flash0 {
163168
partitions {
164169
compatible = "fixed-partitions";

drivers/bluetooth/hci/hci_stm32wb0.c

Lines changed: 18 additions & 1 deletion
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"
@@ -301,6 +302,23 @@ static void ble_isr_installer(void)
301302
IRQ_CONNECT(PKA_IRQn, PKA_PRIO, _PKA_IRQHandler, NULL, PKA_FLAGS);
302303
}
303304

305+
/* BLEPLAT_RngGetRandomXX definitions are needed for the BLE library. */
306+
void BLEPLAT_RngGetRandom16(uint16_t* num)
307+
{
308+
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
309+
uint16_t len = 2;
310+
311+
entropy_get_entropy_isr(dev, (uint8_t *)num, len, 0);
312+
}
313+
314+
void BLEPLAT_RngGetRandom32(uint32_t* num)
315+
{
316+
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
317+
uint16_t len = 4;
318+
319+
entropy_get_entropy_isr(dev, (uint8_t *)num, len, 0);
320+
}
321+
304322
static struct net_buf *get_rx(uint8_t *msg)
305323
{
306324
bool discardable = false;
@@ -465,7 +483,6 @@ static int bt_hci_stm32wb0_open(const struct device *dev, bt_hci_recv_t recv)
465483
HAL_RADIO_Init(&hradio);
466484
HAL_RADIO_TIMER_Init(&VTIMER_InitStruct);
467485

468-
HW_RNG_Init();
469486
HW_AES_Init();
470487
hpka.Instance = PKA;
471488
HAL_PKA_Init(&hpka);

0 commit comments

Comments
 (0)