machine memory module

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
miltmobley
Posts: 30
Joined: Mon Mar 07, 2016 11:44 pm

machine memory module

Post by miltmobley » Tue Jan 19, 2021 11:10 pm

Why is the extmod machine_mem only used in the Unix and Windows ports? It would seem to be more dangerous if used there,
and also more useful on the embedded cards, for example to examine adc or dma registers?

User avatar
dhylands
Posts: 3628
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: machine memory module

Post by dhylands » Wed Jan 20, 2021 12:19 am

machine_mem is used in many of the MCU ports as well (stm32, zephyr, samd, nrf, esp8266, eps32, mimxrt)

Here's some sample code that uses it:
https://github.com/dhylands/upy-example ... der.py#L14

(the stm.memXX functions and machine.memXX functions are the same thing from extmod/machine_mem.c)

User avatar
jimmo
Posts: 2262
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: machine memory module

Post by jimmo » Wed Jan 20, 2021 3:54 am

Only the Unix and Windows port need to provide MICROPY_MACHINE_MEM_GET_READ_ADDR and MICROPY_MACHINE_MEM_GET_WRITE_ADDR -- the other ports get the default implementation.

Otherwise just enabling MICROPY_PY_MACHINE and adding mem8,mem16,mem32 to the port's modmachine globals table is sufficient (which as dhylands says, all the ports do).

miltmobley
Posts: 30
Joined: Mon Mar 07, 2016 11:44 pm

Re: machine memory module

Post by miltmobley » Wed Jan 20, 2021 7:55 pm

Thanks for the example code and explanation

Post Reply