Firmware loader for Teensy 3

Status
Not open for further replies.
If what you want to do is load firmware without access to the USB port, have a look at this thread. I tried it about a year ago and was able to install an update via a hardware serial port. I only tested the process "manually", i.e. using a terminal emulator to send the specified commands and then to send the file containing the new firmware. I never got around to automating it. The basic idea is that your application must fit in less than half of flash space, so the other half is available to install an update. If you use that thread as your starting point and switch to that thread for discussion, there probably will be others who have gone further than I did.

Joe

https://forum.pjrc.com/threads/29607-Over-the-air-updates
 
take the teensyload_cli source code and build your own SW, CLI or GUI as you wish

Absolutely..that's likely to be the plan...but you have to bear in mind I'm no expert...infact barely litterate in terms of creating applications for actual computers. Though I was pretty nifty on the Atari STe and the Commmodore PET. :D
 
If what you want to do is load firmware without access to the USB port, have a look at this thread. I tried it about a year ago and was able to install an update via a hardware serial port. I only tested the process "manually", i.e. using a terminal emulator to send the specified commands and then to send the file containing the new firmware. I never got around to automating it. The basic idea is that your application must fit in less than half of flash space, so the other half is available to install an update. If you use that thread as your starting point and switch to that thread for discussion, there probably will be others who have gone further than I did.

Joe

https://forum.pjrc.com/threads/29607-Over-the-air-updates

Thanks, I will have a good look through that thread,

I really just want to offer a firmware updater for my product that works on Linux, OSX and Win. Something that people can download and click on then it updates the firmware in their attached device. There is a Teensy 3.6 in the unit itselfand it connects to the computer VIA USB so it's already ideal for just flashing.It would be nioce to have a fancy GUI but I'm not sure that is in my skillset yet.
 
At least for windows you can have a look here https://github.com/luni64/TeensySharp The purpose of the library is to provide firmware download capability for user applications. You can of course use it to program a fancy stand alone FW uploader as well.

Usage is quite simple. Basically you create an empty firmware image for your board and parse a Hex file into it:
Code:
var Board = PJRC_Board.Teensy_31; 
var FlashImage = SharpUploader.GetEmptyFlashImage(Board);
SharpHexParser.ParseStream(File.OpenText("firmware.hex"), FlashImage);

Then you start the Bootloader (HalfKay) on the Teensy and download the prepared image by calling
Code:
USB_Device Teensy = Watcher.ConnectedDevices.FirstOrDefault();
SharpUploader.StartHalfKay(Teensy.Serialnumber);
int result = SharpUploader.Upload(FlashImage, Board, Teensy.Serialnumber, reboot: true);

A complete example can be found in the linked repository
 
At least for windows you can have a look here https://github.com/luni64/TeensySharp The purpose of the library is to provide firmware download capability for user applications. You can of course use it to program a fancy stand alone FW uploader as well.

Usage is quite simple. Basically you create an empty firmware image for your board and parse a Hex file into it:
Code:
var Board = PJRC_Board.Teensy_31; 
var FlashImage = SharpUploader.GetEmptyFlashImage(Board);
SharpHexParser.ParseStream(File.OpenText("firmware.hex"), FlashImage);

Then you start the Bootloader (HalfKay) on the Teensy and download the prepared image by calling
Code:
USB_Device Teensy = Watcher.ConnectedDevices.FirstOrDefault();
SharpUploader.StartHalfKay(Teensy.Serialnumber);
int result = SharpUploader.Upload(FlashImage, Board, Teensy.Serialnumber, reboot: true);

A complete example can be found in the linked repository

This looks VERY VERY promising. Thank you so much. I'll see what I can do.
 
FW loader using Raspberry Pi and Python?

Also I am interested again. We have a commercial product using T3.2 and in the manufacturing process need to load test code. A great solution would be a Raspberry Pi which could load the code automatically and blink some lights or have a small touchscreen as a simple go/no go GUI. I have that hardware on hand and will be looking at doing this. If I can make some progress I will post a github link. On the Pi I am thinking of using Python which would be some more incentive to finally learn a bit of that. Anyone with ideas or who wants to collaborate please let me know...
 
