Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 21 of 21

Thread: Wireless (remote) programming of Teensy 3.0?

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    5

    Wireless (remote) programming of Teensy 3.0?

    I'd like to be able to wirelessly (using XBee's) program my Teensy 3.0 - similar to what the AdaFruit tutorial describes here for Arduino's. The idea is to have an LED display outdoors that I can update periodically without going outside, pulling the board, re-programming inside, then redeploying outside. (I did that all last Christmas season... in the rain... )

    I've done it with an Arduino Duemilanove but I'm not sure how to attack the problem with a Teensy 3.0. Specific questions: Does the Teensy reset pin work similarly to the Arduino Duemilanove (pulling it low causes a reset)? After reset, does the bootloader wait for code, just like the Arduino, for a period of time? Can I send code in over one of the serial pins (seems like the answer to that might be no)?

    Anybody tried it? Any pointers or direction on what I should try?

    Thanks,

    Erik

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,300
    Teensy programming is only by USB. Serial-based programming isn't supported, so this approach can't work.

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    5

    Alternate approaches?

    Quote Originally Posted by PaulStoffregen View Post
    Teensy programming is only by USB. Serial-based programming isn't supported, so this approach can't work.
    Thanks Paul, I kind of suspected that. I love my Teensy and would really like to find some way to upload code remotely. Any ideas for alternate approaches? I'm willing to do some work.

    Since I talk to the XBee via USB on the computer side using this, perhaps there's a way to get the receiving side to do the opposite and take the serial XBee data and convert to USB to send to the Teensy? (clearly not my area of expertise)

    Thanks,

    Erik

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    Montréal
    Posts
    462
    While not the ideal solution, for 35$ + 10 $ for a wifi adapter you can get a rapberry pi and connect it to your Teensy to reprogram it remotely.
    I've been using this with a couple of Arduinos and it works like a charm !

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,300
    This request has come up several times... so I'm considering what I might be able to do on a future version. It will require the bootloader in the Mini54 chip to also listen on a serial port, probably Serial3. One side-effect of activating Serial3 would be the TX3 pin will become an output while programming, which could be a pretty substantial issue for people using that pin for other stuff. There probably needs to be some way to not enable the serial transmit pin unless absolutely necessary. Another issue would be how to enter bootloader mode. Maybe one of the XBee pins would need to be wired to the PROG pin to initiate loader mode? These and other issues would need to be figured out pretty well before I could even attempt a new version of Teensy with support for this type of wireless reprogramming.

  6. #6
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    Quote Originally Posted by nlecaude View Post
    While not the ideal solution, for 35$ + 10 $ for a wifi adapter you can get a rapberry pi and connect it to your Teensy to reprogram it remotely.
    I've been using this with a couple of Arduinos and it works like a charm !
    nlecaude - Now that's a creative approach. Seems funny to deploy a whole raspberry pi just to get remote programming but sometimes you do what you have to do! Can you point me to any info on how people have done this (even if it's with an Arduino)?

    Thanks.

  7. #7
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    I'm assuming I'd be able to enter bootloader mode by taking the reset pin low using the same circuit that the Adafruit tutorial uses. True? I can't find what the PROG pin does but based on your question, I'm guessing it does something similar or perhaps needs to be held low while programming?

  8. #8
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Where does this stand? We have a project that will have 84 Teensy's and they will be hard to get to for repropramming after they are installed. Currently planning on RS485 comm for interaction and would love to be able to use that in some fashion to load/modify code.

  9. #9
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    On an ARM7, I wrote a secondary loader (SL) that downloaded updates to config data and/or new code, in .hex form, wirelessly. The SL was stored in a portion (sector) of flash. The app code was stored in other sectors. The SL erased the app's sectors as needed. Allowed for unattended updates and status reporting remotely.

    I did an in-place flash rewrite with automatic unattended restart on comms error - because the downloaded code was larger than RAM and there was no mass storage like an SD card.

    The bug-a-boo:
    If I recall correctly, there's a constraint (?) with the Freescale (or Teensy's loader) where to write any portion of flash, one must first erase all of flash and that would include the area where an SL is installed. I suppose the SL could be coded in position independent code (a compiler option?) and copied to RAM before erasing and re-writing flash as the download progresses. The SL could rewrite itself from RAM back to flash if need be. And so on. The trick is to make this bullet-proof to comms errors. In my case, that was essential in order to not get on airplanes to many sites.
    Last edited by stevech; 01-30-2014 at 10:36 PM.

  10. #10
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    633
    How about programming the Teensy with an interpreter? You would be able to update the behavior by transmitting new code in the form of a sequence of byte codes, a table, or a script.

    There's a bunch of interpreters here: http://www.pjrc.com/teensy/languages.html

    My Morse code PDA has a very simple interpreter with a command line interface.

    It's really easy to write your own. Here's a rough sketch:

    Code:
    while (1) {
        cmd = get_next_command();
        switch (cmd) {
            case LIGHT1_ON: digitalWrite(LIGHT1, HIGH); break
            case LIGHT1_OFF: ...
            ...
            case LOAD_PROGRAM: ...
        }
    }

  11. #11
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    I ended up deploying a Raspberry Pi with my Teensy as nlecaude suggested. Works well for my application although it's a pricey solution.

  12. #12
    Junior Member
    Join Date
    Mar 2015
    Posts
    2
    Sorry to resurrect an old thread... I would be really keen to be able to program the teensy via a uart, instead of the usb. I'd like to put in a Bluetooth LE module, and have it reprogram the board so that you can reprogram it from an iPad app.

  13. #13
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,792
    As was noted above the 'unbrickable' architecture used for the Teensy constrains it to programming via USB. There are a range of AVR based solutions that natively support wireless re-programing but at this time nobody has invested the major effort to find a 100% reliable method, redesign the boards to maintain compatibility and then rebuild the ARM bootloader to make this all happen on a Teensy.

    None of the above is impossible and hopefully will show up in some future design but it's not something that will magically pop up as a software patch for your existing boards as far as I understand things.

  14. #14
    Junior Member
    Join Date
    Mar 2015
    Posts
    2
    Hi, thanks for responding. I need to use something as powerful as the Cortex-M4, but as I've done more research I've realised that reprogramming the device as frequently as my application would require would be detrimental to the lifetime of the chip. I'm trying to build a field-programmable audio effect processor. I'm looking into how possible it would be to write a small kernel to handle I/O, but load DSP programs from an external SRAM chip or something. I'll post a new thread about that though.

  15. #15
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    I vote for Teensy's bootloader to optionally avoid erasing n high-address flash sectors (excluding the one used for non-volatile data), and run code in that area if present, at power-up.

    So as to not burden PJRC, the user community would put various bootloader types there - using whatever medium to do the non-USB download. Such as various wireless radios, CAN, SPI, I2C.
    Or simpler and better and as others do, have a $1 SPI Flash memory chip as a piggy-back board and this secondary bootloader would get the new main program from that and flash it. That way, the download medium that got and wrote new code to the SPI flash can be user-specific - i.e., the download and write-to-SPI flash is a user app, not part of a bootloader. The bootloader would always look to see if new code is in flash. I and others have code for this scenario.

    Perhaps there has to be a white-list (registered CRCs?) of who authored what code that goes in that space, as an anti-counterfeit strategy for PJRC's protection.

    PS: There are other-brand M4s with a ROM bootloader that auto-detects download attempts via USB/DFU, UART, CAN, SPI, etc. This code space could also accommodate a wireless downloader for a variety of radio types. But not K20s, I suppose.
    Last edited by stevech; 03-06-2015 at 05:01 PM.

  16. #16
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    2,785
    Given the Teensy can run instructions that are located in normal read/write memory, an alternative to rewriting the whole flash occurs to me is to use a fixed area of memory to run your dynamic code from. You would download the code to this memory, and jump to it. Because you don't have the whole infrastructure for shared libraries, you would have to setup a class that has function pointers or virtual functions for each of the functions that the dynamic function can call, and pointers for the structures.

    You would have an agreed upon entry point that contains a jump to the actual function to start at, and that function would be passed the pointer to the above class to use. Because read/write memory is not saved across calls, I would suspect you would want to include an EEPROM memory chip or a micro SD card to hold the instructions, and at power up, the static portion of the code would read the instructions into the buffer and jump to it.

    Then in your code, you would have a bluetooth chip that you check if there is any data. If there is data, you then read from the bluetooth device and save the bytes to your permanent storage area. When you have the full data, you would then read it into memory and call it with the class pointer. For safety's sake, I would have two areas in the EEPROM/sd card, and an indication which bank to use. When you are reading the bytes, you would write to the alternative bank, and once you have a complete image transferred, then update the bank pointer, and restart (so if the transmission drops, you can still run from the last good image). Perhaps having a third bank that is the initial code, that is used when a switch is set when you reboot.

    Obviously, you would have to do the developing of this code outside of the Arduino IDE, and you will have to write your own linker scripts to put stuff in the right location, etc.

  17. #17
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,508
    I have some code, it reads from SD-card, flashes it to the upper half of flashmem, and then i a second step it copies the the upper half to the lower half and then resets the teensy.
    Tested only with 3.1 and it's only a "study" so far, but it works good for me. The main code can be changed to use an other source than SD-card. Serial for example. And of course it can be changed to use an other buffer, SPI-Flash or SPI-RAM.
    IT's NOT for beginners, because there is a risk that you brick your teensy if you do not know what you do. If you want to look at it, it's at my github-account. But please do not complain if you successfully bricked your teensy :-)
    Last edited by Frank B; 03-06-2015 at 07:53 PM.

  18. #18
    Quote Originally Posted by nlecaude View Post
    While not the ideal solution, for 35$ + 10 $ for a wifi adapter you can get a rapberry pi and connect it to your Teensy to reprogram it remotely.
    I've been using this with a couple of Arduinos and it works like a charm !
    Hi,

    I have this same problem, and would love to solve it - even at the cost of an additional $45. Can you please point me to any documentation on this method?

    I'm a reasonably competent EE & programmer, but I have never dealt with the Raspberry world

    TIA,

    Frank

  19. #19
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,735
    RPI programs teensy over USB, but I heard the programming is very slow

  20. #20
    So, the Raspberry Pi becomes the USB host for the Teensy - is that the idea?

    TIA,

    Frank

  21. #21
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,735
    Thats what I heard, I'm gathering you wifi to the RPI to basically remote upload the file to it's file server, then use the teensy command line tool on RPI to upload the HEX over USB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •