This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding in drivers into zephyr

Hey all


trying to understand how to add in drivers from zephyr into my project. an example like adding the w5500 module would that ential something like this ?

-1) copy contents of kconfig file into source kconfig (file: Kconfig.w5500 into -> prj.conf
-2) from cmakelists.txt in the ethernet directory 
    -- add zephyr_include_directories(${ZEPHYR_BASE}/subsys/net/l2)
    -- add zephyr_sources_ifdef(CONFIG_ETH_W5500 eth_w5500.c)
    -- add 

 if(CONFIG_ETH_NATIVE_POSIX)
zephyr_library()
zephyr_library_compile_definitions(
NO_POSIX_CHEATS
_BSD_SOURCE
_DEFAULT_SOURCE
)
zephyr_library_sources(
eth_native_posix.c
eth_native_posix_adapt.c
)
endif()


and then reload and enable it in menuconfig ?

Just want some confirmation before i start tinkering.
tried searching on the forum for a similiar question but i didnt see any results with "zephyr & drivers"
if these a page on https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/index.html that i've missed please pop that through as i've missed it

Thankyou !!

  • Good morning @

    Fellow Devzone developer Ted here.  I will be watching replies to your posted question as it's closely related to a Zephyr driver integration problem I was about to post here myself.  I am sorry I do not have a ready solution to share with you right now.

    On my side I am trying to integrate the driver for STMicro's IIS2DH accelerometer into a small Zephyr app of my own, which presently targets Sparkfun's Thing Plus nRF9160 development board.  Nordic Semi's sdk-nrf includes a sample app for the closely related LIS2DH, and there are drivers for both these parts in sdk-nrf v1.6.1 modules project.  I think these may be considered "out-of-tree" drivers because they're located in a 'modules' directory that is cloned along side Nordic's fork of the Zephyr project.  They're not located under the 'zephyr' directory at the top level of the SDK.

    In general I believe you are on the right track.  To enable `cmake` to find IIS2DH header file I needed to add a line to my project's CMakeLists.txt file that's of the form of your line above, `zephyr_include_directories(${ZEPHYR_BASE}/subsys/net/l2)`.

    In your work I am unsure about directly copying contents of a Kconfig file into prj.conf.  These two file types seem to have somewhat different syntax.  Kconfig files express which kernel options and option inter-dependencies are available and present.  Prj.conf enables them with the 'symbol=value' syntax.  But these two files are closely related in a given Zephyr based project.

    - Ted

  • Hi,

     

    This driver is a zephyr component, but I'll try to help you along the way.

    You need to first add the dependencies of the device itself, which is the transport layer (SPI) and the net stack in zephyr:

    CONFIG_SPI=y
    CONFIG_NETWORKING=y
    CONFIG_NET_L2_ETHERNET=y
    CONFIG_ETH_W5500=y
    

     

    And you need to define the device in device tree as well. This can be done by creating the my-application/boards folder, and $(BOARD).overlay (for example: boards/nrf5340dk_nrf5340_cpuapp.overlay), which should hold the peripheral and device specific declaration:

    &spi3 {
            sck-pin = <47>;
            miso-pin = <46>;
            mosi-pin = <45>;
            cs-gpios = <&gpio0 21 GPIO_ACTIVE_LOW>;
            status = "okay";
            w5500: w5500@0 {
                    compatible = "wiznet,w5500";
                    label = "w5500";
                    reg = <0>;
                    spi-max-frequency = <1000000>;
                    int-gpios = <&gpio0 20 GPIO_ACTIVE_LOW>;
    // optional:             reset-gpios = <&gpio0 21 GPIO_ACTIVE_LOW>;
            };
    };

     

    Note that the above is provided as an example, please change the GPIOs to match your wanted pins.

     

    Kind regards,

    Håkon

  • Sorry for the delay. oh ok, so just to reitterate 
    CONFIG_NETWORKING=y
    CONFIG_NET_L2_ETHERNET=y
    CONFIG_ETH_W5500=y
    alone link the drivers to the project.

    so in the case that the driver isnt a zephyr component does that make it alot harder to add in ?  is there a template/ tutorial / page on the matter ?

  • ah ok, thanks for your advice ! i was thinking about just ripping/copying out one of the other drivers that im familiar with and attempting to swap out and integrate it if required but i cant seem to find much on the matter on what is required to nicely have things fit in haha.

  • Hi,

     

    lolcatsnin said:
    so in the case that the driver isnt a zephyr component does that make it alot harder to add in ?  is there a template/ tutorial / page on the matter ?

    If the component/driver isn't already present in zephyr, and you want to add it in the "zephyr way", I'd recommend reading the zephyr documentation, and its driver model:

    https://docs.zephyrproject.org/latest/reference/drivers/index.html

    And the device tree:

    https://docs.zephyrproject.org/latest/reference/devicetree/index.html#

     

    Kind regards,

    Håkon

Related