Dear Sir/Ms.
Question: how to write pflash by useing APP code?
Why program under 2K is safe for writing pflash?
Best Regards,
Kami Huang
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear Sir/Ms.
Question: how to write pflash by useing APP code?
Why program under 2K is safe for writing pflash?
Best Regards,
Kami Huang
Kami, you can write to program flash from anywhere in program flash. You just have to download the writing program into RAM, go to supervisor mode, and then jump to RAM to execute the program. Then the program has to stay in RAM until the write is finished.
This is because during the write, the program flash will return all FFs. You can't read and write at the same time.
If you are using the boot flash, it normally just stays in supervisor mode from the start, so there should be no need to put it into supervisor mode.
When you are in ROM mode, the ROM is mapped to 0 to 0x7fff, so you have to look at 0x10000 to 0x17fff to see the program flash.
When it goes to flash mode, that is when the flash is mapped to 0 to 0x7fff. the ROM is then mapped to 0xa000.
I've sent you my email so you can send me your code to look at.
We put the boot program in the low memory because of the boot checksum feature - it uses the 2K checksum to permit the boot flash area to start even if the rest of the program flash is corrupted.
Our larger memory devices, the UCD3138064 and 128 devices, have multiple program flashes. With these, you can actually program one flash block while executing from another one. So you can run the power supply from one block while downloading to the other one. And you can switch programs very quickly, permitting you to keep the power supply running.
You said that one of the codes you sent me works. I'd suggest taking that one and making small changes to it until you get what you want. If you make a specific small change and it causes a reset that you don't understand, I can help you with that. That's how I debug issues like this, especially if I have a starting point that works. Writing to program flash is pretty complicated, and everything has to be right.
On the chips with multiple flash blocks, it's much easier to write to the other block. You can do it without copying the code to RAM. And you don't have to wait foruntil the write is complete before you return:
It looks like this:
case 15: // write word to other flash block
if(((arg1) < 0x8000) || ((arg1) > 0xfffc))
{//if out of other block range
return;
}
if(DecRegs.MFBALR1.bit.ADDRESS == 0) //here if flash block 1 is at 0
{
while(DecRegs.PFLASHCTRL2.bit.BUSY != 0) //in case we get called while it's still busy
{
; //do nothing while it programs
}
DecRegs.FLASHILOCK.all = PROGRAM_FLASH2_INTERLOCK_KEY;
*(Uint32 *)(arg1 & 0xfffffffc) = arg2 ;
}
else //if it's program flash 2;
{
while(DecRegs.PFLASHCTRL1.bit.BUSY != 0) //in case we get called while it's still busy
{
; //do nothing while it programs
}
DecRegs.FLASHILOCK.all = PROGRAM_FLASH1_INTERLOCK_KEY;
*(Uint32 *)(arg1 & 0xfffffffc) = arg2 ;
}
break;
It's still in the software interrupt because you have to go to a privileged mode. You don't need a dedicate boot flash, because each of the 2 programs, 1 in each block, effectively acts as a boot program for the other program. I'm not sure whether to call it "buddy boot" or "integrated boot. It's a difficult thing to understand if you've always used dedicate boot flash or boot ROM.
Hello Ian
Would you please send me working total project back by Email? If it's possible, I would like to write Pflash in APP.
After study your code I have some question
if(DecRegs.MFBALR1.bit.ADDRESS == 0) //here if flash block 1 is at 0 { while(DecRegs.PFLASHCTRL2.bit.BUSY != 0) //in case we get called while it's still busy { ; //do nothing while it programs } DecRegs.FLASHILOCK.all = PROGRAM_FLASH2_INTERLOCK_KEY;
// is PROGMRAM_FLASH2_INTERLOCK_KEY = 184219b3 for UCD3183A64 *(Uint32 *)(arg1 & 0xfffffffc) = arg2 ; } else //if it's program flash 2; { while(DecRegs.PFLASHCTRL1.bit.BUSY != 0) //in case we get called while it's still busy { ; //do nothing while it programs } DecRegs.FLASHILOCK.all = PROGRAM_FLASH1_INTERLOCK_KEY;
// is PROGRAM_FLASH1_INTERLOCK_KEY = 0x6c97D0C5 for UCD3138061 *(Uint32 *)(arg1 & 0xfffffffc) = arg2 ; } break;
How about page0?
How to call this SWI? I ask this question because I don't know how to use var arg1, arg2 in SWI.
Best Regards,
Kami Huang