I'm looking for an existing way of uploading a .mpy file dinamically, like uploading the file through the HAL port while micropython is running, get the file and execute it. By this, I'm aiming to upload and execute files without having to reprogram the chip, instead of freezing them into the firmware. Does this code or any similar exist?

I'm currently using a STM32 NUCLEO F446ZE with micropython's minimal port, but if there's any other way of doing this or any other port capable of doing it I would be very grateful to know about them.

Using mpy-cross, you can compile the .py file. If the target has a file system, then you can upload it with any suitable tool, like pyboard.py, ampy, rshell. But there is a difference to frozen bytecode. Frozen bytecode is executed from flash. The bytecode and static data remains in flash. Only dynamic data is in RAM. Uploaded mpy files are loaded to RAM for execution. Therefore they need more RAM. Still, the RAM demand is smaller than loading .py files on the target, since no RAM is required for compiling.

Thank you for your responses, I've searching for some clues in the code and I found some save-load file inside persistentcode.*

For what I've understand, these functions work with the board file system, they open and read a .mpy file and then build a reader object with a data attribute which is a reader_posix who has a 'buf' attribute where stores the content of the .mpy file for it's posterior process, am I wrong?

In my case, my board doesn't have one, so I was thinking of modifying these functions or create new one based on them, who could take the content of a .mpy through a HAL_Recieve, and store it inside a reader_posix object which would be inside a reader object which will be passed to 'do_execute_raw_code' for the code execution.

Probably, I am missing some things or not considering others but is the idea I came up with. Do you have any tips or functions I should take a look at before trying my idea?