Beispiel #1
0
        private void cmdMCUReset_Click(object sender, EventArgs e)
        {
            /* get port name */
            string pName = (string)cbPorts.SelectedItem;
            /* get baud rate */
            uint bauds = uint.Parse((string)cbBauds.SelectedItem);

            if (pName == null || pName == "")
            {
                return;
            }

            var uc = new STBoot();

            /* open device */
            uc.Open(portName, baudRate);

            /*Reset the chip via RTS and DTR --> DTR-Signal must be INVERTED!*/
            uc.STM32ResetChip();

            uc.Close();
        }
Beispiel #2
0
        /* upload a binary image to uC */
        private async Task UploadFile(string portName, uint baudRate,
                                      byte[] bin, uint address, uint jumpAddress)
        {
            /* get page size */
            uint psize = uint.Parse(cbPSize.SelectedItem as string);

            /* create new programming interface object */
            using (var uc = new STBoot()) {
                /* open device */
                uc.Open(portName, baudRate);

                /*Reset the chip via RTS and DTR --> DTR-Signal must be INVERTED!*/
                uc.STM32InitBoot();

                /* initialize communication */
                await uc.Initialize();

                /* update the status */
                UpdateStatus(false, string.Format("Connected: Ver: {0}, PID: 0x{1:X4}",
                                                  uc.Version, uc.ProductID));
                /* give some chance see the message */
                await Task.Delay(500);

                /* apply new message */
                UpdateStatus(false, "Erasing...");

                /* checked? */
                if (cbxErase.Checked)
                {
                    await uc.GlobalErase();
                }
                else
                {
                    /* erase operation */
                    for (uint i = 0; i < bin.Length; i += psize)
                    {
                        /* erase page */
                        await uc.ErasePage((i + address - 0x08000000) / psize);

                        /* update progress bar */
                        UpdateProgress((int)i * 100 / bin.Length);
                    }
                }

                /* apply new message */
                UpdateStatus(false, "Programming...");
                /* progress reporter */
                var p = new Progress <STBootProgress>(UpdateProgress);
                /* write memory */
                await uc.WriteMemory(address, bin, 0, bin.Length, p,
                                     CancellationToken.None);

                /* update the status */
                UpdateStatus(false, string.Format("Success: {0} bytes written",
                                                  bin.Length));

                /* go! */
                await uc.Jump(jumpAddress);

                /*Reset the device in normal mode*/
                uc.STM32ResetChip();

                /* end communication */
                uc.Close();
            }
        }