starblue has quit [Ping timeout: 258 seconds]
starblue has joined #rust-embedded
fabic has joined #rust-embedded
PyroPeter has quit [Ping timeout: 258 seconds]
PyroPeter has joined #rust-embedded
DepthDeluxe has joined #rust-embedded
DepthDeluxe has quit [Ping timeout: 264 seconds]
fabic has quit [Remote host closed the connection]
fabic has joined #rust-embedded
richarde1 has joined #rust-embedded
richardeoin has quit [Ping timeout: 260 seconds]
<re_irc> <> Hey there! Does anyone know if there's a general purpose RiscV Allocator crate out there? Similar to alloc-cortex-m?
fabic has quit [Ping timeout: 258 seconds]
<re_irc> <> the cortex_m specific stuff is just a couple of calls to cortex_m::interrupt::free, which you could swap for riscv::interrupt::free
<re_irc> <> i wonder if it would be worth porting it to critical_section instead to make a truly generic allocator
<re_irc> <> Yep, that's what I just did. Maybe that might be a good idea, the cortex_m code is really only the critical section part!
<re_irc> <> Is it possible to have a no-std crate in the same workspace as a std-crate?
<re_irc> <> Context: I want to have a std-enabled host-side client for an embedded-firmware crate in the same repo
fabic has joined #rust-embedded
<re_irc> <> You could do this with a shared workspace ( Just create the two crates in a folder, and then create a Cargo.toml file in the top level folder (where both of them live). Then you could define the workspace in the toplevel Cargo.toml:
<re_irc> <> ```toml
<re_irc> <> [workspace]
<re_irc> <> members = [
<re_irc> <> we're talking about something different here Bastian
<re_irc> <> specifically that cargo tries to include std stuff in your no_std crate if it shares a workspace
<re_irc> <> i think it's still problematic, haven't seen any news that it's changed since someone brought it up last
<re_irc> <> May have changed with the new cargo `resolver="2"`?
<re_irc> <> i haven't tested it since resolver="2" became a thing so that's definitely possible
fabic has quit [Ping timeout: 260 seconds]
<Lumpio-> I've had std and no_std crates in the same workspace and haven't had that problem
<Lumpio-> So it might be dependent on your deps or whatever, and the resolver
<re_irc> <> if your std-using crate has a dep with `std` feature enabled, and your nostd crate wants the same dep but without `std` feature enabled, it breaks
<re_irc> <> because cargo workspaces resolve deps' features for all workspace crates "together"
<re_irc> <> so you end up with `std` enabled for the dep of the nostd crate
<re_irc> <> and there's no way around that
<re_irc> <> you simply can't put them in the same workspace
<re_irc> <> the cargo docs seem to claim that you can condition e.g. std features on build target.
<re_irc> <> resolver=2 doesn't fix it (that's only for dev-deps/build-deps. "main" deps still get features merged)
<re_irc> <> hm
<re_irc> <> maybe you can rig the std-using crate so it only requires `std` features on deps when building for std
<re_irc> <> but that makes cargo.toml super ugly, for something you're not going to build for nostd anyway
<re_irc> <> Maybe instead use one repo with three or more crates (`shared`, `no_std`, `std`) and no top level workspace.
<re_irc> <> Yeah, that's what I was leaning towards as well
fabic has joined #rust-embedded
fabic has quit [Ping timeout: 252 seconds]
fabic has joined #rust-embedded
fabic has quit [Ping timeout: 258 seconds]
<re_irc> <> did anyone end up building a bootloader that's rust friendly? seems like that has been an ongoing thing
<re_irc> <> noticing some nice blog posts on PIC code for cortex-m and such, so maybe even can have multiple slots without moving them around like seems to be the usual strategy
<re_irc> <> Not sure, if I am asking in the best room here, but:
<re_irc> <> Is anyone aware of a crate, which provides a more advanced config system for cargo / rust? I currently have a custom xtask crate for my project, where I do all the stuff, that cargo can`t really do for me.
<re_irc> <> Now I want to implement a config system, where I am able to do more advanced configurations. Cargo is rather limited, there is for example no way, to pass e.g. a numeric cfg etc...
<re_irc> <> The obvious thing would be something generating a module.
<re_irc> <> I am currently thinking of adapting a python kconfig implementation, and modify it to spit out rust files. Something more rusty (pure rust) would be nicer :P
<re_irc> <> You could use to automatically generate rust files too - example here:
<re_irc> <> Yes, thats the way I want to do it. I am specifically asking for any crates, which help with config file parsing & code generation.
<re_irc> <> Perhaps look into `syn`, although that's more used for proc-macros and such
<re_irc> <> But it's a general programmatic approach to generating rust code
<re_irc> <> I will probably just use my own toml based cfg format, then generate a
<re_irc> <> Problem is, that the config can potentially get really complex, and I`d like to define the schema of the config (e.g. which cfg values etc... are available) also with toml.
<re_irc> <> How mature is the stm32l4 crate? It says work in progress, but does that mean unusable or almost ready for professional use?
richarde1 is now known as richardeoin
<re_irc> <> Generally for professional embedded you'll end up forking every dependency anyway.
<re_irc> <> adamgreig: You mentioned 0.8mm pitch BGA at one point—is there any way to determine if a chip has a bga pitch that big without looking all the way down at the datasheet?
<re_irc> <> That's a sad truth!
<re_irc> <> why is that, in general? Experiences, thoughts? I'm curious if there's stuff we can do to make that less frequent
<re_irc> <> faster PR reviews?
<re_irc> <> Sometimes it will say in the package name, distributor websites often have it as a data column, st website has it on their part finder etc, but the datasheet is the place eventually...
<re_irc> <> Not enough compile time configuration in the language yet. In C you can have headers for a user of a library to fill in, and those will const propagate in GCC. Rust has a long way to go for that level of configurability with `const`.
<re_irc> <> Faster PRs is another. Also more frequent releases when a PR is merged, switching to a git version for a bugfix is the gateway to forking.
<re_irc> <> That said, the forking situation is still a lot better in embedded rust than embedded C.
<re_irc> <> can anyone recommend a no_std deflate crate?
<re_irc> <> What's the best way to get random numbers in rust embedded? It seems like most of the relevant features don't work with the `rand` crate with default_features set. Eg generate a random number between 0 and 1
<re_irc> <> Maybe that's what the hardware periphs ar for?
<re_irc> <> for decompression-only I'm using [uzlib]( (C library, not crate). All the crates I tried had at the very least 4x code size. I didn't compare performance since uzlib was fast enough
<re_irc> <> firefrommoonlight: you want a pseudo random number generator.The rand crate can be used in no_std and it provides pseudo random number generators
<re_irc> <> you just need to seed it with *proper randomness* which might be hard depending on your HW
<re_irc> <> use hwrng if it's fast enough for your use case, otherwise use it to seed a ChaCha12Rng :P
<re_irc> <> dirbaio: ok thanks. Was considering zlib already, have some experience with it in embedded. Will look into uzlib
<re_irc> <> Oh nice
<re_irc> <> the impression I got is everyone optimizes for performance, uzlib is the only one optimizing for code size
<re_irc> <> Should I just use the STM32 (etc) RNG periph?
<re_irc> <> or would that be used in addition to rand with the seed?
<re_irc> <> check datasheet for speed
<re_irc> <> some HWRNGs are super slow
<re_irc> <> stm32's (at least some) are fast though
<re_irc> <> sweet
<re_irc> <> in that case chacha is probably not worth it
<re_irc> <> though stm32 rng peripheral gives you a u32 that's distributed uniformly at random between 0 and 0xffff_ffff
<re_irc> <> if you want a random float between 0 and 1 you have to take care of that yourself, for example
<re_irc> <> while rand etc has algorithms for sampling various distributions of interest given some source of uniform randomness
<re_irc> <> doing this yourself is an easy thing to mess up
<re_irc> <> (depends on how much it matters of course...)
<re_irc> <> yeah, use something from rand and seed it with the HW for simplicity.
<re_irc> <> yea. that also saves worrying about sharing access to the rng and so on
<re_irc> <> is there something that can do "random float between 0 and 1", out of a RngCore?
<re_irc> <> that'd be helpful since HALs implement (or should) RngCore
<re_irc> <> `rand`?
<re_irc> <> I think the int would actually be what I want; that's perfect
<re_irc> <> Diving into RM now
<re_irc> <> I figure white noise is pretty easy if you use a finite number of steps with squaring
<re_irc> <> float is more complicated, since the values are not distributed uniformly (more distinct values closer to 0).
<re_irc> <> you want to generate white noise?
<re_irc> <> So you can`t just rand.nextInt() as float
<re_irc> <> Yep!
<re_irc> <> or transmute::<_, float>(rand.nextInt())
<re_irc> <> I want to make headphones with a built in audiogram and then equalizer based on the results, and figure playing the test tones over white noise is a better gauge than the traditional silent environemtn
<re_irc> <> oh `rand` can run on nostd? I thought it couldn't. I don't get what the `rand/rand_core` split is for then, lol
<re_irc> <> Since people with hearing loss might bge able to hear fine when its quiet
<re_irc> <> firefrommoonlight: Personally, I would just generate some random bytes, and put it into an array, then loop over it ^^
<re_irc> <> you
<re_irc> <> For your usecase
<re_irc> <> if you just want to generate noise you don't need it to be cryptographically-secure rand! :)
<re_irc> <> some crap super-fast PRNG should work
<re_irc> <> 44kHz 16-bit samples is 88kB of array just for a 1s period
<re_irc> <> and it'll probably be faster than the HWRNG
<re_irc> <>
<re_irc> <> yea, any fast prng should work well, doesn't even need seeding really
<re_irc> <> adamgreig: yep, that`s a bit much. just repeat a smaller sample then ^^
<re_irc> <> Good point. I think I can do a long array though, or continuously-generated
<re_irc> <> Yea- continuously-generrated white noise is what I would do
<re_irc> <> if you repeat a small sample i think it would sound very obviously periodic?
<re_irc> <> But then a small PRNG is one sample repeated with some Xoring probably :-)
<re_irc> <> i wonder what the best way to generate a white noise source is from random u32
<re_irc> <> probably just 🙈, cast to i32, pretend it's white
<re_irc> <> Sum 10 or so squared random values
<re_irc> <> Although that's with floats so the positives and negs cancel
<re_irc> <> I guess you'd use i32s
<re_irc> <> that seems both inefficient and not necessarily going to get what you want?
<re_irc> <> do you want gaussian white noise?
<re_irc> <> Well, it truly does generate random white noise, but maybe too computationally inefficient
<re_irc> <> white noise is zero mean by definition so not sure summing squares would do it
<re_irc> <> (well, with infinite steps, but close enough is good enough)
<re_irc> <> When half are positive and half negative, mean is 0
<re_irc> <> cat /dev/urandom| aplay sounds very noisy -> so a PSRNG should do well enogu
<re_irc> <> when you say "squared random values" what do you mean?
<re_irc> <> ```rust
<re_irc> <> result / num_steps
<re_irc> <> let mut result = 0;
<re_irc> <> result[i] += (random() -.5) * 2
<re_irc> <> for _ in 0..num_steps:
<re_irc> <> Only with ints
<re_irc> <> It's white noise when num_steps approaches oo
<re_irc> <> I just need the random() fn
<re_irc> <> you might be making more work for yourself than necessary here
<re_irc> <> though I don't know how that's "summing squares", you're not squaring?
<re_irc> <> Oops I mispoke
<re_irc> <> I haven't tried this but I think so, rand's docs say "no_std compatibiliy (partial)"
<re_irc> <> Mainly, I want to make it so the tone is designed to stand out against the white noise background, instead of a very quiet tone in a silent background. This #1 demonstrates hearing in a noisy environment, and #2, avoids the need for a totally quiet room
<re_irc> <> the point of the separate crate is to make it a small dependency for people implementing rng sources I think
<re_irc> <> so, "white noise" is anything that's zero mean, finite variants, and each sample is independent
<re_irc> <> people often talk about "gaussian white noise", which is where the distribution of samples is gaussian
<re_irc> <> the "standard" random() sort of function is "uniform", meaning it returns all possible numbers in its range with equal probability
<re_irc> <> but in a gaussian distribution, samples closer to the mean (0 for white noise) are more common, and more extreme values are less common
<re_irc> <> if you add up a lot of uniform random numbers, the distribution of the sum tends towards a gaussian distribution, because on balance it's likely that positive and negative numbers cancel out, so the sum is closer to 0 (like a gaussian sample)
emerent has quit [Ping timeout: 252 seconds]
<re_irc> <> so, if you're adding ten random numbers, maybe it's because you want gaussian white noise specifically? but in that case, you can probably be more efficient by generating gaussian samples to start with, instead of ten uniform samples
emerent_ has joined #rust-embedded
emerent_ is now known as emerent
<re_irc> <> Correct!
<re_irc> <> there's a few nice algorithms for this, like the box-muller transform which turns two uniform samples into two gaussian samples
<re_irc> <> Maybe CMSIS-DSP has something more efficient
<re_irc> <> Oh nice. What i posted is probably slower than it needs to be
<re_irc> <> so instead of ten uniform samples per output sample (and the output distribution is _not_ gaussian, it's just a bit closer to it than you started), you get one gaussian sample per input sample, and the distribution is much better
<re_irc> <> _but_, the box-muller transform is a bit of a pig to implement on embedded, because it needs sqrt, ln, cos, and sin
<re_irc> <> Luckily, CMSIS *does* have those!
<re_irc> <> yea, but it won't be fast
<re_irc> <> (But perhaps since I don't need ti to be super precise, I could use the algo I posted with a low num of steps??)
<re_irc> <> easy way to get randomness fitted to a gaussian curve is a lookuptable with more samples close to 0.
<re_irc> <> Then generate one random number to select table index, and optionally as a second step add a small offset second random number.
<re_irc> <> That means 1/2 PSRNG calls per sample.
<re_irc> <> Oh nice!
<re_irc> <> If your cpu is slow
<re_irc> <> if your current approach with summing ten samples sounds good enough, you can go ahead with it; maybe use an i32 as the accumulator and split each random u32 into two input i16s
<re_irc> <> there's a slight catch which is that a uniform i16 is not zero mean because there are slightly more negative options than positive options
<re_irc> <> but probably not important for audio noise
<re_irc> <> Yea - Can always convert on first/last step
<re_irc> <> Related question - I always wonder about the u32 buffers you send to DACs etc or accept from mics for audio. Is the DC offset significant for the way speakesr operate?
<re_irc> <> but, you could also try just using each sample by itself instead of summing ten, and see how it sounds, it's still "white noise", just not "gaussian white noise"
<re_irc> <> averaging 10 samples seems faster than the box-muller monster formulas lol
<re_irc> <> yea for sure
<re_irc> <> Ie ideally you think of a signal like a sin wave oscillating around 0, but for these u32 arrays, it's probably osscilating with a DC offset of half a U32's max range
<re_irc> <> much worse distribution quality though
<re_irc> <> not many DACs take 32 bit inputs but in general they define some mapping from their control words to their output voltage
<re_irc> <> True, re maybe not needing gauassian. I'm still in the super early design phase for this
<re_irc> <> And it's going to be a somewhat ambitious project
<re_irc> <> perhaps they're two's complement, perhaps they're 0-VCC and map linearly, whatever
<re_irc> <> usually for an audio DAC you AC-couple the output, which removes any DC offset
<re_irc> <> I was using STM32's 12-bit DAC, where I'd manually reshape the signal to be about 500 - 3000 (range of 12 but unsigned is 0 - 4095)
<re_irc> <> but yea, for a common DAC like on an stm32, where the output is 0v to 3.3v, and you control it with an input of 0 to 4095, your sine wave has a DC offset of like 1.65v
<re_irc> <> Switching to a 24-bit CODEC, but don't have it working yet
<re_irc> <> but if you are using that for audio, you AC couple it (i.e., couple it through a capacitor or other high-pass filter), so the DC component is removed
<re_irc> <> But I send the I2S data to the codec using a u32 (Although without clipping the 24-bit limit)
<re_irc> <> Maybe some dacs output +/- voltage?
<re_irc> <> if you were using it for some other analogue purpose, maybe you need a bipolar DAC (can go above and below zero), or maybe you use some extra circuitry to shift it or whatever
<re_irc> <> I guess the issue is how to speakesr work :/
<re_irc> <> Oh that makes sense re the AC couple!
<re_irc> <> the speakers don't generally enjoy DC because it just heats their coils without moving them
<re_irc> <> but you would AC couple speaker outputs
<re_irc> <> This is great info
<re_irc> <> (depends on the speaker technology I guess. some technologies are inherently high-pass and don't care about DC)
<re_irc> <> It's possible this is handled by codecs
<re_irc> <> Since they tend to be pretty specialized for signal in, sound out
<re_irc> <> yep, quite possible, but often it will be handled by an amplifier stage after the codec too, depending on how integrated your codec is
<re_irc> <> The one I have here has both speaker and headphones out, but I haven't read the fine prints or scoped them
<re_irc> <> I thoguht of this since I was surprised at how... high-level the whole thing is
<re_irc> <> Ie how it's *not* just a DAC, but I can't figure out exactly what it is!
Darius_ has joined #rust-embedded
Darius has quit [Ping timeout: 245 seconds]
Darius_ is now known as Darius
tafa has joined #rust-embedded