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: Custimzied pmbus GUI

Part Number: UCD3138
Other Parts Discussed in Thread: UCD9240, UCD90120, UCD7231, TPS40400

Hi Amiel,

With your help, I could have a PMBUS custimized GUI that could be able to communicate UCD3138 device.

But one proplem is that scan device in flash mode will take long time, can you please help me know how to make it faster like you did in device GUI? 

Bellow code is the reference code from fusion api example, it takes about 10 seconds to scan all address.

var sb = new StringBuilder();
// Use this style for most devices supported by Fusion Digital Power Designer
// Examples: UCD9240, UCD90120, UCD7231
int num_devices = PMBusDevice.Discover();

// Another way to call -- only scan the addresses listed; very fast
// int num_devices = PMBusDevice.Discover(75, 126);

// Use this style for select devices that do not support DEVICE_ID
// Examples: TPS40400, TPS4100
// int num_devices = PMBusUtils.Attach_And_Discover(PartID.TPS40400, true);


sb.Append("Found " + num_devices.ToString() + " device on bus...");
Log1(sb.ToString());

Thanks,

Jack

  • Hello Jack,

    If you know the address that you wish to use, you can use that directly like the line below.

    int num_devices = PMBusDevice.Discover(75, 126

    It may be that you have some conditional breakpoints enabled in Visual Studio.  This can explain the slow behavior.  Can you confirm that you are running the code without any breakpoints?  Also for the adapter are you running at 100 khz or 400 khz?  These may be some things to consider.  If you are still having difficulty, let me know the code block that is specifically taking time and I will try to reproduce.  I don't see an obvious reason why it should take that much time.

  • Hi Amiel,

    Here is my C# code, and there is no hardware breakpoint in my Visual studio.

    Actually this code I take this code(https://www.ti.com/lit/zip/slvc460) as reference, it looks that it has the same result with me.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    using TIDP.PMBus;
    
    using TIDP.SAA;
    using TIDP;
    using TIDP.PMBus.Parts.UCD92XX;
    using TIDP.PMBus.Parts.UCD3000;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Runtime.Serialization;
    
    namespace PMBUS_BOOT
    {
        public partial class Form1 : Form
        {
            public static UInt32 pageSize = 0;
            public static UInt32 oldAddress;
            public static UInt32 newAddress;
            public static UInt32 startAddress;
            public static UInt32 endAddress;
            public static UInt16 byteSize = 8; /* defaults are 8 bits */
            public static UInt16[] PFLASH_DATA = new UInt16[0x1000000];
    
            public byte pmbus_addr = 88;
            private TIBusAdapters Adapters = new TIBusAdapters();
    
            public Form1()
            {
                InitializeComponent();
    
                //Wire SAA events that tell us of interesting changes
                Adapters.RequestComplete += new TIBusAdapters.RequestCompleteEventHandler(Adapters_RequestComplete);
                Adapters.Warning += new TIBusAdapters.WarningEventHandler(Adapters_Warning);
                Adapters.ControlLineUpdated += new TIBusAdapters.ControlLineUpdatedEventHandler(Adapters_ControlLineUpdated);
                Adapters.SMBusAlertLineUpdated += new TIBusAdapters.SMBusAlertLineUpdatedEventHandler(Adapters_SMBusAlertLineUpdated);
                Adapters.USBDetached += new TIBusAdapters.USBDetachedEventHandler(Adapters_USBDetached);
                Adapters.USBReattached += new TIBusAdapters.USBReattachedEventHandler(Adapters_USBReattached);
    
                devicDetermination();
            }
    
            // PUBLIC METHODS //////////////////////////////////////////////
    
            // EVENTS I HANDLE /////////////////////////////////////////////
    
            // We do one-time SAA discovery here; you might do this somewhere else
            // in your app (the Fusion GUI has a custom splash screen form shared
            // by all Fusion apps which allows for retry/etc).
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                // This ensures that all SMBusAdapter events get fired on main thread,
                // making for much simpler development
                SMBusAdapter.Run_Events_On_UI_Thread(SynchronizationContext.Current);
                while (true)
                {
                    //find at least one USB adapter
                    if (Adapters.Discover() == 0)
                    {
                        var result = MessageBox.Show("No USB Adapter found. Please check your connection.", "No USB Adapter Found", MessageBoxButtons.RetryCancel);
                        if (result == DialogResult.Cancel)
                        {
                            Close();
                            return;
                        }
                    }
                    else
                    {
                        Log1("Found " + Adapters.Num_Adapters + "USB adapter(s)");
                        break;
                    }
                }
            }
            private void Adapters_USBReattached(TIBusAdapters.USBReattachedEventArgs e)
            {
                Log2("USBReattached: Adapter_Number" + e.Adapter_Number + "; Message=" + e.Message);
            }
    
            private void Adapters_USBDetached(TIBusAdapters.USBDetachedEventArgs e)
            {
                Log2("USBDetached: Adapter_Number" + e.Adapter_Number + "; Message=" + e.Message);
            }
    
            private void Adapters_SMBusAlertLineUpdated(TIBusAdapters.SMBusAlertLineUpdatedEventArgs e)
            {
                Log2("SMBusAlertLineUpdated: Adapter_Number=" + e.Adapter_Number + "; Message=" + e.Message);
            }
    
            private void Adapters_ControlLineUpdated(TIBusAdapters.ControlLineUpdatedEventArgs e)
            {
                Log2("ControlLineUpdated: Adapter_Number=" + e.Adapter_Number + "; Message=" + e.Message);
            }
    
            private void Adapters_Warning(TIBusAdapters.WarningEventArgs e)
            {
                Log2("Warning: Adapter_Number=" + e.Adapter_Number + ": Message=" + e.Message);
            }
    
            private void Adapters_RequestComplete(TIBusAdapters.RequestCompleteEventArgs e)
            {
                Log2("RequestComplete: Adapter_Number=" + e.Adapter_Number + "; Message=" + e.Message + "; Is_Success=" + e.Is_Success);
            }
    
            private void Log1(string msg)
            {
                logCtrlInfo.Add(msg);
            }
    
            private void Log2(string msg)
            {
                logCtrlInfo.Add(msg);
            }
    
            public void devicDetermination()
            {
                try
                {
                    Int32 BootSize = Convert.ToInt32(cBoxBootSize.Text);
    
                    if ((comboBoxDevice.Text == "F280049") || (comboBoxDevice.Text == "F280048") || (comboBoxDevice.Text == "F280045"))
                    {
                        rBtnFlashBank1.Visible = true;
                        rBtnFlashBank2.Visible = true;
                        rBtnBoth.Visible = true;
    
                        if (rBtnFlashBank1.Checked == true)
                        {
                            startAddress = 0x80000;
                            endAddress = 0x8FFFF;
                        }
                        else if (rBtnFlashBank2.Checked == true)
                        {
                            startAddress = 0x90000;
                            endAddress = 0x9FFFF;
                        }
                        else if (rBtnBoth.Checked == true)
                        {
                            startAddress = 0x80000;
                            endAddress = 0x9FFFF;
                        }
                        else
                        {
                            startAddress = 0x80000;
                            endAddress = 0x8FFFF;
                        }
    
                        pageSize = 16;
                        byteSize = 16;
                    }
                    else if ((comboBoxDevice.Text == "F280041") || (comboBoxDevice.Text == "F280040"))
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x80000;
                        endAddress = 0x8FFFF;
    
                        pageSize = 16;
                        byteSize = 16;
                    }
                    else if (comboBoxDevice.Text == "F280025")
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x80000;
                        endAddress = 0x8EFFF;
    
                        pageSize = 16;
                        byteSize = 16;
                    }
                    else if (comboBoxDevice.Text == "F280023")
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x80000;
                        endAddress = 0x87FFF;
    
                        pageSize = 16;
                        byteSize = 16;
                    }
                    else if ((comboBoxDevice.Text == "F280021") || (comboBoxDevice.Text == "F280020"))
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x80000;
                        endAddress = 0x83FFF;
    
                        pageSize = 16;
                        byteSize = 16;
                    }
                    else if ((comboBoxDevice.Text == "F28023") || (comboBoxDevice.Text == "F28027"))
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x3F0000;
                        endAddress = 0x3F7FFF;
                        byteSize = 16;
                    }
                    else if (comboBoxDevice.Text == "UCD3138")
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x0000;
                        endAddress = 0x7FFF;
                        byteSize = 8;
                    }
                    else if (comboBoxDevice.Text == "UCD3138064")
                    {
                        rBtnFlashBank1.Visible = true;
                        rBtnFlashBank2.Visible = true;
                        rBtnBoth.Visible = true;
    
                        if (rBtnFlashBank1.Checked == true)
                        {
                            startAddress = 0x0000;
                            endAddress = 0x7FFF;
                        }
                        else if (rBtnFlashBank2.Checked == true)
                        {
                            startAddress = 0x9000;
                            endAddress = 0xFFFF;
                        }
                        else if (rBtnBoth.Checked == true)
                        {
                            startAddress = 0x0000;
                            endAddress = 0xFFFF;
                        }
                        else
                        {
                            startAddress = 0x80000;
                            endAddress = 0x8FFFF;
                        }
                        byteSize = 8;
                    }
                    else if ((comboBoxDevice.Text == "F28034")||(comboBoxDevice.Text == "F28035"))
                    {
                        rBtnFlashBank1.Visible = false;
                        rBtnFlashBank2.Visible = false;
                        rBtnBoth.Visible = false;
                        startAddress = 0x3E8000;
                        endAddress = 0x3F7F7F;
                        byteSize = 16;
                    }
    
                    startAddress += (UInt32)BootSize * 1024;
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
    
            }
            public void FilledPflashBuff()
            {
                for (UInt32 n = 0; n < PFLASH_DATA.Length; n++)
                {
                    PFLASH_DATA[n] = 0xFFFF;
                }
            }
    
            private void bTbrowse_Click(object sender, EventArgs e)
            {
                try
                {
                    OFDImage.InitialDirectory = System.Environment.CurrentDirectory;
                    OFDImage.Title = "Select firmware files";
    
                    OFDImage.CheckFileExists = true;
                    OFDImage.CheckPathExists = true;
    
                    OFDImage.DefaultExt = "txt";
                    OFDImage.Filter = "Hex files (*.hex)|*.hex|TekHex Files (*.x0)|*.x0|All Files (*.*)|*.*";
                    OFDImage.RestoreDirectory = true;
    
                    OFDImage.ReadOnlyChecked = true;
                    OFDImage.ShowReadOnly = true;
    
                    if (OFDImage.ShowDialog() == DialogResult.OK)
                    {
                        textBoxFilePath.Text = OFDImage.FileName;
    
                        devicDetermination();
    
                        FilledPflashBuff();
    
    
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
    
            private void bTclear_Click(object sender, EventArgs e)
            {
                logCtrlInfo.Clear();
            }
    
            private void llbRomID_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                int AdaperNum = Adapters.Num_Adapters;
    
                var sb = new StringBuilder();
                byte addr = 11;
                byte cmd = 0xEC;
                sb.Append("SAA:BlockRead (Address: "+ addr +"d, Cmd 0x" + cmd.ToString("X2") + "): ");
                var block_result = Adapters.Read_Block(AdaperNum, addr, cmd);
                if (block_result.Success)
                {
                    sb.Append("ACK ");
                    sb.Append(block_result.Block.Hex);
                }
                else
                {
                    sb.Append("NACK ");
                    sb.Append(block_result.ToString());
                }
                Log1(sb.ToString());
            }
    
            private void llbFlashID_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                var sb = new StringBuilder();
                // Use this style for most devices supported by Fusion Digital Power Designer
                // Examples: UCD9240, UCD90120, UCD7231
                int num_devices = PMBusDevice.Discover();
    
                // Another way to call -- only scan the addresses listed; very fast
                // int num_devices = PMBusDevice.Discover(75, 126);
    
                // Use this style for select devices that do not support DEVICE_ID
                // Examples: TPS40400, TPS4100
                // int num_devices = PMBusUtils.Attach_And_Discover(PartID.TPS40400, true);
    
     
                sb.Append("Found " + num_devices.ToString() + " device on bus...");
                Log1(sb.ToString());
    
    #if false
                for (byte addr = 1; addr <= 127; ++addr)
                {
                    if ((addr == 11)||(addr == 12)) { continue; }   //Skip PMBus alert response address
                    var sb = new StringBuilder();
                    sb.Append(addr + ":");
                    var block_result = Adapters.Read_Block(1, addr, 0xFD);
                    if (block_result.Success)
                    {
                        sb.Append(block_result.Block.Hex);
                    }
                    else
                    {
                        sb.Append(block_result.ToString());
                    }
                    Log1(sb.ToString());
                }
    #endif
            }
            private void comboBoxDevice_TextChanged(object sender, EventArgs e)
            {
                devicDetermination();
            }
    
            private void btCopyAll_Click(object sender, EventArgs e)
            {
                //Clipboard.SetText();
                logCtrlInfo.CopyAllToClipboard();
            }
    
            private void btCopySelected_Click(object sender, EventArgs e)
            {
                logCtrlInfo.CopySelectToClipboard();
            }
        }
    }
    

  • Hello Jack,

    I will try and get back to you by Friday latest.

  • Hello Jack,

    I think it is difficult to debug a large piece of code.  I highly suggest that you restrict yourself to a console application as mentioned in the first thread for a custom GUI.  Then those specific lines in the program you are having difficulty with would be more easy to share with me and debug rather than a whole program. 

    When you have UI, now you need to manage the front and back end processes.  The logging on the UI may be a cause of slowing everything down.  Also regarding the speed make sure you SMBusAdapter is running at 400 kHz as that may also be an issue

    SMBusAdapter.Adapter.Set_Bus_Speed(SMBusAdapter.BusSpeed.Speed400KHz);

    You can use the console app to develop your program and then at the end, you can look into adding the UI.  Doing it this way I can help offer Fusion API support more directly as debugging an API with a front end is a lot more involved.

    I have also added a basic Fusion API user guide that talks about some making some simple programs.  FYI when pointing to the assemblies you can point to the ones directly in the bin folder of the latest Fusion Studio installer.  You will need to set the .net framework to 4.5 instead of 4.0.   

    ---------------------------------------------------

    Now having said that, the current GUI does support partial flash download of the pflash.  If you look at the boot options you can either download just a boot, or above the boot.  So in that way it will only pick those locations that are above or part of the boot.  Even though it is called a boot it doesn't need to be treated as a boot flash but can be your partial pflash. So if your partial flash begins at the beginning of the program flash the you can use the boot option.  If it doesn't begin at the start of pflash but ends at the end of a pflash block then you use the above boot option.  If it doesn't begin at the start or end at the end of pflash then you need to proceed with the Fusion API.Fusion API Training.docx

  • Hi Amiel,

    Thanks for your suggestions here, and appreciate sharing this trainning docs with me.

    It looks that you're right, the logging on GUI cause the slowing down. My code will display the ack message one by one in very event handler, after changing code to display all infomation after all discovery finished, it looks it's normal.

    Thanks...

    Jack