After weeks of debugging and a million things tried, finally fixed a bug that ended up being an off-by-one error. Had to turn < into <=. Debugging embedded devices can be hard...
edit: the chaos caused by the error was of course completely unrelated to the process, caused a full watchdog timeout