!WqsLCItsZbJGhRjnxP:matrix.org

stm32-rs

110 Members
Discussion and support for stm32-rs projects. History is publicly viewable. Bridged to #stm32-rs on Libera IRC. Code of conduct: https://www.rust-lang.org/conduct.html. Public logs: https://libera.irclog.whitequark.org/stm32-rs13 Servers

Load older messages


SenderMessageTime
28 Jul 2021
@firefrommoonlight:matrix.orgfirefrommoonlightExquisite timing13:30:23
@dirbaio:matrix.orgdirbaio

This will use DMA:

    let mut spi = Spi::new(
        p.SPI1,
        p.PB3, p.PB5, p.PB4,
        p.DMA2_CH3, p.DMA2_CH2,
        Hertz(1_000_000),
        Config::default(),
    )

This will use good old cpu-copying

    let mut spi = Spi::new(
        p.SPI1,
        p.PB3, p.PB5, p.PB4,
        NoDma, NoDma,
        Hertz(1_000_000),
        Config::default(),
    )
13:30:48
@dirbaio:matrix.orgdirbaiobut yeah it's quite opinionated, this means you can't use all the weird custom fancy DMA pacing/timing/request generation stuff13:32:16
@dirbaio:matrix.orgdirbaiomaybe embassy will expose a lower-level unsafe api where you can configure all that stuff13:32:47
@thalesfragoso:matrix.orgthalesfragoso
In reply to @firefrommoonlight:matrix.org
And IIRC, the biggest safety concern with the interface I posted exposes is the buffer being dropped while a DMA operation is in progress
Not only being dropped/forgotten in your case, since you don't have a Transfer type, the user can just continue using the buffer
13:33:21
@thalesfragoso:matrix.orgthalesfragosoSo I think it's quite dangerous13:33:27
@firefrommoonlight:matrix.orgfirefrommoonlightGood point13:33:54
@thalesfragoso:matrix.orgthalesfragosoI would recommend doing a transfer type that at least borrows the buffer13:34:01
@thalesfragoso:matrix.orgthalesfragosoIt would still be unsafe, but way less13:34:15
@dirbaio:matrix.orgdirbaio+1 to Transfer type, it'll make the borrow checker prevent the obvious ways of shooting yourself in the foot13:34:55
@dirbaio:matrix.orgdirbaioyou can even have Transfer's drop gracefully stop DMA13:35:08
@firefrommoonlight:matrix.orgfirefrommoonlightFrom an API perspective, what dirbaio just posted is outstanding. I don't think it's possible without HAL managing interrupts to some extent13:35:09
@dirbaio:matrix.orgdirbaioat that point the only wya to trigger UB is to leak the Transfer (with eg mem::forget) 13:35:31
@dirbaio:matrix.orgdirbaio

I don't think it's possible without HAL managing interrupts to some extent

With blocking read/write you can just spin on DMA finishing. With async yeah you need the HAL to own the interrupts

13:36:02
@thalesfragoso:matrix.orgthalesfragoso
In reply to @firefrommoonlight:matrix.org
From an API perspective, what dirbaio just posted is outstanding. I don't think it's possible without HAL managing interrupts to some extent
You can have a method to check if it's complete and a stop/finish method
13:36:44
@thalesfragoso:matrix.orgthalesfragosoThen you can let the user call them as they prefer13:37:08
@firefrommoonlight:matrix.orgfirefrommoonlightYeah; to block you could just poll the tx complete etc flag then return, but at that point, you lose a big adv of DMA13:37:15
@thalesfragoso:matrix.orgthalesfragosoBe it on interrupts or from time to time, or just block on it13:37:23
@firefrommoonlight:matrix.orgfirefrommoonlight * Yeah; to block you could just poll the tx complete etc flag then return, but at that point, you lose a big adv of DMA13:37:24
@dirbaio:matrix.orgdirbaiodma is still useful with polling13:37:35
@dirbaio:matrix.orgdirbaiouser can start 10 DMA transfers at once then wait for all to finish13:37:48
@thalesfragoso:matrix.orgthalesfragosoEven without the interrupts, the user can still do some unrelated work and then poll later13:38:00
@dirbaio:matrix.orgdirbaiowhere it really shines is async though 😜13:38:19
@firefrommoonlight:matrix.orgfirefrommoonlight That works too, and would make for an easy API. I'm using a working assumption that practical uses will involve an interrupt. Maybe that's a good assumption - and maybe not 14:06:04
@firefrommoonlight:matrix.orgfirefrommoonlight
In reply to @thalesfragoso:matrix.org
You can have a method to check if it's complete and a stop/finish method
* That works too, and would make for an easy API. I'm using a working assumption that practical uses will involve an interrupt. Maybe that's a good assumption - and maybe not
14:06:15
@firefrommoonlight:matrix.orgfirefrommoonlightedit: NVM, that's a good point re multiple tranfsers and polling14:06:46
@firefrommoonlight:matrix.orgfirefrommoonlightor start, and poll at arbitrary later point14:07:54
@firefrommoonlight:matrix.orgfirefrommoonlightI think this will make more sense after I use it more14:08:04
@damccull:matrix.orgdamccull joined the room.15:50:02
@9names:matrix.org9namesDMA is lower power and can also be faster than CPU, since it can (potentially) do a load+store on different busses in a single cycle23:26:02

There are no newer messages yet.


Back to Room List