Hello Daniel, thanks for responding.
I created a separate task just for the flashing, it has 2100 bytes of stack allocated to it. I am unable to allocate more due to what I think is heap fragmentation, as I am deleting some tasks before creating this one.
Anyways, 2100 sounds like it should be enough -- yet it still fails in the same way. For the flashing, I am doing 16 bytes at a time, exactly like our bootloader.
Do you still think it's a stack problem?
Thanks.
EDIT: I have just managed to try it with 8192 bytes allocated to the flashing task. Still the same problem.