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.

UCD3138128: Multiple image progamming

Part Number: UCD3138128
Other Parts Discussed in Thread: , UCD3138064

Tool/software:

I am writing some code to allow the UCD3138128A to be programmed though a serial port.

The question I have is

What do I have to do to make the boot code recognize an image in blocks 2 and 3 to switch too when it boots up.

And then.. how to I get it to switch to blocks 0 and 1 again when I program those with a newer image?

  • Hello BatMan,

    I am reviewing your inquiry and I will respond on Friday.

    Regards,

    Jonathan Wong

  • Hello BatMan,

    The UCD3138FW-BIDI has an example of clearing blocks 0 - 3 on the UCD3138128. 

    main.c in BiDirection_DC-DC_UCD3138128 has a clear_integrity_word() (line 110) function that clears block 0 - 3 based on the argument. 

    #if (UCD3138128 )
    	#ifdef MEMORY_SCRUBBING
    					clear_integrity_word(1);		// erase 8-byte checksum @ end of pflash block 1
    				  //clear_integrity_word(3);		// erase 8-byte checksum @ end of pflash block 3
    					reset_uP();
    	#else
    					clear_integrity_word(0);
    	#endif

    software_interrupt_wrapper.c shows that clear_integrity_word() triggers software interrupt case 12 (line 95). 

    void clear_integrity_word(Uint32 block)
    {
         swi_single_entry(block,0,0,12);
    }

    interrupts.c contains the software interrupt handler. In case 12 (line 163), the code clears the program flash block by clearing the corresponding user checksum.

    case 12: // clear integrity words, depending on arg1
    
    #if (UCD3138128)
    		//Note:  This clear integrity word covers all cases.  It is designed to clear integrity words based on what address the flash block is
    				//mapped to when it is called.  This is done for code which switches blocks.  And it can erase the integrity word at the end of each of 4 blocks.
    				//
    				//For most applications, it can be simplified considerably if code space is scarce
    				//
    				//
    	{
    		register Uint32 * program_index = (Uint32 *) program_area; //store destination address for program
    					register Uint32 * source_index = (Uint32 *) zero_out_integrity_double_word; //Used for source address of PFLASH;
    
    					register Uint32 counter;
    
    					if(arg1 == 0) //0 means first block in memory, regardless of which block that is;
    					{
    						zoiw_address = 0x7ff8;
    
    						if((DecRegs.MFBALR1.bit.ADDRESS == 0) && (DecRegs.MFBAHR1.bit.ADDRESS == 0)) //here if flash block 0 is at 0
    						{
    							zoiw_flash_key = PROGRAM_FLASH0_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR17.bit.ADDRESS == 0) && (DecRegs.MFBAHR17.bit.ADDRESS == 0))//if it's program flash 1;
    						{
    							zoiw_flash_key = PROGRAM_FLASH1_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR18.bit.ADDRESS == 0) && (DecRegs.MFBAHR18.bit.ADDRESS == 0))//if it's program flash 2;
    						{
    							zoiw_flash_key = PROGRAM_FLASH2_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR19.bit.ADDRESS == 0) && (DecRegs.MFBAHR19.bit.ADDRESS == 0))//if it's program flash 3;
    						{
    							zoiw_flash_key = PROGRAM_FLASH3_INTERLOCK_KEY;
    						}
    						else
    						{
    							return;
    						}
    					}
    					else if(arg1 == 1)//1 means end of second block;
    					{
    						zoiw_address = 0xfff8;
    
    						if((DecRegs.MFBALR1.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR1.bit.ADDRESS == 0)) //here if flash block 0 is at 0x8000
    						//note that the address bits start at bit 10, so 0x20 in the address field equals 0x8000
    						{
    							zoiw_flash_key = PROGRAM_FLASH0_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR17.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR17.bit.ADDRESS == 0))//if it's program flash 1;
    						{
    							zoiw_flash_key = PROGRAM_FLASH1_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR18.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR18.bit.ADDRESS == 0))//if it's program flash 2;
    						{
    							zoiw_flash_key = PROGRAM_FLASH2_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR19.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR19.bit.ADDRESS == 0))//if it's program flash 3;
    						{
    							zoiw_flash_key = PROGRAM_FLASH3_INTERLOCK_KEY;
    						}
    						else
    						{
    							return;
    						}
    					}
    					else if(arg1 == 2) //2 means end of third block in memory, regardless of which block that is;
    					{
    						zoiw_address = 0x17ff8;
    
    						if((DecRegs.MFBALR1.bit.ADDRESS == 0) && (DecRegs.MFBAHR1.bit.ADDRESS == 1)) //here if flash block 0 is at 0x10000
    						{
    							zoiw_flash_key = PROGRAM_FLASH0_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR17.bit.ADDRESS == 0) && (DecRegs.MFBAHR17.bit.ADDRESS == 1))//if it's program flash 1;
    						{
    							zoiw_flash_key = PROGRAM_FLASH1_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR18.bit.ADDRESS == 0) && (DecRegs.MFBAHR18.bit.ADDRESS == 1))//if it's program flash 2;
    						{
    							zoiw_flash_key = PROGRAM_FLASH2_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR19.bit.ADDRESS == 0) && (DecRegs.MFBAHR19.bit.ADDRESS == 1))//if it's program flash 3;
    						{
    							zoiw_flash_key = PROGRAM_FLASH3_INTERLOCK_KEY;
    						}
    						else
    						{
    							return;
    						}
    					}
    					else if(arg1 == 3)//2 means end of fourth block;
    					{
    						zoiw_address = 0x1fff8;
    
    						if((DecRegs.MFBALR1.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR1.bit.ADDRESS == 1)) //here if flash block 0 is at 0x18000
    						//note that the address bits start at bit 10, so 0x20 in the address field equals 0x8000
    						{
    							zoiw_flash_key = PROGRAM_FLASH0_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR17.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR17.bit.ADDRESS == 1))//if it's program flash 1;
    						{
    							zoiw_flash_key = PROGRAM_FLASH1_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR18.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR18.bit.ADDRESS == 1))//if it's program flash 2;
    						{
    							zoiw_flash_key = PROGRAM_FLASH2_INTERLOCK_KEY;
    						}
    						else if((DecRegs.MFBALR19.bit.ADDRESS == 0x20) && (DecRegs.MFBAHR19.bit.ADDRESS == 1))//if it's program flash 3;
    						{
    							zoiw_flash_key = PROGRAM_FLASH3_INTERLOCK_KEY;
    						}
    						else
    						{
    							return;
    						}
    					}
    					else
    					{
    						return; //reject other arg1 values
    					}
    
    					for(counter=0; counter < 32; counter++) //Copy program from PFLASH to RAM
    					{
    						*(program_index++)=*(source_index++);
    					}
    
    					DecRegs.MFBALR1.bit.RONLY = 0; //enable program flash 1 write
    					DecRegs.MFBALR17.bit.RONLY = 0; //enable program flash 2 write
    
    					{
    						register FUNC_PTR func_ptr;
    						func_ptr=(FUNC_PTR)program_area;     //Set function to program area
    						func_ptr();
    
    					}        //execute erase checksum
    
    					DecRegs.MFBALR1.bit.RONLY = 1; //restore it to read only
    					DecRegs.MFBALR17.bit.RONLY = 1; //restore it to read only
    		            SysRegs.SYSECR.bit.RESET = 2;   //now reset processor.
    					break;
    
    	}

    The user checksum addresses are based off Table 13-6 on page 469 of the UCD31xx TRM. See the table for a visual overview of the program flash and user checksum addresses. 

    You can use these addresses to clear and switch between different program flash blocks.

    I presume your application for switching between program flash blocks is for an on-the-fly update. If so, then we do have an example on-the-fly update firmware that I can share, although it is for the UCD3138064 and not the UCD3138128A. Let me know if you are interested and I can send you the files directly.

    Here is an article that walks through general on-the-fly/over-the-air (OTA) update: https://www.electronicproducts.com/on-the-fly-power-supply-firmware-upgrades/?terms=Ian+Bower 

    On-the-fly power supply firmware upgrades.docx

    Here are some other E2E threads that may be useful:

    Regards,

    Jonathan Wong