Replies: 3 comments
-
In terms of performance, the overhead of the VM is likely going to overshadow any difference between Make sure you avoid global variables or attribute lookups... e.g.
is slower than
because you avoid the lookup of globals["machine"] and machine["mem32"], whereas m32 is a fast local. The main thing to watch out for is memory allocations -- this can happen in uctypes when accessing nested fields (see https://docs.micropython.org/en/latest/library/uctypes.html#limitations), but also when using register values that are larger than small ints. |
Beta Was this translation helpful? Give feedback.
-
uctypes is quite powerful for creating an object that describes / accesses memory (eg CPU registers). I wrote a script to parse stm hal headers and translates them into uctypes definitions to provide convenient register access (for advanced timer/dma setup) The catch is, the generated files are big. In micropython where you're often counting bytes for efficient flash and ram use, even just the strings that name all the register / field variables adds really quick. Just the registers and their dependent defines for Timer, dma and RCC access added up to 40KB of compiled bytecode! |
Beta Was this translation helpful? Give feedback.
-
Thank you both for your feedback. I currently work on a system where memory constraints are not an issue, so it makes sense for generators to make as much code as possible (with plenty of comments and documentation strings also). Memory constraints make this kind of register map code generators an awkward fit with MicroPython. Good to know, but still a bit of a disappointment. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I do not have much experience with MicroPython, but I do have experience with the
ctypes
anddevmem
with a full Python on PYNQ.What I would like to know is, how
machine.mem8/16/32
anductypes
compare to each other in the context of accessing memory mapped registers. How do they compare in terms of performance and memory usage.The purpose of this question is to provide some context to the idea of writing a SystemRDL code generator for MycroPython memory maps.
Beta Was this translation helpful? Give feedback.
All reactions