Skip to content

Conversation

@HoZHel
Copy link
Contributor

@HoZHel HoZHel commented Oct 23, 2025

  • Fix the TRNG driver issue regarding non-stop ISR firing for STM32WB09.

  • Clear RNG_IRQ_SR_ERROR_IRQ and RNG_IRQ_SR_FF_FULL_IRQ flags when they are set.

  • Change the number of attempts to empty the RNG FIFO according to the FIFO size.

  • Fix the issue regarding passing the TRNG peripheral instance to the BLE driver.

  • Increase the SYSTEM_WORKQUEUE_STACK_SIZE when CONFIG_BT is set.

Here is the screenshot of beacon sample to show the reason for increasing SYSTEM_WORKQUEUE_STACK_SIZE. Previously, the default was 1024 bytes.

image

Fix the TRNG driver issue regarding non-stop ISR firing for STM32WB09.

Clear RNG_IRQ_SR_ERROR_IRQ and RNG_IRQ_SR_FF_FULL_IRQ flags
when they are set.

Change the number of attempts to empty the RNG FIFO according to its size.

Signed-off-by: Ali Hozhabri <[email protected]>
…ance

Fix the issue regarding passing the TRNG peripheral instance to the driver.

Increase the SYSTEM_WORKQUEUE_STACK_SIZE when CONFIG_BT is set.

Signed-off-by: Ali Hozhabri <[email protected]>
@sonarqubecloud
Copy link

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how "drivers: entropy: Fix non-stop RNG ISR firing for STM32WB09" fixes your issue. I must miss something if it really changes the driver behavior.

For commit "drivers: bluetooth: hci: Fix the issue about the TRNG peripheral instance": could you describe a bit more why CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE is increased: how does it help? I also this the commit message header line and body is not very explicit about which TRNG issue is being addressed.

