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

Thread: Basic question about creating custom Teensy

  1. #1
    Junior Member
    Join Date
    Jul 2016
    Posts
    12

    Basic question about creating custom Teensy

    Hello, forgive my ignorance, but I have a pretty basic question about creating my own custom Teensy.

    Just as a starter; I've created a great deal of PCBs before. Not an expert, but not totally inexperienced either. I made my own custom functional custom Netduino (http://forums.netduino.com/index.php...er-netduino-2/) a little while back. In my current project I've got a custom PCB working which has a socket for an original Teensy 3.2. I want to change my PCB to incorporate custom Teensy directly.

    Reading on the forums I see that people who make their own custom Teensy's have to get a pre-loaded bootloader chip from Paul to get it working. And that is where my question comes in. Is that absolutely neccesary? The chip is rather expensive, and it'll take time to ship to Norway. I was hoping I would be able to build the custom Teensy without having to reply on a specific "magic" chip from Paul.

    Is there any way around this, so that I can create my custom Teensy just using standard parts?

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,924
    I think the short answer is - without the custom chip - it isn't a Teensy. That chip facilitates the tested environment that is 'PJRC Teensy' and gives access to the programming process and tools that PJRC supports. There are threads about aspects of this that will give real details.

  3. #3
    Junior Member
    Join Date
    Jul 2016
    Posts
    12
    Thanks for your answer. I've been using the Teensy for a couple of years now, but as far as I know I haven't really used anything really Teensy-specific. In fact I'm not sure what software-features the Teensy actually has that regular Arduino has not got. My reason for using the Teensy has been the form-factor, and CPU speed. For the most part I'm just using regular GPIO's, I2C and PWM. Maybe Teensy is overkill for my need...?

    Another naive question then - if I drop the bootloader, would I then be able to use the rest of the design as a more "standard" Arduino? Perhaps I should go for creating just a custom version of one of the regular Arduino's?

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    I use the Segger J-link EDU to program the MK20 over JTAG.
    There are some serial bootloaders floating around that you can then use to program the device from the pc (or other device) from that stage forth

    If you give us some information on the project we can probably give you better advice
    Last edited by Xenoamor; 07-15-2016 at 08:17 PM.

  5. #5
    Junior Member
    Join Date
    Jul 2016
    Posts
    12
    Sure, let me explain my project.

    Click image for larger version. 

Name:	2016-07-15 22.31.29.jpg 
Views:	146 
Size:	145.6 KB 
ID:	7634

    I've made this PCB. It is just a prototype for now. It has a Bluetooth device, a Wi-Fi device (haven't decided which of the two I'm going to use in the end product, so I'm testing both), a current sensor, an accelerometer and compass, and a I2C multiplexer. And a big chunk of Teensy in the middle of it.

    Here is the board after the Teensy is added.

    Click image for larger version. 

