Closed mattico closed 1 year ago
Here's an example of using this to implement a DMA transfer on STM32: https://github.com/mattico/stm32h7xx-hal/blob/df7cfd347a87ad37f9d6b7dcbd69f2a9369fbd07/examples/dma_uart.rs
I did attempt to use this on shared memory between processes, but failed.
I think the problem is that only the data buffer (buf
) is placed at the pointed-to memory location. The other fields such as write
and read
are on the stack. So this doesn't actually allow sharing the bip buffer (with state) as a whole, but just the data buffer part. To use this for communication between two processes it would require allocating the rest of the fields on the pointed-to memory block as well. Is this correct (my knowledge is lacking here)?
Edit: yes, it seems you noted that here:
I'm trying to do a similar thing, making the buffer use a specific SRAM at a specific address ... but I don't want to use any of the SRAM memory for the bookkeeping variables.
Right, that's a feature for me, wish it was more helpful for you. I suppose what you need is placement-new or a custom Box
that allocates in shared memory. You should be able to just move the BBBuffer
into your shared memory just fine but you'll probably have to use a raw pointer.
cc #67
This allows the
BBuffer
to use a pointed-to memory location rather than an owned array. Some use-cases would be shared-memory IPC, MMIO, or using a specific memory region on embedded. In my case, I want to use a 64KiB block SRAM for a DMA buffer on an STM32H7. It's not enough to just place theBBuffer
there because I want the state variables to live in ITCM for speed, and I want to be able to use the whole buffer for data. There isn't an option for a typenum that's 2^16 - sizeof(BBuffer) so I can't even construct one of the right size currently.I implemented this similar to other embedded libs I've seen by adding a
BBStorage
trait which is implemented by either aPtrSorage
or anArrayStorage
. It worked out okay, but the ergonomics of theArrayStorage
suffer due to const fns being unable to return generic types. Perhaps someone can think of a solution.