Page 1 of 1

How to find the absolute memory pointer to a buffer.

Posted: Mon Dec 30, 2019 7:26 pm
by Ephreal
My mypy resides in memory from where it is executed (no drive).

I need to setup a DMA controller and for that I need to map an area of my entire memory (essentially outside the heap defined area) and write the start address to this DMA controller.

How do I achieve this in mypy. Do I need to write my own c module or is there an buildtin feature which can give me this address. I'm guessing that I need two address one for accessing the area inside mypy and one for the DMA controller.

I am thinking though I have not tested this but creating a buffer in the mypy virtual environment will only give me an relative point inside the heap mapped area of the total ram area.

Regards

Re: How to find the absolute memory pointer to a buffer.

Posted: Mon Dec 30, 2019 8:10 pm
by Roberthh
Look at the module uctypes and the methods uctypes.addressof() and uctypes.bytearray_at().

Re: How to find the absolute memory pointer to a buffer.

Posted: Tue Dec 31, 2019 6:09 am
by pythoncoder
Those deal with absolute addresses, but only of objects created in the MicroPython heap. To program DMA outside of the heap area will require a C module, and also altering the build system to reserve a suitable area. Why does the object have to be outside the heap area? The normal MicroPython approach would be to create buffers in the heap (bytearray instances) and pass their addresses (acquired by the addressof method suggested by @Roberthh) to the C module.

Re: How to find the absolute memory pointer to a buffer.

Posted: Tue Dec 31, 2019 9:30 am
by Ephreal
I might have explained it wrong. The memory area vill ofc be mapped inside the heap. But the address I need to pass to the DMA must be the absolute address since it can only target the entire memory.

Re: How to find the absolute memory pointer to a buffer.

Posted: Wed Jan 01, 2020 5:33 am
by pythoncoder
addressof does produce absolute addresses.