Monday, July 2, 2012

Open Source: Template Peripheral Library for the STM32 microcontrollers


Today I'm releasing a library that I developed for the STM32 microcontrollers (currently there is support for the F1, F2 and F4 families). This library is written in C++0x, and addresses some issues I run into when I used other free peripheral C libraries.

The library is named libstm32pp, and it's available in this repository. libstm32pp makes heavy use of template metaprogramming, enumerators, static assertions, templates and namespaces. (Most of these are C++ exclusive features)

All these features allow a memory efficient implementation, compile-time error checking, a clean global namespace, highly organized functions in classes,  and a overall enjoyable programming experience.

I use this library along with bareCortexM, an Eclipse-based bare metal development enviroment, but you can use any other IDE, toolchain, etc. Although, I recommend having a auto-complete/content-assist feature, to get the most of this library.

Now, I'll go into some details of why this C++ library is better than other C peripheral libraries.

Enumerators instead of MACROS for constant values


Rationale: Enumerators can be used as function arguments, MACROS can't. Enumerators don't waste memory at run-time, like MACROS, in contrast with "const" variables. Enumerators are the best friends of template metaprogramming.

Hierarchical organization using namespaces and classes


Rationale: Nobody wants to call the content-assist/auto-complete and get hundreds of suggestions of enumerators and functions, a hierarchical organization using namespaces makes easier to find what your are looking for. Functions are stored inside classes as static members.


Verbose configuration, minimalistic implementation


Rationale: Template metaprogramming, allows the creation of advanced functions, that can get resolved at compile time, reducing the number of instructions at run time (which means faster execution and smaller memory footprint).


Highly configurable clock initialization


Rationale: Selecting between internal clock, external clock or PLL, and setting the bus prescalers is as easy as commenting a macro or filling an enumerator.


Static assertions


Rationale: Kills the bugs at compile time. Eliminates the chance of making impossible configurations. Template arguments are the best friends of static assertions.


Compile-time functions


Rationale: Get more done at compile-time, run less instructions at run-time, save power and memory. My favorite is the compile-time print, you can see values at compile time. (They appear as errors though)


Easy aliasing of peripherals


Rationale: The default name of the peripherals are nice, but sometimes giving them an alias name makes the program clearer.


That sums it all, I hope this library will be useful for all the STM32 hackers out there. I'll love to get feedback on this library. See you around.

Acknowledgements

  • Federico Terraneo, his post inspired the creation of this library.

Updates

  • I figured how to activate optimization without destroying the microcontroller exceptions and interrupts.
  •  The library now contains various demos to help you get started.
  • Added system calls, now the new / delete operators can be used. printf is also supported.

 How to use


Check this post, which offers a detailed tutorial on how to use this library alongside bareCortexM.

13 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download Now

      >>>>> Download Full

      Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download LINK

      >>>>> Download Now

      Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download Full

      >>>>> Download LINK 7m

      Delete
  2. @manoj
    How about actually commenting about the library, before posting links to your site?
    Thanks

    ReplyDelete
  3. Hola. Enhorabuena y gracias por la biblioteca.

    Hello. Good job!. I will test it soon. Since I read the Terraneo Federico's article on template metaprogramming the STM32 GPIO I was seeking for an extension of that concept to all peripherals. And there is your project!

    Thank you very much.

    ReplyDelete
    Replies
    1. Hola Francisco,

      Thanks for pointing out the identity of the creator of the GPIO template metaprogramming post, I've added a proper acknowledgment.

      I hope you find this library useful. Feedback and constructive criticism is welcome!

      Delete
  4. Hello Jorge !
    I am trying to use your library with an stm32F103RC
    I unused PLL USART works fine, but when I try to turn PLL the program either loops (PLL=2-7) or displays the port(PLL=8,9): üüà üà üà à à à üüüüà üà üà à à à üüüüà üà üà à à à üüüüà üà üà à à à üüüüà üà üà à à à üüü
    üà üà üà à à àü............
    Tell me where can be the problem?

    p.s. Sorry for my English, I'm from Russia. Thank you very much.

    ReplyDelete
    Replies
    1. Hello there,

      I haven't done much testing with the F1 microcontroller, and I don't have one at hand right now. I think you might have forgotten to:

      Uncomment the #define STM32F1XX under the device_select.h file

      or

      You are exceeding the device operating frequency. Check the datasheet and the cPrint command.

      Hope that helps

      Delete
  5. Hey,

    Have you used this library in the CoIDE? I'd guess you haven't because this IDE doesn't like your .hpp file extension but this is one of the most user friendly environments available. Are you able to any support because I have had no luck including your library thus far?

    ReplyDelete
  6. Selling USA FRESH SPAMMED SSN Leads/Fullz, along with Driving License/ID Number with EXCELLENT connectivity.

    **PRICE**
    >>1$ FOR EACH FULLZ WITHOUT DL NUMBER
    >>2$ FOR EACH LEAD/FULLZ/PROFILE
    >>5$ FOR EACH PREMIUM LEAD/FULLZ/PROFILE

    **DETAILS IN EACH LEAD/FULLZ**

    ->FULL NAME
    ->SSN
    ->DATE OF BIRTH
    ->DRIVING LICENSE NUMBER WITH EXPIRY DATE
    ->ADDRESS WITH ZIP
    ->PHONE NUMBER, EMAIL, I.P ADDRESS
    ->EMPLOYEE DETAILS
    ->REALTIONSHIP DETAILS
    ->MORTGAGE INFO
    ->BANK ACCOUNT DETAILS

    >All Leads are Tested & Verified.
    >Invalid info found, will be replaced.
    >Serious buyers will be welcome & I will give discounts on bulk orders.
    >Fresh spammed data of USA Credit Bureau
    >Good credit Scores, 700 minimum scores
    >Bulk order will be preferable
    >Minimum order 20 leads/fullz
    >Hope for the long term business
    >You can asked for samples, specific states & zips (if needed)
    >Payment mode BTC, ETH, LTC, Paypal & PERFECT MONEY

    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ''OTHER GADGETS PROVIDING''

    >SSN Fullz
    >CC fullz
    >Dead Fullz
    >Carding Tutorials
    >Hacking Tutorials
    >SMTP Linux Root
    >DUMPS with pins track 1 and 2
    >Sock Tools
    >Server I.P's
    >USA emails with passwords (bulk order preferable)

    **Contact 24/7**

    Email > leads.sellers1212@gmail.com
    Telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete
  7. Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download Now

    >>>>> Download Full

    Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download LINK

    >>>>> Download Now

    Embedded Programmer: Open Source: Template Peripheral Library For The Stm32 Microcontrollers >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete
  8. Buy bank login, Buy logs, Scampages, Tools , Credit cards, Smtps, Rdps, Email Sender, Scanner and Many More Tools by contacting me on telegram @cpanelmaster.
    ------
    cPanel hosting
    WHM
    Windows RDP
    inbox SMTP
    SMS Leads-Phone Number
    Email Leads
    Office 365 Email Leads
    Bulk Phone Number
    Residential Proxy
    Email Extractor
    Bank logs from ALL countries
    Fullz Debit/Credit Card
    Bill-payment School fee and other payment
    Money transfer Money
    SSN DOB DL data With Id pictures and Selfie
    -------
    Telegram: @cpanelmaster
    Join my telegram channel: https://t.me/cpanelmaster0
    ICQ: @cpanelmaster
    Website: https://toolz.store

    ReplyDelete
  9. Nice Blog. Thanks for sharing with us. Keep Sharing!!

    Do you want to buy Windows Embedded Panel PCs Online?

    Buy Windows Embedded Panel PCs Online

    ReplyDelete