How to add a peripheral to mbed-os ?

02 Aug 2017

Hello,

I'd like to add a bluetooth device commanded through SPI. I saw in the feature folder the MAXIM device which exchange through SPI to take it as an example but I don't figure out how it works. For example, how to tell the compiler to use the maxim device ? If I want to add one, I think I need to declare it in the json file, but what I need to do else ?

Thanks for any reply. Regards, Flo

15 Aug 2017

Hello Flo,

In order to add a peripheral device to an mbed program one has to import a library which is implementing a driver for that particular device:

  • In the online compiler create a new program or select an existing one.
  • On the toolbar click on the Import button and then proceed to the Libraries tab.
  • Type your search criteria into the line edit box and click on the Search button (See below where you can find some component drivers).
  • From the list presented select the line with the driver you would like to import and then click on the Import! button located in the top-right corner.
  • Once the library has been imported you should be able to examine the source codes implementing the device driver interface.
  • To use the device driver interface (define variables, execute commands, handle interrupts etc.) in your program add the header file of the imported library to your application program's code.
  • Repeat the steps above for each device you would like to use in your application program.

There are lot of devices already supported by mbed. It means that someone (the mbed team, the manufacturer or a user like you) has written and published a library implementing a device driver. In some cases there are published also some example programs demonstrating how to use the given library. For example, the Hardware->Components page presents lot of components along with device driver libraries and example programs demonstrating how to use them. In addition you can search the mbed for more drivers and demos written and published by mbed users.

So in case you would like to add a new device, which isn't supported yet, most likely you have to write a library implementing the device driver. The best way of learning is to study the existing drivers. Also have a look at:

https://developer.mbed.org/handbook/mbed-library-internals
https://developer.mbed.org/cookbook/Writing-a-Library
https://developer.mbed.org/handbook/API-Documentation