SRAM decorator for RP2 port? #18429
Replies: 3 comments 9 replies
-
|
Can one even do this with the native API? |
Beta Was this translation helpful? Give feedback.
-
|
The way I understand it is :
Theoretically it might be better to not freeze modules that contain hot loops.
Note I have not tested / verified this |
Beta Was this translation helpful? Give feedback.
-
|
Bear in mind that MicroPython bytecode is not actually executed. It is read by the MP runtime interpreter. The physical location of the bytecode may be in RAM or in Flash. If the application comprises Python sourcecode, the compiler converts the code into bytecode in RAM which is then interpreted by the runtime. So XIP is not really relevant to running bytecode, which to the hardware is just data. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am fairly new to MicroPython. This question is targeted at RP2 port! Been writing C-like languages for a while now, decided to force myself to learn MicroPython!
I am curious if there has been any discussion as to having a SRAM decorator to keep time critical bytecode in SRAM and avoiding XIP cache misses?
from machine import Timer@micropython.sram # keep/copy into sram@micropython.native # if necessary for native or viper performance ??def my_callback(t):print("Timer fired!")# [...]tim = Timer()tim.init(period=2000, mode=Timer.PERIODIC, callback=my_callback)I am also uncertain as to IRQ call backs to native/viper code, I think I read there are some gotchas or limits to this so a callback might need to do:
@micropython.sram # keep/copy into sram@micropython.native # or viperdef cpu_intensive_function(x: int) -> int:# something CPU intensive herereturn answer@micropython.sram # keep/copy into sramdef my_callback(t):print("Timer fired!")result = cpu_intensive_function(1)# [...]or possibly freeze the code into custom firmware.UF2 for RP2's (did a hello "module" frozen into a custom UF2 firmware to figure out how that works).
>>> help("modules")__main\__ asyncio/lock hashlib random_asyncio asyncio/stream heapq re_boot binascii hello rp2...
>>> import hello>>> hello.world()hello worldJust throwing this out. Thanks for any constructive responses back to a MicroPython newb!
Beta Was this translation helpful? Give feedback.
All reactions