# 1.0.12 Noise bug

**URL:** <https://ksoloti.discourse.group/t/1-0-12-noise-bug/322>\
**Category:** Software\
**Tags:** core, firmware, bug, noise, axo\
**Created:** [April 25, 2025, 11:32am UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322 "2025-04-25T11:32:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blindsmyth](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Blindsmyth](https://ksoloti.discourse.group/u/Blindsmyth)\
**Post date:** [April 25, 2025, 11:32am UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/1 "2025-04-25T11:32:42Z")

</div>

It seems to be more stable in that case. To be fair I had 2 ksoloti patchers and 1 axoloti patcher open. Maxing out on the boards here 🙂 it is also not proven that these crashes were Ksoloti related, it was usually though when I would compile all of them in a row.

EDIT: Just found sth weird, the white noise (noise/uniform) sounds completely different (and kinda terrible) than on an original axoloti. Here are the 2 in comparison.

> **[Dropbox](https://www.dropbox.com/scl/fo/v5vizkd1v0aajzib0wk04/AOcoWF3SU1C8raGAsLgYgj0?rlkey=fy341y7bttq05xv36cue22p7x&dl=0)**

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 6, 2025, 11:15am UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/2 "2025-05-06T11:15:26Z")

</div>

Are you still getting this with the white noise (uniform)?

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 6, 2025, 12:42pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/3 "2025-05-06T12:42:47Z")

</div>

Did you try knoise? (The k is anything but silent)

Always great when people report things that don’t work as they should - it looks like I may have introduced a wee inconsistency when I rewrote part of the random number generator part?

Actually the two ways should do the same, but maybe they just don’t.

Haven’t had a listen yet but it might just take the noise back to where it was.

 ![2025-05-06 21_20_11-Code search results — Mozilla Firefox](https://global.discourse-cdn.com/free1/uploads/ksoloti1/original/1X/c557cc8bb935770fa0c598756ca015d4d6506796.png)

Edit: Waaait… they don’t really do the exact same thing.

The SMMUL instruction multiplies **scaled** values, doesn’t it. So multiplying, say,  
`0xFFFFFFFF * 0xFFFFFFFF = 0xFFFFFFFF` (1 \* 1 = 1)  
whereas  
`0x80000000 * 0x80000000 = 0x40000000` ? (0.5 \* 0.5 = 0.25)

whereas `randSeed * 196314165` will lead to intentional overflow.

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 6, 2025, 3:51pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/4 "2025-05-06T15:51:23Z")

</div>

Something very wrong with that noise… I don’t remember it being like this. Axoloti Core & Ksoloti Core

 ![2025-05-06 23_50_18-_untitled](https://global.discourse-cdn.com/free1/uploads/ksoloti1/original/1X/2a845557c4959ad367fbb82843a9049eae2cc4fe.png)

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 6, 2025, 4:33pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/5 "2025-05-06T16:33:28Z")

</div>

Found the bug: missing “static”

 ![2025-05-07 00_29_14-_untitled](https://global.discourse-cdn.com/free1/uploads/ksoloti1/original/1X/bab8681aa0701b35b45ccaf95fb29f28bc3355e0.png)

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 7, 2025, 12:41pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/6 "2025-05-07T12:41:11Z")

</div>

Where’s the bug?

The uniform noise on my gills/h7 sounds fine to me!

Am I using an old object maybe?

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 7, 2025, 1:35pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/7 "2025-05-07T13:35:29Z")

</div>

Could be the H7 has a faster (T)RNG? I bet it has lots more config bits than the F4 too.

What messed up the STM32F4 noise is declaring and initializing `int32_t randSeed = 22222;` every time the function was called. This lead to a sort of easily repeating/slowly changing pattern.

After changing it back to `static int32_t randseed = 22222;` (the static somehow got lost on the way): apparently declaring a variable static inside a function is a special case where it actually only gets initialised once then it would squat inside the function and the value is preserved between calls.

The noise/uniform object hasn’t changed for a decade: it really just calls `GenerateRandomNumber()` at s-rate, which is more or less deprecated for `rand_s32()`

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 7, 2025, 2:43pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/8 "2025-05-07T14:43:49Z")

</div>

I’m still a bit confused 🙂

I checked the `RNG->DR` is fast enough on the H7.

That `___SMMLA` is not updating `randseed`, shouldn’t it read:

```auto
 static uint32_t randSeed = 22222;
 return randSeed = ___SMMLA(randSeed, 196314165, RNG->DR);

```

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 7, 2025, 3:10pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/9 "2025-05-07T15:10:35Z")

</div>

Maybe? Sounds about right - those intrinsics are easy to misunderstand for me, as many operate on registers directly without “returning” anything.

I’ve given up on \_\_\_SMMLA here due to its “scaled” operation - randSeed SMMLA’d with 196314165 will technically always get smaller (though we’re adding RNG-\>DR to it so maybe fine)

Just reverted it to plain old

```cpp
    static uint32_t randSeed = 22229; /* Static declaration inside function -> will retain its last value between calls */
    return randSeed = (randSeed * 196314163) + RNG->DR;

```

And the numbers are now prime numbers - chef’s kiss

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 8, 2025, 3:01am UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/10 "2025-05-08T03:01:12Z")

</div>

