Hey there,
I'm developing on ColdFire V1 (MCF51QE128) using CodeWarrior v10.1. All flash routines are taken from AN3942.
BurstProg and PageErase are working in general, but:
When I want to Erase several pages in one function, the microcontroller crashed (debug session is terminated, connection lost; micro controller does wierd things). This happens in this function, when i>= 12:
Where:
So, this function crashes, when address is 0x17400 or higher (I tested it with i=12 or i=13, by skipping i=12).
Please help me finding the source of this problem.
Thanks in advance!
alias5000
Solved! Go to Solution.
Oh, it's pointer arithmetic related bug:
when you incement some pointer by N, it is incremented by the size of pointer data times N. So if int* ptr points to 0x14400, and in case sizeof(int)==4, ptr+1 will point to 0x14404. What happens in your code is that you first typecast base to int*, then add to that 1024*4*i, so you are erasing 0x14400, then 0x14400+1024*1*4, 0x14400+1024*2*4, 0x14400+1024*3*4 etc. Try calculating integer address first, and then typecasting it to pointer type:
Page_Erase((unsigned int *) (FLASH_DATA_BASE + i*1024));
Oh, it's pointer arithmetic related bug:
when you incement some pointer by N, it is incremented by the size of pointer data times N. So if int* ptr points to 0x14400, and in case sizeof(int)==4, ptr+1 will point to 0x14404. What happens in your code is that you first typecast base to int*, then add to that 1024*4*i, so you are erasing 0x14400, then 0x14400+1024*1*4, 0x14400+1024*2*4, 0x14400+1024*3*4 etc. Try calculating integer address first, and then typecasting it to pointer type:
Page_Erase((unsigned int *) (FLASH_DATA_BASE + i*1024));
Oh, yes, what a stupid mistake!
Thank you very much for this hint
Isn't watchdog enabled?
Hm, that is a good hint.
Watchdog (COP) is enabled. For testing purposes I diabled it, which didn't change anything in behaviour. But obviously there is a reset happening, because the main routine is re-executed from beginning, when I perform this flash-erase in free run mode (--> no debugging).
I copied the output of srs-register to some LEDs and found out, that an illegal Address reset happens. Flash is unprotected (FPS = 7f, FPOPEN = 1). I don't see, why this happens.