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

Thread: How does the upload actually work?

  1. #1
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415

    Question How does the upload actually work?

    I just received my teensy 3.0, it's fantastic. I'm really impressed by the completeness and features; it's going to make at least one of my projects an order of magnitude simpler.

    Because I can't stand not knowing things, I'm trying to wrap my head around how it actually works. I've been digging through the schematics and data sheets and from what I can tell teensyduino has a basic initialization wrapper for the ARM stuff in mk20dx128.c but there's no hooks for reprogramming etc. in the Arduino-fied MK20 code itself?

    From what I can tell when you press the 'program' button the mini54 resets the MK20 and looks like it's doing something with JTAG? ...uploading code to erase the flash, read data from USB and write that to flash, then reboot the MK20? If so, what doe the pins on PTB2 and PTB3 do? Are you sending something between the chips via I2C? Also, why does PTA3 need two mini54 pins (P0.5 and P0.6)?

    I apologize if this is already documented somewhere else, or if you consider this proprietary information and don't want to reveal it publicly.

    Thanks again for a great product, I think I'm going to have to order boards #2 and 3 in a few days because this first one is already working out better than I'd hoped.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,212
    In a nutshell, when you press the button, the Mini54 resets the MK20 and copies a tiny bootloader program into its RAM.

    The MK20 lacks a hardware bootloader feature similar to the AVR chip. It can't reassign the boot address and interrupt vectors like AVR can. The ARM does have a vector reassign feature, but it works differently than AVR. The MK20 does have some provision for permanently preventing writes to sections of the flash memory, but it just isn't similar enough to AVR. This 2-chip design allows good compatibility with Arduino on the MK20 chip which lacks the specific AVR hardware features that are really the foundation of Arduino.

    The other nice advantage is your code can use the entire flash memory on the MK20.

    PTB2 and PTB3 are currently not used. Early on, I thought it might be necessary to have the chips communicate with each other using I2C, but that capability was never actually needed. Someday a future version might implement some way for one board to reprogram another using the I2C lines, but at this point it seems unlikely that will happen anytime soon, if ever.

    P0.6 on the Mini54 is not used. P0.5 does everything with PTA3 and P0.6 is configured as a high impedance input that is never used in any way. Those 2 pins are the MOSI and MISO pins on the Mini54's SPI port, but the idea to use SPI was not used. The Mini54 does everything by just manipulating the pins with normal I/O.

    Some of the finer details really are proprietary information, but hopefully this gives you some better understanding?

  3. #3
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    1,027
    Hi Paul,
    this got me thinking, if you ever update the firmware for the mini54 is there a way to load it on to the min54? or would we have to buy a new teensy?

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Location
    Torrance CA
    Posts
    415
    Thanks for the information; very helpful. This is an impressive hardware hack, and I mean that in the best sense of the word.

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Sorry for necro-posting, but I have a related question...

    I would like the option of re-programming the teensy3.0 in-circuit without having to press a button. I'd rather be able to have a software event jump to a location or send a signal to enter the bootloader.

    I would simply tie a digital output pin to the "Program" pin, but this is fraught with issues. I am about to build a 555 one-shot timer and trigger it with a digital pin write.

    Can anyone give me a better idea?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,212
    Quote Originally Posted by jspark311 View Post
    Can anyone give me a better idea?
    Call the _reboot_Teensyduino_() function. It does not return...

    The specific mechanism may change slightly in future versions, so I highly recommend you call this function rather than copy its asm code directly.

  7. #7
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Thank you! That was exactly what I needed!
    Is there a similar call to reboot normally? IE, to restart the program?

    I really like the teensy3.

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Posts
    18
    Is the Mini54 chip needed everytime the Teensy receives power, or is it only necessary for reprogramming the MK20 chip?

    If it is the latter, should it not be possible to expose the relevant MK20 pins to a header and then design a separate "flasher" board with the Mini54 chip that hooks onto those exposed pins on the MK20's PCB? I ask this because I do not want to bundle the flashing capability on my boards unless the buyer specifically asks for it, at which point the warranty would be void for any software issues. The buyer can simply order the flasher board which would have USB on one side and the relevant pins on the other side that plug into my MK20 board for flashing.

    Thanks!

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,212
    The Mini54 is only needed for reprogramming.

  10. #10
    Junior Member
    Join Date
    Jul 2013
    Posts
    9
    Ok... I've made substantial progress on my project. And now I have another question regarding upload.

    Background: I would like to deploy my Teensy3 project paired with a Raspberry Pi. The two devices will be integrated into an environment where it will be a nusince to connect a development PC to the Teensy in order to reprogram it (for bug-fixes, new capabilities).

    Questions: Is there a "kernel" for the uploading program that I could install without GUI support that would allow me to flash the Teensy from the RasPi? If not, is it as simple as detecting a certain VID:PID USB device, and then sending it the hex file? I'm hoping all your proprietary technique is self-contained on the Teensy PCB, as I'd like to write an uploader.

    Thank you for taking the time to address everyone's questions. :-)

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,212
    as I'd like to write an uploader.
    Here's source code to get you started. Only the Linux part has been updated for Teensy3.

    http://www.pjrc.com/teensy/beta/load_linux_only.c

  12. #12

Posting Permissions

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