Mbed API compatibility layer

Status
Not open for further replies.

bloodline

Well-known member
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.
 
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...

Capture.JPG
 
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...

View attachment 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.
 
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.
 
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! :)
 
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:
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:
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.
 
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.
 
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 !
;-)
 
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.
 
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:
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:
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.
 

Attachments

  • Mbed_Teensy_test.jpg
    Mbed_Teensy_test.jpg
    145.1 KB · Views: 341
Last edited:
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:
Status
Not open for further replies.
Back
Top