Satrapes
Satrapes

Reputation: 183

How do you start writing your API for an MCU peripheral?

I am trying to improve on my embedded programming skills by learning how to program each peripheral on an STM32 Nucleo board (STM32F401RE) and slowly building my own library from scratch (Without using HAL initially just toggling bits directly on the registers).

I am facing a problem though, when I try to encounter something that I haven't used before I am getting stuck on figuring what to include on the API.

Let's say that I want to use the ADC peripheral, is it enough to just copy the API from the mbed-src on github and start from there, or am I going to need any extra functions?

https://github.com/mbedmicro/mbed/blob/03fff9249b0ca5efb2e12506ce8fb3e6cc258d9d/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4XX/analogin_api.c

Are there any universally accepted resources from where to start from?

Thanks for your help.

Upvotes: 1

Views: 1460

Answers (1)

embedded_guy
embedded_guy

Reputation: 1967

Jacob Beningo has a white paper that he created that describes the basics of creating API's for embedded work. I would highly recommend reading this as a starting point: Developing Reusable Device Drivers for MCUs.

His paper walks you through the design of API's for digital I/O and for SPI. He describes why he makes a lot of the design decisions that he has made and has great tips on the use of pointer arrays, and configuration tables. I found it very informative when I was starting out.

Of course, as Olaf and dwelch point out in the comments, you have to familiarize yourself with the datasheet in order to properly implement any of the peripherals of your MCU.

Upvotes: 2

Related Questions