At least in the past, the trouble with using the Rasberry Pi was the Raspberry Pi you would typically want to use (Raspberry Pi Zero or Raspberry Pi Zero W) from a size, cost, and power usage was hard to get in sufficient quantities for commercial usage.

Some places like newark/element14 don't carry the Pi Zero, others like digi-key charge much higher prices for the Zero, while others like Adafruit, Sparkfun, Pi-supply, and Micro Center limit you to 1 Pi Zero per customer (for the stripped down $10 board only price). I believe the reason is it probably costs more than $5 or $10 to make and distribute the Pi Zero, but the Raspberry Pi Foundation wanted something cheap for hackers to use. But if you are on the commercial side of things, you need to plan for a higher cost to embed the Pi Zero or Pi Zero W's or step up to the Pi 1/2/3/4's.
 
This looks VERY VERY promising. Thank you so much. I'll see what I can do.

Just for fun I added a quick example "firmware uploader" to the TeensySharp repo. It is a simple WPF app and can easily be styled in any way you like. Since it is just an example, I didn't bother for MVVM or some other fancy programming model. It handles hot plugging of boards and verifies that the firmware and the board type are compatible before uploading.

The required code is quite simple:

Code:
using Microsoft.Win32;
using System.Windows;
using TeensySharp;
using System.IO;

namespace WpfDownload
{
    public partial class MainWindow : Window
    {
        TeensyWatcher watcher;

        public MainWindow()
        {
            InitializeComponent();
            watcher = new TeensyWatcher();

            // fill board list with connected boards
            foreach (var teensy in watcher.ConnectedDevices)
            {
                cbTeensy.Items.Add(teensy);
            }
            cbTeensy.SelectedIndex = 0;

            watcher.ConnectionChanged += OnBoardPlugged; // event handler
        }

        // Handle life hot plugging of boards -------------------------------------------------
        private void OnBoardPlugged(object sender, ConnectionChangedEventArgs e)
        {
            var board = e.changedDevice;
            if (e.changeType == TeensyWatcher.ChangeType.add)
            {
                Dispatcher.Invoke(() =>              // we can not access GUI thread directly from event handler, use dispatcher instead
                {
                    cbTeensy.Items.Add(board);                    
                    cbTeensy.SelectedItem = board;
                });
            }
            else if (e.changeType == TeensyWatcher.ChangeType.remove)
            {
                Dispatcher.Invoke(() =>             // we can not access GUI tread directly from event handler, use dispatcher instead
                {
                    cbTeensy.Items.Remove(board);
                    cbTeensy.SelectedIndex = 0;
                });
            }
        }

        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == true)
            {
                tbFirmware.Text = dlg.FileName;
            }
        }

        private void Download_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(tbFirmware.Text))
            {
                MessageBox.Show("Firmware file not found!");
                return;
            }

            var board = cbTeensy.SelectedItem as USB_Device;
            var image = SharpUploader.GetEmptyFlashImage(board.Board);

            using (var stream = File.OpenText(tbFirmware.Text))
            {
                SharpHexParser.ParseStream(stream, image);
            }

            var fwType = SharpHexParser.IdentifyModel(image);
            if (fwType != board.Board)
            {
                MessageBox.Show("Firmware not compatible with Board");
                return;
            }

            SharpUploader.StartHalfKay(board.Serialnumber);
            int result = SharpUploader.Upload(image, board.Board, board.Serialnumber);

            if (result != 0)
            {
                MessageBox.Show("Error uploading board");
            }
        }
    }
}


Here a screenshot (the fancy styling is just a picture which was lying around ;) )
downloader.png
 
Can you guys clarify for me whether the solutions you're talking about now all rely on the USB port and Paul's bootloader on the Teensy? What I'm interested in is being able to update the Teensy through a hardware UART connection, bypassing the USB and secondary ARM processor. I know there are limitations, but my applications generally would have only UART connections.
 
If you refer to the TeensySharp library that uploads via USB port and the bootloader chip on the Teensy.
 
Status
Not open for further replies.
Back
Top