This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Preempting a task writing to flash

When addressing an (external) flash by a RTOS task, is it generally safe to allow that task to be preempted while it is updating the flash? What about interrupts during writing to flash?

  • please do correct me if I'm wrong: As long as I do not overwrite internal flash interrupt vectors, interrupts should not be a problem. that goes for external flash too, I guess? but can it be a problem if a task is preempted before the entire write cycle (on device level) has finished?

  • That depends a great deal on what those other tasks and ISRs do. Any access to the flash by those threads of execution would tend to make it unsafe.

  • I understand. I am more worried about operational sequences not getting completed at the low-level device domain, because the respective task is preempted. is that a danger? if not, I understand that if I use a task to access the flash (and that task only), and that task uses data that copied for it into a queue as source (the task is the only one reading the queue), no problem should be expected, even if interrupts occur as well as preemptions?

  • Whether or not there is a danger of

    operational sequences not getting completed at the low-level device domain

    depends on what kind of interface your external flash has. If the access protocol has maximum times between steps, preemption may have to be forbidden. Some interfaces (e.g. synchronous serial) may not care at all.

  • thanks. I guess I'll have to try and see, because the data sheet does not say a thing about it.

  • You must safeguard the portion of the code when it is performing a write to the flash. Else, the preempting will corrupt the data on the flash. I have experienced this first-hand when I wrote a embedded Linux NAND flash driver. Basically, the NAND flash eventually will hit a critical period when other devices generates interrupts, preempting in the middle of the flash write. This causes the flash's internal logic to provide some error correction. As a result, a few bits are modified and hence, your data is corrupted. You should mask out interrupts during this flash write period.

    Cheers and good luck,
    Tom