*/
WRITE_REG(RNG->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ);
if (LL_RNG_GetFfFullIrq(RNGx)) {
SET_BIT(RNGx->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using SET_BIT(), you may clear also a pending ERROR flag. I think WRITE_REG() was the way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1: WRITE_REG is the correct operation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you're saying is the opposite. As the name suggests, SET_BIT() is for setting one bit of the register, while WRITE_REG() manipulates the whole register. Here you can find these two macros as follows:

#define SET_BIT(REG, BIT) ((REG) |= (BIT))
#define WRITE_REG(REG, VAL) ((REG) = (VAL))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what the macros do. SET_BIT() is not correct here because it does a read then write, and the flags are cleared by writing 1 to their bit:
image

If ERROR_IRQ was 1, SET_BIT(IRQ_SR, FF_FULL_IRQ) will read the register (= ERROR_IRQ), then |= FF_FULL_IRQ to the read value and write back the result (= ERROR_IRQ | FF_FULL_IRQ) which will clear both interrupt flags.

Using WRITE_REG (or really, just RNG->IRQ_SR = RNG_IRQ_SR_FF_FULL_IRQ) will write a value with only bit FF_FULL_IRQ set which ensures that only this specific interrupt flag is cleared.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I understand, thanks for the clarification.


#if defined(CONFIG_SOC_STM32WB09XX)
if (LL_RNG_GetErrorIrq(rng)) {
SET_BIT(rng->IRQ_SR, RNG_IRQ_SR_ERROR_IRQ);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag should have already been cleared by ll_rng_clear_sei() above.
Using SET_BIT() here may also clear the FF_FULL flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ll_rng_clear_seis() doesn't clear IRQ_SR_ERROR 🤔

Copy link
Contributor Author

@HoZHel HoZHel Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etienne-lms , ll_rng_clear_seis() clears RNG_CR_RST_HEALTH_FLAGS flag.
For your second sentence, please refer to the previous comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. Indeed it is an error, we should clear that bit.
Could you rather fix ll_rng_clear_sei() adding their clear of IRQ_SR_ERROR?

I think we need to revisit a bit WB09xx sequences in this driver.

#if IRQLESS_TRNG
#define MAX_AVAIL_RND_NUM 1
#else
#define MAX_AVAIL_RND_NUM 4 /* Internal four-word FIFO */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an error is triggered only 3 samples are to be removed from the 4-word FIFO.
If there is no FIFO, there is nothing to evacuate since upon error RNG produces no random sample.

That said, the change shows something that was not update by commit d65f8e3: indeed value 12 should have been updated to 3 at that time and no-FIFO instance addressed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't really matter, reading empty FIFO will just return 0.

Copy link
Contributor

@mathieuchopstm mathieuchopstm Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And FWIW other IPs do also have a FIFO but no corresponding "FIFO full" interrupt so I'm not sure that lowering this value is "correct"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think lowering the value will fix anything. Just a matter of consistency.

}

#if defined(CONFIG_SOC_STM32WB09XX)
if (LL_RNG_GetErrorIrq(rng)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on Etienne's comment: unless there's a reason for it, let's not bother checking for the flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean clearing a flag without checking if it is raised?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Per RefMan, this should have no effect

*/
WRITE_REG(RNG->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ);
if (LL_RNG_GetFfFullIrq(RNGx)) {
SET_BIT(RNGx->IRQ_SR, RNG_IRQ_SR_FF_FULL_IRQ);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1: WRITE_REG is the correct operation

ll_rng_clear_seis(rng);

for (int i = 0; i < 12; ++i) {
for (int i = 0; i < MAX_AVAIL_RND_NUM; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be replaced with:

Suggested change
for (int i = 0; i < MAX_AVAIL_RND_NUM; ++i) {
while (ll_rng_is_active_drdy(rng)) {

to be more solid

Comment on lines +23 to +24
config SYSTEM_WORKQUEUE_STACK_SIZE
default 1152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config SYSTEM_WORKQUEUE_STACK_SIZE
default 1152
configdefault SYSTEM_WORKQUEUE_STACK_SIZE
default 1152

@HoZHel
Copy link
Contributor Author

HoZHel commented Oct 24, 2025

I don't understand how "drivers: entropy: Fix non-stop RNG ISR firing for STM32WB09" fixes your issue. I must miss something if it really changes the driver behavior.

Clearing the interrupt flags prevents continuous interrupt firing.

For commit "drivers: bluetooth: hci: Fix the issue about the TRNG peripheral instance": could you describe a bit more why CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE is increased: how does it help? I also this the commit message header line and body is not very explicit about which TRNG issue is being addressed.

In this commit, the correct node identifier of RNG is passed to the variable. Previously, it was DT_DRV_INST(0) which referred to the bt_hci_wb0 node due to the presence of #define DT_DRV_COMPAT st_hci_stm32wb0.
For the increase of CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, I attached a screenshot which shows that 1024 is not enough anymore.

@etienne-lms
Copy link
Contributor

I don't understand how "drivers: entropy: Fix non-stop RNG ISR firing for STM32WB09" fixes your issue. I must miss something if it really changes the driver behavior.

Clearing the interrupt flags prevents continuous interrupt firing.

Ok, I understand now that you pointed me ll_rng_clear_seis() didn't do the expected job.

In this commit, the correct node identifier of RNG is passed to the variable. Previously, it was DT_DRV_INST(0) which referred to the bt_hci_wb0 node due to the presence of #define DT_DRV_COMPAT st_hci_stm32wb0.

Ok. Right, you mention that in the commit message body.

For the increase of CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, I attached a screenshot which shows that 1024 is not enough anymore.

Could you mention that in the commit message? Like Experimentation show that 1048 bytes of stack where used when BT is enabled hence increase CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE to a safer value..


#if defined(CONFIG_SOC_STM32WB09XX)
if (LL_RNG_GetErrorIrq(rng)) {
SET_BIT(rng->IRQ_SR, RNG_IRQ_SR_ERROR_IRQ);
Copy link
Member

@erwango erwango Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use new bits handling functions: #97329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants