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

Thread: Mbed API compatibility layer

  1. #1
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90

    Mbed API compatibility layer

    Hi All,

    I really like the Teensy Hardware and appreciate the power of the Arduino platform as a brilliant way to get started with micro controllers. But I must be honest, I prefer the mbed API, it feels more modern.

    I have been using the mbed for a few years now and I have a lot of projects built on it. But the Teensy 3.1 was just too exciting to ignore, so I bought one and have found it a fantastic piece of hardware! I wanted to run my old mbed projects on the Teensy without having to rewrite them entirely from scratch, so I have written a simple mbed API compatibility layer on top of Teensyduino. I publish it here in case others will find it useful.

    At the moment only the DigitalIO, PWM and some of the timer classes are supported, but I hope to add the rest in as I have time. The git repository is public, feel free to commit bug fixes and improvements if you can. As I learn the MK20DX hardware better, I will rewrite the methods to hit the hardware directly, I hope the more technical member of this forum will help too. :-)

    https://github.com/h5n1xp/Teensymbed.git

    Enjoy.

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    I have an mbed.. used it for a while when it was new.
    Have you studied the Teensyduino libraries of C++ classes for the K20 hardware? It's pretty extensive. Paul's put a lot of blood and sweat into these. And these enable many of the Arduino libraries for higher level functions to work.

    the URL has an oops...

    Click image for larger version. 

Name:	Capture.JPG 
Views:	161 
Size:	27.3 KB 
ID:	1361

  3. #3
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90
    Quote Originally Posted by stevech View Post
    I have an mbed.. used it for a while when it was new.
    Have you studied the Teensyduino libraries of C++ classes for the K20 hardware? It's pretty extensive. Paul's put a lot of blood and sweat into these. And these enable many of the Arduino libraries for higher level functions to work.

    the URL has an oops...

    Click image for larger version. 

Name:	Capture.JPG 
Views:	161 
Size:	27.3 KB 
ID:	1361
    I forgot to sync my local repo with the server, it's good now.

    My work is simply a compatibility layer, it sits on Paul's excellent work. I hope it will make the Teensy 3.x hardware more attractive to mbed developers.

  4. #4
    Member dhylands's Avatar
    Join Date
    Nov 2013
    Location
    Shuswap, BC, Canada
    Posts
    45
    I believe that there is also work under way in the mbed repository to add support as well.

  5. #5
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90
    Quote Originally Posted by stevech View Post
    I have an mbed.. used it for a while when it was new.
    Have you studied the Teensyduino libraries of C++ classes for the K20 hardware?
    Are you able to offer a link?

  6. #6
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90
    Quote Originally Posted by dhylands View Post
    I believe that there is also work under way in the mbed repository to add support as well.
    That would be a better solution, the mbed platform offers a rather fun RTOS as well as a few standard C/posix functions

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,363
    That's awesome.

    Perhaps this could be repackaged into an Arduino style library? Maybe a name like MBedCompatibility or MBedEmulation would be nice?

    If it were in a library format, I'd love to include it in the libraries distributed with the Teensyduino installer.

  8. #8
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90
    Quote Originally Posted by PaulStoffregen View Post
    That's awesome.

    Perhaps this could be repackaged into an Arduino style library? Maybe a name like MBedCompatibility or MBedEmulation would be nice?

    If it were in a library format, I'd love to include it in the libraries distributed with the Teensyduino installer.
    Thanks Paul, once I get the more of the API implemented (with wrappers around the various coms libraries) and tested it more with my own projects, I will repackage it as an arduino library, for you to do with as you deem best. The Teensyduino API and mbed API don't seem to have any clashes, so users should be able to pick and choose to suit their coding style (I think the mbed PWM class is particularly elegant compared with the Arduino functions).

    Thnaks for producing the Teensy project, I really do love the Teensy 3.1 board!

  9. #9
    Member
    Join Date
    Mar 2014
    Location
    Übersee, Germany
    Posts
    40
    How is the progress on this topic?
    I am struggling whether to abandon teensy 3.1 just because I prefer to use mbed.
    Teensy 3.1 is still the best module around for my choice and the solution for the bootloader stored in a companion chip and reloaded into Ram @ every boot time is brilliant.
    Please make this a 100% solution for me and many others adding mbed support.
    Another idea could be to implement a MSD mode in teensy 3.1. I believe that this would be enough to allow a porting of the real mbed system to teensy. Why not include teensy 3.1 in the list of mbed boards? Mbed as well as freescale should support it, I think.
    Regards.
    Eduardo
    Last edited by eduardo; 04-08-2014 at 12:02 PM.

  10. #10
    Member
    Join Date
    Jan 2014
    Location
    London, UK
    Posts
    90
    Quote Originally Posted by eduardo View Post
    How is the progress on this topic?
    I am struggling whether to abandon teensy 3.1 just because I prefer to use mbed.
    Teensy 3.1 is still the best module around for my choice and the solution for the bootloader stored in a companion chip and reloaded into Ram @ every boot time is brilliant.
    Please make this a 100% solution for me and many others adding mbed support.
    Another idea could be to implement a MSD mode in teensy 3.1. I believe that this would be enough to allow a porting of the real mbed system to teensy. Why not include teensy 3.1 in the list of mbed boards? Mbed as well as freescale should support it, I think.
    Regards.
    Eduardo
    Hi Eduardo,

    Let me know which part of the Mbed API you depend on and I will prioritise my free time to work on it. Right now, basic mbed stuff should be usable... I have already used it to assist porting my own projects from the mbed platform

    I agree, it would be nice if we had real Mbed compatibility, but I have a love/hate relationship with their web dev environment.

    -edit- personally, I prefer the Teensy hardware over the mBed hardware, and I like to have both the Arduino and Mbed APIs available during development
    Last edited by bloodline; 04-08-2014 at 12:15 PM.

  11. #11
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    Quote Originally Posted by eduardo View Post
    I am struggling whether to abandon teensy 3.1 just because I prefer to use mbed.
    Teensy 3.1 is still the best module around for my choice and the solution for the bootloader stored in a companion chip and reloaded into Ram @ every boot time is brilliant.

    Regards.
    Eduardo
    Funny what makes the world go 'round! I used the mbed for a couple of months when it first came out. First use of an on-line compiler that pushed down to me the executable. Then stored that executable on the mbed's extra flash memory. Then a 2nd smaller NXP processor copied to the main CPU's flash and launched it.

    I love the concept of this download to secondary storage (much like an SD card), then boot automatically. The Mbed stores many programs and auto-runs the youngest, but you can boot any. A weakness, I suppose, of the Teensy 3 is that although it has a 2nd processor for booting (and other reasons), it can only use USB.

    Funny though... I changed to the Teensy3 because I found the mbed community to be lacking in terms of collaboration. And for me, the lack of a stable TCP/IP stack for the onboard NIC was the deal breaker.

    Also, I grew to dislike the on-line compiler scenario - mostly because the project-IDE scheme via a browser was confusing to me. But it was nice to get a "free" Keil compiler to use.
    The CMSIS - never seemed valuable to me- seemed mostly focused on DSP things. The RTOS- nah, I'd prefer FreeRTOS. Old habits I guess.

    So, kind of interesting how experiences differ.

  12. #12
    Member
    Join Date
    Mar 2014
    Location
    Übersee, Germany
    Posts
    40
    A lot of interest in this thread. Great.
    mbed-API @bloodline: Thanks for your offer. I will start a new customer project (scientific instrument) in May. By that time I will know more precisely what I need in terms of functionality, API-calls, ... Mbed-Api is definitely a choice. Auto-run ADC and PWM is a must.
    mbed vs teensyduino A great topic to discuss on. Lots of aspects (and personal/passionate preferences). Probably better in another thread.
    teensy 3.1 for mbed @Paul: My wish would be "teensy 3.1 -m" modules w/ MSD bootloader and native mbed support. K20 is already supported in the mbed community. At the moment there is only one interesting mbed board for my needs. It is called DipCortex-M3. Cheap, simple and good for comercial usage. Unfortunately only M3 and out of stock. Teensy 3.1 would be a killer among the mbed-HW choices. And SW support would be done by the mbed guys. Worldwide marketing is guaranteed.

  13. #13
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    M3 - flash/RAM too small for this era.

  14. #14
    Member
    Join Date
    Mar 2014
    Location
    Übersee, Germany
    Posts
    40
    FastAnalogIn from mbed is quite interesting

  15. #15
    Junior Member
    Join Date
    Nov 2012
    Location
    Northern Germany
    Posts
    9
    Quote Originally Posted by eduardo View Post
    teensy 3.1 for mbed @Paul: My wish would be "teensy 3.1 -m" modules w/ MSD bootloader and native mbed support. K20 is already supported in the mbed community. At the moment there is only one interesting mbed board for my needs. It is called DipCortex-M3. Cheap, simple and good for comercial usage. Unfortunately only M3 and out of stock. Teensy 3.1 would be a killer among the mbed-HW choices. And SW support would be done by the mbed guys. Worldwide marketing is guaranteed.
    an absolutely interesting thought ...
    I second that !
    ;-)

  16. #16
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    DipCortex-M3
    12KB RAM
    Too small for me!

  17. #17
    Member
    Join Date
    Mar 2014
    Location
    Übersee, Germany
    Posts
    40
    Teensy 3.1 is a Cortex-M4 (without FPU) w/ 256K Flash and 64K Ram. ADC is 16 bits. Two DACS.
    The module is small and inexpensive. Add-Ons for micro-SD, Ethernet and HiRes-Audio available.

    In my opinion one of the most interesting (semi-)professional platforms for mbed ever if it comes to that.
    What needs to be solved is:
    - Support freescale K20M72 fully as mbed platform (almost so, see K20M50)
    - provide a commandline bin-to-hex converter (easy) between mbed and teensyduino loader SW or
    - convince Paul from pjrc to provide a MSD firmware option for the integrated bootloader chip so that mbed's bin files can be used.

  18. #18
    Junior Member
    Join Date
    Nov 2014
    Posts
    12
    The Freescale FRDM-K20 board is now fully supported in Mbed.
    I have compiled, converted to .hex and loaded a simple LED blinky program to the Teensy3.1 but it did not work.
    Is this due to the bootloader code?

    This board would be popular on Mbed, so may pay to iron this one out if possible before someone else markets a small board that does.

    Looking a bit further, the Mbed compiles for an 8Mhz crystal, the Teensy uses a 16Mhz, perhaps this is the problem?
    Last edited by STAR297; 11-08-2014 at 12:22 PM.

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,363
    The interrupt vectors are different too.

  20. #20
    Member
    Join Date
    Mar 2014
    Location
    Übersee, Germany
    Posts
    40
    Quote Originally Posted by STAR297 View Post
    The Freescale FRDM-K20 board is now fully supported in Mbed.
    I have compiled, converted to .hex and loaded a simple LED blinky program to the Teensy3.1 but it did not work.
    Is this due to the bootloader code?

    This board would be popular on Mbed, so may pay to iron this one out if possible before someone else markets a small board that does.

    Looking a bit further, the Mbed compiles for an 8Mhz crystal, the Teensy uses a 16Mhz, perhaps this is the problem?
    The bootloader code should not be the cause, I believe.
    Have you tried to load your programm into a teensy 3.0 instead of a 3.1? This should be the correct target for a programm which was originally built for frdmK20.
    Otherwise setting mbed for FRDMK22 may be worth a try too.
    Last edited by eduardo; 11-26-2014 at 02:34 PM.

  21. #21
    Junior Member
    Join Date
    Nov 2014
    Posts
    12
    Okay, looked at this a bit closer, system_KD50D5.c file in MBED-SRC library has clock_setup defined as mode-1 using 8Mhz crystal.
    Change this to mode-0 slow internal IRC (32KHz). Speed drops to 41.94MHz core and bus that will affect serial coms at higher speeds and will have poor Ticker, Timer accuracies.

    This works as a test (Blinky LED set to PTC5), you will need to power cycle the Teensy to reset and run.
    However the way forward would be to replace the original 16MHz crystal on the Teensy with an 8MHz crystal.
    Then the Mbed code should run out of box???

    I have removed earlier comments to save wasting reading time.

    I now have most of the code correct and will add a link to Mbed shortly.
    I will detail it more there.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Mbed_Teensy_test.jpg 
