Hi
Using a KL05, I'm having problems with a bus error generated when reading the FSTAT register after launching a erase command operation. The exact operations I'm doing are the following:
while(FTFA_PDD_GetCmdCompleteFlag(FTFA) != FTFA_FSTAT_CCIF_MASK); /* just to be sure peripheral is ready */
FTFA_PDD_SetFCCOBCommand(FTFA, FLASH_CMD_ERASE_SECTOR);
FTFA_PDD_SetFCCOBAddress(FTFA, addr);
FTFA_PDD_LaunchCommand(FTFA)
/* verification to know when the operation has been completed */
while(FTFA_PDD_GetCmdCompleteFlag(FTFA) != FTFA_FSTAT_CCIF_MASK); /* THIS IS WHERE THE BUS ERROR IS GENERATED */
When the bus error is generated, I observe the flag RDCOLERR in FTFA_FSTAT register has been enabled. I can't understand why this is happening. Even more weird: when I execute step by step this operation, no error is generated. I have tried to add a delay before the sencond FSTAT verification but it is useless.
Do you have any idea about what could be happening? All help will be appreciated.
Thanks in advance
Eduardo
UPDATE: I'm not using Processor Expert code.
Eduardo
When the command is launched the Flash cannot be used until the operation has completed. This means that the code needs to run from RAM.
Check that the launch command is running form RAM otherwise it will indeed work when single-stepped but fail when running normally.
Also
while(FTFA_PDD_GetCmdCompleteFlag(FTFA) != FTFA_FSTAT_CCIF_MASK);
after the launch command has completed is of no use since the launch command MAY never return before completed (otherwise it will immediately crash unless also the complete routine is run in RAM).
The only check that makes sense is for error bits.
Regards
Mark
Kinetis: µTasker Kinetis support
Hi Mark
Thanks for your quick reply. You're right: according to the RM and this AN (AN4695), the launch command and supervision of completion flag must be executed from RAM. But this error is more interesting. Let me explain it:
In the AN note it is indicated that ISR should be disabled before erasing or programming flash operations. My problem is I disabled all peripheral ISR ( __DI(); ), but not core interrupts such as system tick. Once I have disabled the system tick interrupt the erase command is working correctly. This is indeed a good news, but it contradicts the RM and the AN: My code should still be crashing because I'm executing the erase command from the same block flash I'm erasing the sector.
Do you have any explanation about this issue? Thanks in advance
Regards,
Eduardo
Eduardo
I can't explain why you seem to be able to execute the programming code from Flash.
However, since it is contradicting the instructions of usage I would concentrate on correcting the method rather than investigating why incorrect use can operate.
Could you tell me which compiler you are using with the __DI() intrinsic? Is there a description of this because I would have thought that it disabled all interrupts (?)
Regards
Mark
Kinetis: µTasker Kinetis support
KL05: http://www.utasker.com/kinetis/FRDM-KL05Z.html
For the complete "out-of-the-box" Kinetis experience and faster time to market
Don't worry. Looks like a matter related to flash instruction cache or similar. I have made several tests in the function I use to check if the operation has been completed:
This code is OK:
<code>
while(1){<br>
if (FLASH_GetCmdCompleteFlag(FTFA) == FTFA_FSTAT_CCIF_MASK){<br>
res = FLASH_OK;<br>
break;<br>
}<br>
}<br>
</code>
But this other fails:
<code>
while(num_ms < FLASH_TIMEOUT_MS){<br>
if (FLASH_GetCmdCompleteFlag(FTFA) == FTFA_FSTAT_CCIF_MASK){<br>
res = FLASH_OK;<br>
break;<br>
}<br>
delay_us(1000); // IF SUPRESSING THIS CALL, EXECUTION IS OK<br>
num_ms++;<br>
}<br>
</code>
I guess the flash memory buffers the immediate following instructions before they are executed. So this would explain why the execution of first code doesn't crash: because they are being executed from cache instead than flash. Because the code to be executed is more complex in the second one, they wouldn't fit in the flash cache, so it crashes. According to my register MCM_PLACR, cache is ON for both instruction and data, so I think this is a reasonable explanation.
As conclusion: I think is strongly advisable to execute these functions from RAM. Although in my case, that method could give me problems at code certification time.
Thanks a lot of for your help
Regards,
Eduardo