Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions boards/st/nucleo_wb05kz/nucleo_wb05kz.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,bt-c2h-uart = &usart1;
zephyr,entropy = &rng;
};

leds: leds {
Expand Down Expand Up @@ -167,6 +168,10 @@
};
};

&rng {
status = "okay";
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
5 changes: 5 additions & 0 deletions boards/st/nucleo_wb07cc/nucleo_wb07cc.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,bt-c2h-uart = &usart1;
zephyr,entropy = &rng;
};

leds: leds {
Expand Down Expand Up @@ -164,6 +165,10 @@
};
};

&rng {
status = "okay";
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
5 changes: 5 additions & 0 deletions boards/st/nucleo_wb09ke/nucleo_wb09ke.dts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,bt-c2h-uart = &usart1;
zephyr,entropy = &rng;
};

leds: leds {
Expand Down Expand Up @@ -166,6 +167,10 @@
};
};

&rng {
status = "okay";
};

&flash0 {
partitions {
compatible = "fixed-partitions";
Expand Down
27 changes: 25 additions & 2 deletions drivers/bluetooth/hci/hci_stm32wb0.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <zephyr/sys/byteorder.h>
#include <zephyr/bluetooth/hci_types.h>
#include <zephyr/drivers/bluetooth.h>
#include <zephyr/drivers/entropy.h>
#include "bleplat_cntr.h"
#include "ble_stack.h"
#include "stm32wb0x_hal_radio_timer.h"
Expand All @@ -20,7 +21,6 @@
#include "dm_alloc.h"
#include "aci_adv_nwk.h"
#include "app_common.h"
#include "hw_rng.h"
#include "hw_aes.h"
#include "hw_pka.h"

Expand Down Expand Up @@ -301,6 +301,30 @@ static void ble_isr_installer(void)
IRQ_CONNECT(PKA_IRQn, PKA_PRIO, _PKA_IRQHandler, NULL, PKA_FLAGS);
}

static void rng_get_random(void *num, size_t size)
{
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
int res;

/* try to allocate from pool */
res = entropy_get_entropy_isr(dev, (uint8_t *)num, size, !ENTROPY_BUSYWAIT);
if (res != size) {
/* Not enough available random numbers, so it falls back to polling */
entropy_get_entropy_isr(dev, (uint8_t *)num, size, ENTROPY_BUSYWAIT);
}
}

/* BLEPLAT_RngGetRandomXX definitions are needed for the BLE library. */
void BLEPLAT_RngGetRandom16(uint16_t *num)
{
rng_get_random(num, sizeof(*num));
}

void BLEPLAT_RngGetRandom32(uint32_t *num)
{
rng_get_random(num, sizeof(*num));
}

static struct net_buf *get_rx(uint8_t *msg)
{
bool discardable = false;
Expand Down Expand Up @@ -465,7 +489,6 @@ static int bt_hci_stm32wb0_open(const struct device *dev, bt_hci_recv_t recv)
HAL_RADIO_Init(&hradio);
HAL_RADIO_TIMER_Init(&VTIMER_InitStruct);

HW_RNG_Init();
HW_AES_Init();
hpka.Instance = PKA;
HAL_PKA_Init(&hpka);
Expand Down