We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Anybody got any experience with writing to Flash Code Memory in User Application Mode? I'm trying to write code to upgrade firmware in the field, but am unable to successfully overwrite more than just a few pages of new firmware into the MSC1210 flash code memory.
I've written successfully to the Flash data memory (but only actually needed to write 2 or 3 pages), and am aware of the problems with running code from flash whilst writing to it so I'm using the BootRom routines.
I'm trying to write 8k of new code over the first 8k of code space. I've made sure that my code to do this is high up in memory - around 24k - it's written in C and I've looked at the generated assembler to make sure no calls to any "helper" routines elsewhere are getting called (other than the routines in the bootrom of course). my code is something like:
for (i = 0; i < 64; i++) //64 pages in total in 8k { address = i * 128; src = &xMem.Code[address]; if (page_erase(address, 0, FPM) == 0) { for (j = 0; j < 128; j++) { hex = *src++; write_flash_chk(address, hex, FPM); address++; } } }
Its a simple loop to write 64 pages, each page 128 bytes 1 byte at a time. It mostly gives up the ghost at around page 10 or 11 -occasionally it will write 17 or 18 pages.
If I make the outer loop (i = 30; i < 32; i++) it writes those page ok, so It doesn't seem to be an addressing problem. I've played around with lots of different values in the FTCON (flash timeing control) register with no better success.
Anybody got any ideas?
.
Oh yes it is!!
After a day of searching I have finallly resolved the problem.
It is, specifically, C51's rather agressive optimization. Taking the default level of 8, described as "Reuse common entry code" in the "Options" dialog and "Common Tail Merging" in the online documentation, created a helper function that it placed in the code space I was writing to. Even though the two "common" calls were syntacticaly different C51 optimized them and placed a helper routine in memory where I was loading new code to.
The two calls, which were located in seperate modules are:
write_flash_byte(add++,*ptr++,0);
and
write_flash_byte(add,*ptr,0); add++; ptr++;
In the second instance I had deliberately placed the increments outside the parameter list as I wanted to ensure the code was as "simple" as possible, and I had used the userclass pragma so I could direct the linker to place high in memory, way from where I was writing the new code to.
not a C51 issue
never heard of "User Application Mode" for a '51.
some larger processors have "system mode" and "application mode"
Erik
"User Application Mode" here relates (as the thread subject implies) to the programming of the internal flash memory - other modes in this respect are Serial Programming mode and Parallel programming mode. Nothing at all to do with the mode of the processor - though whilst in either the Parallel or Serial programming modes the processor is to all intents and purposes idle.
Rod.