Harmandeep Dubb
Harmandeep Dubb

Reputation: 149

How to import Zephyr Project device drivers

I am trying to use a device driver that is present in the Zephyr Project.

To my understanding the steps to import the driver are as followed:

  1. Verify that zephyr has drivers for your device. (I have ensured that Zephyr has drivers for my device by going to the github and finding that the drivers are made for gnss u_blox_m10 devices at this git hub page: https://github.com/zephyrproject-rtos/zephyr/tree/v3.7-branch/drivers/gnss)
  2. Look at the Kconfig file present for the drivers and included the needed config items included in the proj.conf file. The Kconfig file is as so:
# Copyright (c) 2023 Trackunit Corporation
# SPDX-License-Identifier: Apache-2.0

menuconfig GNSS
    bool "GNSS drivers"
    select EXPERIMENTAL
    help
      Enable GNSS drivers and configuration.

if GNSS

config GNSS_SATELLITES
    bool "GNSS satellites support"
    help
      Enable GNSS sattelites callback.

config GNSS_DUMP
    bool "GNSS dump support"
    depends on LOG
    help
      Enable GNSS dump library

config GNSS_DUMP_TO_LOG
    bool "Dump GNSS events to log"
    select GNSS_DUMP
    help
      Enable GNSS dump to log.

if GNSS_DUMP_TO_LOG

config GNSS_DUMP_TO_LOG_BUF_SIZE
    int "GNSS log dump buffer size"
    default 128
    help
      Size of GNSS log dump buffer

endif

config GNSS_PARSE
    bool "GNSS parsing utilities"
    help
      Enable GNSS parsing utilities.

config GNSS_NMEA0183
    bool "NMEA0183 parsing utilities"
    select GNSS_PARSE
    help
      Enable NMEA0183 parsing utilities.

config GNSS_NMEA0183_MATCH
    bool "GNSS NMEA0183 match utilities"
    select GNSS_NMEA0183
    help
      Enable NMEA0183 match utilities.

config GNSS_INIT_PRIORITY
    int "GNSS driver initialization priority"
    default 80
    range 0 99
    help
      Driver initialization priority for GNSS drivers.

config GNSS_U_BLOX_PROTOCOL
    bool "GNSS U-BLOX protocol"
    select MODEM_UBX
    help
      Enable gnss u-blox protocol.

module = GNSS
module-str = gnss
source "subsys/logging/Kconfig.template.log_config"

rsource "Kconfig.emul"
rsource "Kconfig.generic"
rsource "Kconfig.quectel_lcx6g"
rsource "Kconfig.u_blox_m10"
rsource "Kconfig.luatos_air530z"

endif

I have included all of the configs that are after config keyword.

  1. Include the config statements for the driver that is directly related to your device. In my case I then went to the file named Kconfig.u_blox_m10 which is below and included the needed configs after the config keyword:
# Copyright 2024 NXP
# SPDX-License-Identifier: Apache-2.0

config GNSS_U_BLOX_M10
    bool "U-BLOX M10 GNSS Module"
    default y
    depends on GNSS
    depends on DT_HAS_U_BLOX_M10_ENABLED
    select MODEM_MODULES
    select MODEM_BACKEND_UART
    select MODEM_CHAT
    select MODEM_UBX
    select GNSS_PARSE
    select GNSS_NMEA0183
    select GNSS_NMEA0183_MATCH
    select GNSS_U_BLOX_PROTOCOL
    select UART_USE_RUNTIME_CONFIGURE
    help
      Enable U-BLOX M10 GNSS modem driver.

config GNSS_U_BLOX_M10_SATELLITES_COUNT
    int "Maximum satellite count"
    depends on GNSS_SATELLITES
    default 24
    help
      Maximum number of satellite that the driver that can be decoded from
      the GNSS device. This does not affect the number of devices that the
      device is actually tracking, just how many of those can be reported
      in the satellites callback.

After this I am not sure what to do 100% but from prior experience I should be able to import the dirver file and work with the functions.

To do this I included the following statement in my main.c file:

#include <zephyr/drivers/gnss/gnss_u_blox_m10.c>

However this is referring an error. SO after doing more research about the matter, I have read that the device just uses the generic gnss interface to get you the data.

Is this true? When looking at the GNSS example it just uses the following code for data collection:

static void gnss_data_cb(const struct device *dev, const struct gnss_data *data)
{
    if (data->info.fix_status != GNSS_FIX_STATUS_NO_FIX) {
        printf("Got a fix!\n");
    }
}
GNSS_DATA_CALLBACK_DEFINE(GNSS_MODEM, gnss_data_cb);

Am I suppose to use the generic interface as illustrated above?

Is there some reference that clearly spells this out?

Upvotes: 0

Views: 68

Answers (1)

Unn
Unn

Reputation: 5098

You are missing one critical piece to enabling the GNSS hardware, and then aren't quite using the API correctly from your post. The steps you should follow for any hardware device, in general, are:

  1. As you say, see if Zephyr supports the specific hardware (or if your hardware has a standard interface, see if Zephyr supports that interface). In your case, there does appear to be a driver for the U-blox M10 GNSS module; otherwise you might have to write one.
  2. Add the device to your project or boards devicetree. The devicetree is how Zephyr knows what hardware is present and how it's connected. Looking at the GNSS sample, they have two board overlays in the boards/ folder that have examples for how you would declare the GNSS module as a child of the associated UART controller to which it is connected.
  3. After the devicetree, then you need to confirm the correct Kconfig settings are set in your project. In this case, adding most of the settings is unnecessary, you probably just need CONFIG_GNSS and then any others for which you do not like the default. In the case of the actual driver (ie, CONFIG_GNSS_U_BLOX_M10), it's usually set to y so only as there is a matching node and it's status in the devicetree is "okay". Notice the dependency on DT_HAS_U_BLOX_M10_ENABLED, this Kconfig is generated by the devicetree and cannot be override by the project. And if it's not enabled, you will not be able to force CONFIG_GNSS_U_BLOX_M10 as even if a value is set to y in the project, it will still respect its dependencies.
  4. Finally, the driver should be included and available to the application. See the sample above for the proper usage of the API to access it.

Upvotes: 0

Related Questions