parezj / BSL430.NET

TI MSP430 Bootloader (BSL) .NET Cross-Platform Toolchain & Firmware Tools. The cheapest way to flash MSP430, with FTDI/Serial/UART converters. Intel-HEX, TI-TXT, ELF and SREC firmware format support, can also convert, combine, hex-edit..
MIT License
42 stars 10 forks source link

Some bugs for uploading code to MSP430G2553 #1

Open weihsiangteng opened 4 years ago

weihsiangteng commented 4 years ago

I found some bugs in protocol 1xx, 2xx and 4xx families using your console program. This will fail password checking also uploading code to msp430g2553. After I modified some codes then it worked. Following are my modifications:

Main_priv.cs:

  1. case Command.Password:  // address: -   data: D1 ... D20
    {
        BSL_frame.Add(Const.BSL_CMD124__RX_PASSWORD);  // typo?
        BSL_frame.AddRange(Enumerable.Repeat(Const.BSL_DATA124__PW_L1_L2, 2).ToArray());
        BSL_frame.AddRange(Enumerable.Repeat(Const.BSL_DATA124__DUMMY, 4).ToArray());
    
        if ((data == null || data.Length != Const.BSL_SIZE124__PASSWORD))
        {
            message.status = Utils.StatusCreate(801);
            return message;
        }
        BSL_frame.AddRange(data);
    }
    break;
  2. RX data block BSL command should take n-4 bytes:

    case Command.Upload:  // address: AL, AH   data: D1 ... Dn-4
    {
        BSL_frame.Add(Const.BSL_CMD124__RX_DATA_BLOCK);
        BSL_frame.AddRange(Enumerable.Repeat((byte)(data.Length + 4), 2).ToArray());
    
        if ((address == null) || (data == null || data.Length < 1))
        {
            message.status = Utils.StatusCreate(801);
            return message;
        }
        BSL_frame.AddRange(_address.ToArray());
        BSL_frame.Add((byte)(data.Length));
        BSL_frame.Add(0);
        BSL_frame.AddRange(data);
    }
    break;
  3. case Command.Upload:
    {
        Debug.Assert(typeof(T) == typeof(Data_Void));
        //throw new BSL430Exception(460, "Result<Data_Void> res = msg(Command.*)");
        result.data = (T)(object)new Data_Void();
        ok = (answer.data.Length == 1 && answer.data[0] == Const.BSL_GENERAL124__ACK);   // another typo?
    }
    break;
  4. In ParseFirmware function, the variable fill_FF should be true for TI text format?

Constants.cs

// BSL RX SIZE - PROTOCOL 1xx 2xx 4xx
public const byte BSL_SIZE124__PASSWORD = 32;

Thank you for providing this awesome software so that I can flash my msp430g2553!

parezj commented 4 years ago

Thank you very much for correcting this issue! fill_FF is usually not needed for Uploading code to MCU, because users dont enter valid BSL password, and therefore Mass Erase is executed prior to Upload. If you know BSL password and want to upload only INFO A code, also you dont need fill_FF. It is usefull for CRC calculation and other FirmwareTools specific stuff.

Warning: Password is optional for Download, but if wrong password is entered, MCU takes it as an attack and erase all memory, executing Mass Erase. If modern 5xx/6xx micro is used, code is just wiped, but if old 1xx/2xx/4xx one is used and LOCK A bit is not set, also Info A mem is wiped, with factory calibration data. So please be careful.

I will push your changes into main line, thank you.