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.

UCD3138: Write UCD3138 Pflash then UCD3138 Reset.

Part Number: UCD3138

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

  • Hi Kami,
    If you are a Chinese, you can send me a email using Chinese to clarify your question. My email address is Frank-Tang@ti.com
  • Hello Frank
    我已經寄Email給你了.Email標題 UCD3138 Reset while write Pflash
    E2E以及Email上面的內容,簡單來說 我要寫入Pflash. 我拿到TI Boot_flash的範例程式. 開發環境是CCS3.3的.
    1.我在APP裡面寫Pflash UCD3138會Reset (使用SWI)
    2.我在Boot_flash超過2K的地方寫也會Reset
    3.我在Bootflash 2K內寫.就可以完整的寫入我想寫的內容.
    目標在APP裡面寫,因為APP可以做PWM控制.
  • 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. 

  • Hello Ian
    thanks for your help.
    I very interesting in memory re-mapping function (fly switching). I already apply chips sample but disty sales reply back order till 2017/4/25. currently I only have UCD3138 (40pin and 64pin). Before the all, I must solve the issue of can not write pflash.
    Best Regards,
    Kami Huang
  • 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

  • Hello Ian
    I still don't understand how to program plash at all. Should I write DecRegs.MFBALR1.all ?
    I saw following example TI example code in technical_reference_manual(SNIU028A) page 523.
    Would you please explain more detail?
    Best Regards,
    Kami Huang