How to find the absolute memory pointer to a buffer.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

How to find the absolute memory pointer to a buffer.

Post by Ephreal » Mon Dec 30, 2019 7:26 pm

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

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Mon Dec 30, 2019 8:10 pm

Look at the module uctypes and the methods uctypes.addressof() and uctypes.bytearray_at().

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Tue Dec 31, 2019 6:09 am

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.
Peter Hinch
Index to my micropython libraries.

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

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

Post by Ephreal » Tue Dec 31, 2019 9:30 am

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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Wed Jan 01, 2020 5:33 am

addressof does produce absolute addresses.
Peter Hinch
Index to my micropython libraries.

Post Reply