Name:	2016-07-15 23.18.53.jpg 
Views:	225 
Size:	130.0 KB 
ID:	7635

    As you can see the Teensy becomes a substantial part in the center.

    So, my thought is to rather than use an external Teensy, incorporate the Teensy (or similar) into my PCB. And that's when I started searching the forums, and found all the discussions about the bootloader chip.

    It doesn't really have to be a Teensy, any capable microcontroller could probably be used. The Arduino code (currently) doesn't have any intricate code. Its mostly digitalRead/digitalWrite, I2C and PWM stuff.

  6. #6
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Nordic Semiconductor do a range of SoC bluetooth devices. Have a look at the RFduino for example
    The ESP8266 is the same sort of thing but WiFi. It can also be programmed from the Arduino enviroment
    Both are very compact and are available in small boards if you don't wish to make your own

    Why do you have an I2C multiplexer...? Isn't the whole purpose of I2C to allow you to have many devices on the same bus?

  7. #7
    Junior Member
    Join Date
    Jul 2016
    Posts
    12
    I do wish to create my own That is most of the reason why I'm doing this.

    I'm happy with the Teensy, and the only reason to throw it out would be if I could get everything integrated on my custom PCB. I'm not looking for a replacement for Teensy if that requires me to still have my board+some external board.

    See the tree headers on the left side? Well, there are actually eight of them, all for connecting I2C IR sensors. All the IR sensors unfortunately have the same I2C address, and thats why I have to multiplex between each of them.

    So, back to the main topic. How to integrate Teensy (or similar microcontroller) on my PCB when I'm reluctant to buy the "magic" pre-loaded bootloader chip?

  8. #8
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    Just stick the same microcontroller on the board and bring out the JTAG pins. Then use a Segger J-Link to program the hex file in

  9. #9
    Junior Member
    Join Date
    Jul 2016
    Posts
    12
    I haven't really worked at that level before. I've just used Arduino software when programming my boards, but I'm very interrested in expanding my horizon. (I'm a professional software developer, but that is mostly C# and some C++).

    When using Segger J-Link to program "the hex file", is that something you do one time to get things up and running, or is that how you you make every program change? And what software do you use? You mention "the hex file". Do you mean a specific hex file, or one that I create that represents my program?

  10. #10
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    Quote Originally Posted by Scalpel78 View Post
    I haven't really worked at that level before.
    And that's why you pay for the bootloader chip. It allows you to use the MK20 chip right out of the Arduino IDE. The Teensy hardware itself isn't that special, it's the environment integration, software support and hardware abstraction that makes Teensy a Teensy. You can just use a MK20 without the bootloader chip, but then you have to get your hands dirty on some more low level flashing stuff.

  11. #11
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    If space considerations are an issue, consider going the route of breakout boards on Tindie. With the right cutouts in the PCB, you can mount the teensy directly to the PCB and have access to all pads and pins. The additional height is negligible. The only thing to consider is how to access the USB port - you may need to relocate the edge that the USB port sits on to be closer to an edge of the underlying PCB or have a cutout in the underlying PCB to accommodate a right angle plug.

  12. #12
    Senior Member
    Join Date
    Nov 2015
    Location
    Wales
    Posts
    579
    I use Kinetis Design Studio which is free and will allow you to develop and program any Kinetis device all from within one application. It certainly is not everyone's cup of tea though

    The hex file generated on compiling your code is effectively the raw machine code that your device will run. Because of this if it changes you have to reupload it to the device. What some people do is allow the device to self program, commonly referred to as a bootloader. This means you can program the bootloader and never have to reprogram the device with a programmer again.
    The Teensy takes this one step further. Instead of having a bootloader it has a bootloader chip. What this does is reads the HEX file from the USB and acts as a programmer for the MK20 device. This has various advantages and disadvantages and I'll let you decide if that's something you wish to stick with.

    You can if you so desire continue to develop in Arduino and when you upload your program is compiled into a HEX file. However at this stage you may then use this HEX file with a segger Jlink to program the device directly without the bootloader chip

    Some people have a seperate board with the Teensy bootloader chip on. This can then be removed once programming is complete. I'd personally question the morallity of doing this

    If you wish to expand your horizons I would strongly recommend pursuing an 'Arduino & bootloader' free solution. I believe you would develop a richer understanding of the device and processes used in the professional enviroment
    Last edited by Xenoamor; 07-16-2016 at 02:38 PM.

  13. #13
    Junior Member
    Join Date
    Jul 2016
    Posts
    12
    Thanks for a very thorough answer Xenoamor, I appreciate the time and effort you put into that post

    I've done some FPGA programming at the University, and there the FPGA chip would reprogram itself everytime the board was powered up, from a non-volatile memory chip that contained the program code (since FPGA chips are volatile and blanks out when power is lost). Is the bootloader kind of like that? Or is the bootloader only used when you actually make a change in the functionality? I assume the last since you mention that some remove the bootloader once the microcontroller has been programmed.

    Ok, let me see if I got this...

    So from Arduino software I compile my sourcecode into a .hex file. That .hex file is then passed to the MK20 chip. From your post I actually thought it was sent to the Kinetis MKL02 but from the scematic I see USB pins D-/D+ are connected to MK20. The last USB pin goes to the MKL20 though. Does this mean that via USB the MKL20 gets a command that we want to do a reprogramming of the MK20, then MKL02 uses the four connected pins it has to the MK20 to tell it to go into "re-program mode", and then the MK20 reads the new hex file from USB D+/D-? If I have understood that correctly then I understand that the code inside the MKL02 never changes, and that it is used as an in-circuit-programmer for the MK20, and that it is used when we actively want to reprogram the MK20. During regular usage, like when the board is powercycled the MKL20 doesn't do anything. Or?

    If I had used Kinetis Design Studio and a Segger J-link device I could have dropped the MKL02 chip. I can use the Arduino software for writing my code, configure it to use another programmer and then get the hex file into the MK20 via the J-Link. That would require me to learn Kinetis Design Studio, and also break out a JTAG connector to the MK20.
    Another alternative might be to drop the Arduino software alltogether and write all my code in KDS, right? Then its starting to become a bit too daunting.

    I think, for this prototype, I'll purchase a couple of the MKL02 chips and create my PCB with similar schematics as the Teensy 3.2 schematics. The $6 chip + $12 shipping is a bit pricey, but for a one-off project I'll manage.

  14. #14
    Senior Member Epyon's Avatar
    Join Date
    Apr 2013
    Location
    Belgium
    Posts
    443
    The MKL20 contains PJRCs proprietary Halfkay bootloader. When teensygateway.exe sends a 'program' command - or if you press the program button on the Teensy, the MKL20 restarts the MK20 and flashes the bootloader onto the main chip. It can then receive the new program code through USB and will run it after another reboot. The MKL20 then goes into standby mode.

    There are other ways to get your hex file onto the chip, e.g. through other programmers like the one you describe.

    If you are in prototype or low volume stadium, I wouldn't bother too much with stuff like this. A lot of developers loose themselves early on into these technical details trying to shave of some euros/dollars from the final product, not considering that their design probably won't be the final product and that they should invest more time in building a relationship with their customers/end-users first. Most of my low volume projects even use a standard Teensy with headers that I stick onto a custom PCB. If your product has been finalised, most of the times after a few production rounds, and your sales are running, you can start investing time in cost saving. E.g. you could then even buy MK20 chips that are preprogrammed with your code.

    That being said, there is one extra downside on this approach for us EU based customers. We have to pay for shipping but also VAT, meaning a $19 Teensy costs us €17 + €5 shipping + €5 VAT (21% on item value + transport) = €27. There are ways to avoid this, but for smaller purchases it isn't worth the trouble.

  15. #15
    Senior Member
    Join Date
    Jun 2015
    Posts
    132
    You also only need the boot-loader chip for programming. Once programmed it can be removed and the mk20 will boot up and run the firmware without it. So for production runs you can design the board without the boot-loader chip and just have it on a single external programmer board and program each board before they are shipped.

  16. #16
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    329
    I've done all the different options and when I have a choice, I still use the teensy loader.

  17. #17
    Senior Member
    Join Date
    Nov 2015
    Posts
    189
    the bootloader option (buy only the bootloader) will be available also for the new 3.5 and 3.6?

  18. #18
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    See the documentation on the MKL02 bootloader chip page in the store. Support for 3.5 and 3.6 is explicit.

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,467
    Quote Originally Posted by urbanspaceman View Post
    the bootloader option (buy only the bootloader) will be available also for the new 3.5 and 3.6?
    Yes, but not for several weeks. The MKL02 and MKL04 chips sold today only implement Teensy LC and 3.2.

  20. #20
    Junior Member
    Join Date
    May 2017
    Posts
    5
    Hi all,
    I have been working with the teensy's for some time and love them.
    Interesting thread this one is which peaks my interest of using teensyloader(MKL02/04) bootloader chips being used for other Kinetis MCU's except the teensy 3.x family.
    I am working on a project using the MK22 using KDS . So my idea was to program .hex files from KDS using teensyLoader.exe. As it provides fast way to upload/reprogram via USB removing the hassle of having a JTAG header on your board.
    I think it is theoretical possible as the MK20 and Mk22 share same pins but their memory size is different.But that involve changes in the Halfkay protocol on the teensy loader chip is that thing possible to do for the MKL02
    or it not a good idea to proceeed with? and work other Bootloaders.

    Thanks

Posting Permissions

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