Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

How to register a NuttX driver in a STM32 board. #3

@jfm92

Description

@jfm92

Sometimes a driver is developed but it's not registered in your board.
I will try to explain how to register a driver (Developed by you or an already existing) to a board throw an example(The registration of the BMP180 driver).
Note: This guide is for STM32 boards. Some things could be different in other brands.

First it's necessary to create an "arch driver"(I don't know the real name, because in the documentation there isn't different terminology between the general drivers and specific drivers).

Difference between arch driver and general driver:

Arch Driver: They are at src folder in the config(i.e. nuttx/configs/olimex-stm32-e407/src) and they can be only called by that board. An arch driver can use a functions of a general driver.

General Driver: Theses drivers are in nuttx/driver and can be use by any board (Other thing if it'll run in your board).

Add the driver:

The majority of times if a driver is developed, the most sure is that it will be resgister in the most popular boards so, you can go to nuttx/configs/stm32f103-minimum/src and check if it available.(If you're working with an STM32 micro, the driver it will call smt32_whatever.c)
For this example, we are going to copy stm32_bmp180.c to nuttx/configs/olimex-stm32-e407/src.
Then we must open the file and change #include "stm32f103_minimum.h" to #include "olimex-stm32-e407.h"
imagen
This change is just to use the variables and pin map of this board instead of the other one.

The majority of the times the arch driver are use to call registration functions of the general driver. This function usually registry the device and set-up the configuration necessary for the device.
imagen

In this particular case, we can see that the function initialize the I2C bus and then call to the bmp180 register function. This function do the next actions(In the majority of the cases they do exactly the same things):

  • Reserve memory to save the connection data.
    -Configure the device.
    -Make like a ping to check if the connection is ok.
    -Finally if everything is fine , register the driver of the device allowing to access in the app.
    (This function is in nuttx/drivers/sensor/bmp180)

Now we should go to Makefile (in nuttx/configs/olimex-stm32-e407/src) and add:
ifeq ($(CONFIG_SENSORS_BMP180),y)
CSRCS += stm32_bmp180.c
endif

The first line means, that we'll use the next line if we've checked this configuration at menuconfig. You can add more config condition adding bellow the first one more "ifeq".
The functionality of this file, is add the file that we want to the compilation.
Tip:
To know the name of a configuration and the dependencies that have, go to the configuration that you want to check and push 'h'. This will show this image
imagen

Also in the opposite case that you know the name of a configuration but you don't find it. Push '/' and this will start a config browser allowing you to find whatever you want in the menuconfig.
End of the tip.

In the same folder, go to olimex-stm32-e407.h (or the name of your board) and add the next line:
imagen

Finally we are going to add the driver to the bootloader.

Go to the file stm32_bringup and add the next lines:
imagen
The first line check if the sensor have the correct option checked.
The second line is the initialization/registration of the sensor at the boot time.

Configuration of the sensor in menuconfig:

This final part is exactly of the BMP180 sensor. Each sensor or device need a particular configuration that is usually in the readme file.
Go to the menuconfig and check the next options in the next path:
System Typed -> STM32 peripheral->I2C1(Checked)
Device drivers -> Sensor (Checked) -> BMP180(Checked)
Device drivers -> I2C Driver Support (Checked)
Application configuration -> Examples -> BMP180 Barometer sensor Example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions