internal flash with FreeRTOS?

hudson2009 wrote on Wednesday, October 22, 2008:

Hi

I have a problem when trying to write to flash on a AT91SAM7X256.

I have moved my flash-write functions to RAM.

I think I have it setup correctly.

The problem seems to be timing, because if I step through the flash write code, it works like a charm… but if I let it run full speed it crashes every time to the pabort!

Thanks!

regards

woops_ wrote on Wednesday, October 22, 2008:

Is this a freertos question? There are no flash write functions in freertos.

hudson2009 wrote on Thursday, October 23, 2008:

Yes the question is for freeRTOS.

I have project running on freeRTOS.
I am using AT91SAM7X  and Rowley Crosswork.

I am trying to use the internal flash to store/log data.
My function seem to be running ok(write to flash) if I run it before RTOS
vTaskStartScheduler();

and after i shift it into one of the task after scheduler start,
I always end up in :

dabort_handler:
  b dabort_handler

Any idea how to write internal flash in RTOS?

many thanks!

regards
HS

tonau wrote on Wednesday, June 17, 2009:

Hello @ All,

I had the same problem. I made a funktion based on the code of the example project basic-internalflash-project. I tested the funktion in main before the scheduler starts and everything was fine. Then I moved it into a Task and nothing worked anymore.I discovered that two things are important. First you have to encapsulate your flash_write function with taskENTER_CRITICAL(); and taskEXIT_CRITICAL();. Second the system crashes if you use FLASHD_Unlock(AT91C_IFLASH, AT91C_IFLASH + AT91C_IFLASH_SIZE , 0, 0); and FLASHD_Lock(lastPageAddress, lastPageAddress + AT91C_IFLASH_PAGE_SIZE, 0, 0); to lock and unlock the flash pages. Dont ask me why this happens. But I found that no pages are locked so writing to flash should be no problem.
Maybe anyone can explain this behavior.