Assert error during garbage collection [Solved]
Re: Assert error during garbage collection [Solved]
Hello Dave, hello @stijn aka stinos,
that was it, it seems. Inclduign the helper functions remove the error, as fas as I tested it.
Thanks a lot.
that was it, it seems. Inclduign the helper functions remove the error, as fas as I tested it.
Thanks a lot.
Re: Assert error during garbage collection [Solved]
Nice!
Can you post the diff here, or a link to it, so the solution is easy to find in the future? This might very well happen again and by now this thread has a bunch of interesting information (actually, almost to the point it should be in the documentation or wiki, or made stciky or so) so would be ideal if it's complete.
Can you post the diff here, or a link to it, so the solution is easy to find in the future? This might very well happen again and by now this thread has a bunch of interesting information (actually, almost to the point it should be in the documentation or wiki, or made stciky or so) so would be ideal if it's complete.
Re: Assert error during garbage collection [Solved]
Hello Stijn,
the changed gc_collect() function/file reads as:
The change consisted of replacing the line:
with
and including the respective header file: #include "lib/utils/gchelper.h"
I did not test the non-threading variant, but opposed to the initial version it now uses the proper addresses for the stack.
The set of files I'm working with is available in my fork of MP as branch w60x. In contrast to the WinnerMicro version is is based on MP version 1.12. https://github.com/robert-hh/micropython/tree/w60x
the changed gc_collect() function/file reads as:
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include "py/obj.h"
#include "py/gc.h"
#include "py/mpthread.h"
#include "lib/utils/gchelper.h"
void gc_collect(void) {
// start the GC
gc_collect_start();
// get the registers and the sp
uintptr_t regs[10];
uintptr_t sp = gc_helper_get_regs_and_sp(regs);
// trace the stack, including the registers (since they live [now] on the stack in this function)
#if MICROPY_PY_THREAD
gc_collect_root((void **)sp, ((uint32_t)MP_STATE_THREAD(stack_top) - sp) / sizeof(uint32_t));
#else
gc_collect_root((void **)sp, ((uint32_t)(mpy_task_stk + MPY_STACK_LEN) - sp) / sizeof(uint32_t));
#endif
// trace root pointers from any threads
#if MICROPY_PY_THREAD
mp_thread_gc_others();
#endif
// end the GC
gc_collect_end();
}
Code: Select all
uintptr_t sp = get_sp();
Code: Select all
// get the registers and the sp
uintptr_t regs[10];
uintptr_t sp = gc_helper_get_regs_and_sp(regs);
I did not test the non-threading variant, but opposed to the initial version it now uses the proper addresses for the stack.
The set of files I'm working with is available in my fork of MP as branch w60x. In contrast to the WinnerMicro version is is based on MP version 1.12. https://github.com/robert-hh/micropython/tree/w60x
Re: Assert error during garbage collection [Solved]
From the looks of it the non-threading one should be fine as well since the registers were the clue.
Re: Assert error during garbage collection [Solved]
Just a question about gc_collect. What is the task gc_collect_root()? Do I understand it right that it searched the stack, or in general, all memory outside the Python heap, for pointers to objects acquired from the python heap and marks them as used?
Re: Assert error during garbage collection [Solved]
gc_collect_root scans a region of memory for root pointers (I.e pointers into the heap) and marks those heap blocks as in-use. gc_collect_start has some calls to gc_collect_root for known areas. The port implementation of gc_collect adds calls to any additional regions of memory which might contain root pointers.
Re: Assert error during garbage collection [Solved]
Thank you. That is a very clear answer.
Re: Assert error during garbage collection [Solved]
This thread is part of the inspiration behind https://github.com/micropython/micropython/pull/5961 (step one in some improvements for making it easier to get this right in ports). Although this change alone might not have been enough, there's so many little details that are hard to get right in a new port that it's worth trying to improve them.
Re: Assert error during garbage collection [Solved]
Thanks, Jimmo. That is surely worth considering. The hint Dave gave was in the same direction and solved the problem. Your's seems a little bit more convenient to use being it a C file which is included, and it also already contains the statement for stack cleanup.
Still, there is some trouble in the code when using LittleFS. Both trouble to the RAM which leads to the file system inaccessible, which disappears after boot, and file corruption. Indeed, that may be related. No problem when using FAT.
Still, there is some trouble in the code when using LittleFS. Both trouble to the RAM which leads to the file system inaccessible, which disappears after boot, and file corruption. Indeed, that may be related. No problem when using FAT.