Skip to content

BSL430.NET.Library

Jakub Parez edited this page Sep 17, 2019 · 18 revisions

BSL430.NET Library

BSL430.NET is Cross-Platform library serving as MSP430 Toolchain, to Upload, Download and Erase MCU memory, with communication based on generic UART converters like FT232 or Serial port. It uses BSL430.NET.FirmwareTools as aux library to help manage most common firmware formats like Intel-HEX, TI-TXT, SREC and ELF, with ability to Convert, Combine, Create, Parse, Validate and Get BSL password.

Note: This library is recommended to build as x86 or x64, rather than AnyCPU!
      It depends on unmanaged code, that needs to use correct pointer size.

Framework Support

  • .NET Framework 4.6.1
  • .NET Standard 2.0

Communication

Communication with MCU is handled by 4 different ways. FTDI (FT232) is Windows only approach and requires FT2XX drivers installed on target PC. Another approch is called Libftdi and this works on Windows and also Linux, because rather on FT2XX original FTDI drivers it depends on open-sourced alternative libftdfi. Both ways use unmanaged libraries for low-level communication, those libraris are provided in folder lib or just integrated into Win GUI App. Another simple approch is to use standard Serial port (COM) with RS232/UART converter, or the last one, USB with F5xx/F6xx USB enabled MCUs. These 2 ways use managed libraries so you dont need to worry about anything, plus they are also multiplatform.

It is required to connect RST/TEST pins to DTR/RTS according to Wiring Diagram and specific MCU family. These two signals provide special voltage sequence, that forces MCU to start execute BSL bootloader code. In most cases, when MCU has Shared JTAG pins, RST(MCU) is connected to DTR(PC) and TEST(MCU) to RTS(PC). In case of MCU has Dedicated JTAG pins,

Unmanaged comm libs need to be put in right location, to let CLR correctly loads them, please follow .NET P/Invoke guidelines (usually in same folder as executable).

Warning: Old 1xx/2xx/4xx bootloader protocol handle Erase or incorrectly entered 
         password as complete memory wipe including Info A (with calibration data), 
         if LOCK A bit is not set! It is always better to use modern MCUs with 
         5xx/6xx BSL protocol, but if there is no oher way, be careful.

Code Samples

Scan (FTDI)

public ScanResult<FTDI_Device> ScanFTDI()
{
    using (var dev = new BSL430NET(Mode.UART_FTD2XX))
    {
        var scan = dev.Scan<FTDI_Device>();

        Console.WriteLine(scan.Status);
        Console.WriteLine(scan.Devices);

        return scan;
    }
}

Scan (libftdi)

public ScanResult<Libftdi_Device> ScanFTDI()
{
    using (var dev = new BSL430NET(Mode.UART_libftdi))
    {
        var scan = dev.Scan<Libftdi_Device>();

        Console.WriteLine(scan.Status);
        Console.WriteLine(scan.Devices);

        return scan;
    }
}

Scan (USB)

public ScanResult<USB_HID_Device> ScanFTDI()
{
    using (var dev = new BSL430NET(Mode.USB_HID))
    {
        var scan = dev.Scan<USB_HID_Device>();

        Console.WriteLine(scan.Status);
        Console.WriteLine(scan.Devices);

        return scan;
    }
}

Scan (Serial COM)

public ScanResult<Serial_Device> ScanFTDI()
{
    using (var dev = new BSL430NET(Mode.UART_Serial))
    {
        var scan = dev.Scan<Serial_Device>();

        Console.WriteLine(scan.Status);
        Console.WriteLine(scan.Devices);

        return scan;
    }
}

Scan All Devices

public ScanAllResult ScanAll()
{
    using (var dev = new BSL430NET())
    {
        var scan = dev.ScanAllEx<FTDI_Device>();

        Console.WriteLine(scan.FtdiDevices.Status);
        Console.WriteLine(scan.LibftdiDevices.Status);
        Console.WriteLine(scan.UsbDevices.Status);
        Console.WriteLine(scan.SerialDevices.Status);

        Console.WriteLine(scan.FtdiDevices.Devices);
        Console.WriteLine(scan.LibftdiDevices.Devices);
        Console.WriteLine(scan.UsbDevices.Devices);
        Console.WriteLine(scan.SerialDevices.Devices);

        return scan;
    }
}

Upload to MCU

public StatusEx Upload()
{ 
    string FirmwarePath = @"./firmware.hex";           // firmware file path
    string HardcodedDevice = "FTDI1";                  // hardcoded device name
    var DeviceFromScan = new Bsl430NetDevice("COM1");  // device from Scan methods

    // First way with DefaultDevice - default device is entered once into
    // constructor, and then doesnt need to be filled again; the usual way.
    // This example shows upload to 2 different MCUs simultaneously
    using (var dev1 = new BSL430NET(HardcodedDevice))
    using (var dev2 = new BSL430NET(DeviceFromScan))
    {
        // create simple event handler, prints progress (0-100) and report
        var BslEventHandler += new Bsl430NetEventHandler(delegate
            (object s, Bsl430NetEventArgs args)
        {
            Console.WriteLine($"{args.Progress} {args.Report}");
        });

        // assign same event handler for both devices
        dev1.ProgressChanged += BslEventHandler;
        dev2.ProgressChanged += BslEventHandler;

        // dev1 settings, intelliSense described, MCU is the most important
        Status stat1Baud = dev1.SetBaudRate(BaudRate.BAUD_115200);
        Status stat1Mcu = dev1.SetMCU(MCU.MSP430_F5XX);
        Status stat1Invoke = dev1.SetInvokeMechanism(InvokeMechanism.SHARED_JTAG);

        // dev2 settings
        Status stat2Baud = dev2.SetBaudRate(BaudRate.BAUD_9600);
        Status stat2Mcu = dev2.SetMCU(MCU.MSP430_FR6xx);
        Status stat2Invoke = dev2.SetInvokeMechanism(InvokeMechanism.DEDICATED_JTAG);

        // Run Upload of single firmware to 2 MCUs, BSL password is not needed,
        // as Mass Erase is executed first, clearing memory. Only beware when
        // 1xx/2xx/4xx old MCU is used, Mass Erase could wipe also Info A with 
        // calibration data. This is not case of modern 5xx/6xx MCUs, however
        // if you dont want to clear memory first, you must supply BSL password
        var result1 = Task.FromResult<StatusEx>(dev1.Upload(FirmwarePath));
        var result2 = await Task.FromResult<StatusEx>(dev2.Upload(FirmwarePath));
        
        Console.WriteLine($Dev1: "{result1.ToString()}");
        Console.WriteLine($Dev2: "{result2.ToString()}");
    }
}

Download from MCU

public StatusEx Download(string FirmwasssssssrePath)
{

}

Erase MCU

public StatusEx Erase()
{

}
Clone this wiki locally