Views:	247 
Size:	145.1 KB 
ID:	3008  
    Last edited by STAR297; 12-03-2014 at 01:12 PM. Reason: Further Tests

  22. #22
    Junior Member
    Join Date
    Nov 2014
    Posts
    12
    Teensy3.1 support is now available on Mbed Git Hub here:

    https://github.com/mbedmicro/mbed/tr...e/TARGET_K20XX

    Currently waiting for approval for the platform to be added to Mbed.
    Only the CAN embedded peripheral API remains to be added.

  23. #23
    A couple questions on this old thread. I looked at the github files. Does the target-teensy_3_1 work with the 3.2 as well? Also, If I have a fairly large Mbed LPC1768 project I have been working on converting over to teensy 3.1. Can I just compile it in the online mbed IDE then convert to hex for this target? I know I'll have to address a couple incompatibilities I am aware of (atomic functions), but this may save me a bit of time. This is the project I am trying to convert.

    just4trionic

    edit: Poking around some more. I am getting to know the IDE a bit. I have installed the teensy 3.1/2 platform and can select the teensy as my device to program for. Now, I need to replace the onboard storage with sd card, I'm sure I can poke around a bit for that. How do I enable the CAN bus on the teensy? The error is:

    Error: Identifier "CAN" is undefined in "interfaces.h", Line: 21, Col: 9

    KeithG
    Last edited by keithg; 02-18-2016 at 04:38 PM.

  24. #24
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,363
    Quote Originally Posted by keithg View Post
    Does the target-teensy_3_1 work with the 3.2 as well?
    It certainly should.

    The main difference between 3.1 & 3.2 is an improved 3.3V regulator, using a dedicated chip instead of the weaker one built into the processor.

Tags for this Thread

Posting Permissions

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