How fast is fast enough? On the F4 the speed for new random numbers to be ready is (as far as I understand it) `(RNG clock = PLL48 = USB clock) / (40 RNG clock cycles)` - which means  
`48 MHz / 40 = 1.2 MHz`  
I would think this is an acceptable speed as the RNG is mostly ever called at s-rate? Maybe it wasn’t fast enough for true randomness, or a good-sounding one, so they added this pseudo-randomize multiply?

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 8, 2025, 11:36am UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/11 "2025-05-08T11:36:55Z")

</div>

in the F4 using a rand\_s32() that only uses RNG-\>DR:

```auto
    volatile int32_t vals[32];
    for(int i=0 ;i < 32; i++)
        vals[i] = rand_s32();

```

I see repeated values , 7 or 8 times in a row.

On the H7 you don’t get repeats, but… You get a lot of zeros! So something needs looking at there!

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 8, 2025, 12:32pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/12 "2025-05-08T12:32:05Z")

</div>

> [@AndyCap](#):
>
> ```auto
> volatile int32_t vals[32];
> for(int i=0 ;i < 32; i++)
> vals[i] = rand_s32();
> 
> ```

The loop is too fast… the RNG value has no time to refresh.

After which clock is the H7 RNG set up to run?

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 8, 2025, 1:24pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/13 "2025-05-08T13:24:19Z")

</div>

Yep, was just trying to show the speed of the RNG was not fast enough 🙂

The H7 is the same 48 clock, not sure what is going on there. Need to look down into chibios to see what is going on. You seem to get 8 random readings, then a load of 0’s. Maybe it does batches of 8 then you have to wait or maybe it is entering an error condition and then clearing…

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 8, 2025, 1:53pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/14 "2025-05-08T13:53:29Z")

</div>

A lot of trickery going on inside the H7 RNG, a FIFO, clocking via two separate clocks, clock error detection… enjoy

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 8, 2025, 2:31pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/15 "2025-05-08T14:31:11Z")

</div>

I can’t even find where it is set up in the code, not a good start!

We do have this 🙂

```auto
#define STM32_RNGSEL STM32_RNGSEL_HSI48_CK

```

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 8, 2025, 3:27pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/16 "2025-05-08T15:27:25Z")

</div>

It does seem to generate them in batches of 8, then RNG-\>DR becomes 0 and you have to wait for the next batch.

HAL Code for the wait:

```auto
 /* Check if data register contains valid random data */
    while (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
    {
      if ((HAL_GetTick() - tickstart) > RNG_TIMEOUT_VALUE)
      {
        /* New check to avoid false timeout detection in case of preemption */
        if (__HAL_RNG_GET_FLAG(hrng, RNG_FLAG_DRDY) == RESET)
        {
          hrng->State = HAL_RNG_STATE_READY;
          hrng->ErrorCode = HAL_RNG_ERROR_TIMEOUT;
          /* Process Unlocked */
          __HAL_UNLOCK(hrng);
          return HAL_ERROR;
        }
      }
    }

```

Edit: Actually it seems to generate them in batches of 4, with storage for 8.

---

<div class="post-metadata">

**Author:** ![Ksoloti](https://yyz2.discourse-cdn.com/free1/user_avatar/ksoloti.discourse.group/ksoloti/32/71_2.png) [@Ksoloti](https://ksoloti.discourse.group/u/Ksoloti)\
**Post date:** [May 8, 2025, 3:49pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/17 "2025-05-08T15:49:41Z")

</div>

Do you need the HAL for that on H7?

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 8, 2025, 6:08pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/18 "2025-05-08T18:08:30Z")

</div>

No, I will whip out the code to check that flag, or maybe it isn’t necessary really. `return randSeed = (randSeed * 196314163) + RNG->DR;` is going to give a different value each time `RNG->DR` is 0, maybe not “random” but will be different, just like it is at the moment with RNG-\>DR staying the same?

---

<div class="post-metadata">

**Author:** ![Blindsmyth](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@Blindsmyth](https://ksoloti.discourse.group/u/Blindsmyth)\
**Post date:** [May 9, 2025, 1:58pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/19 "2025-05-09T13:58:08Z")

</div>

Wow seems, like I really started sth here 😅

> [@AndyCap](#):
>
> Are you still getting this with the white noise (uniform)?

yes this is the white nosie uniform.

> [@Patcher 1.1.0 Released (\*Edit: back to beta for now!\*)](https://ksoloti.discourse.group/t/patcher-1-1-0-released-edit-back-to-beta-for-now/271/33):
>
> Did you try knoise? (The k is anything but silent)

I did not try that one. I ended up switching to another noise though, the others seemed fine.

> [@Patcher 1.1.0 Released (\*Edit: back to beta for now!\*)](https://ksoloti.discourse.group/t/patcher-1-1-0-released-edit-back-to-beta-for-now/271/36):
>
> The uniform noise on my gills/h7 sounds fine to me!

does that mean you have a ksoloti board with a faster processor? 👀 or is this just the general difference between ksoloti and axoloti?

---

<div class="post-metadata">

**Author:** ![AndyCap](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@AndyCap](https://ksoloti.discourse.group/u/AndyCap)\
**Post date:** [May 9, 2025, 3:17pm UTC](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322/20 "2025-05-09T15:17:26Z")

</div>

Seb has found the problem with the random number generator and fixed it, will be in the next release I guess.

I have a prototype of a newer Ksoloti board with a more powerful processor in it, I have been attempting to get all the software running on it…

[Next page](https://ksoloti.discourse.group/t/1-0-12-noise-bug/322.md?page=2)
