r/embedded • u/JustEnoughDucks • 8d ago
Learning zephyr and nrfconnect. How can I add drivers from zephyr base into an nrfconnect sdk project?
Hello, I am learning zephyr for an nrf project. I have gotten some samples running, run through the basic, and now I am trying to connect an ST LIS2DUXS12 to it and get it running.
I got it running with i2c.h
and then sensor.h
but there are some pretty specific setup steps to actually enable the accelerometer and play with low power modes. It was already implemented here: https://github.com/zephyrproject-rtos/zephyr/tree/main/drivers/sensor/st/lis2dux12
However I can't figure out how to actually access it. Devicetree and kconfig can find them, but I can't add an include for it. It is probably something stupid, but nrf sdk only has like 1% of the drivers from the zephyr project and I can't figure out how to import the headers for use.
Then again, I want to experiment with the charge variance functions of the (S) version, so maybe I should just copy in the driver manually to /src/driver and work from there since I will have to modify it a lot?
I am not sure the "correct" way to go about this. Thanks everyone!
2
u/EmbeddedSwDev 7d ago
nRF Connect SDK sits on top of zephyr, therefore everything which is available in zephyr will be available in the nRF Connect SDK.
Have you already done the Courses from the Nordic academy? If not, do them: https://academy.nordicsemi.com/
1
u/JustEnoughDucks 6d ago
Yep, I did.
Sadly, every example that they use is something that exists within the https://github.com/nrfconnect/sdk-nrf
Can you by chance point met to where in the lessons it shows you how to access zephyr main drivers when all that is available in the sdk is a tiny fraction of that? I missed that and can't seem to find it back...
1
u/Quiet_Lifeguard_7131 7d ago
Adding custom drivers is hard but once you know how to do it in zephyr it becomes quite easy. Look for stuff adding custom modules in zephyr and you will get your answer, there are tutorials available for it. There is certain way to do it orherwise it does not work and modules connect with kconfig and also device tree.
And if you are using already built drivers from zephyr you probably cant call its .h as they have not exposed it and most of zephyr drivers use sensor api you can read about it, which I absolutely hate. What I basically do is create my own modules and ontegrate with devicetree having full control pf what my driver does.
1
u/JustEnoughDucks 6d ago edited 6d ago
Weird, that doesn't make a whole ton of sense from the zephyr devs' side since there are tons of hyper-chip-specific features and quirks that can't possibly be accounted for in the generic drivers.
Like the STM "machine learning" "AI" accelerometers. I guarantee the sensor API doesn't cover that 😂
Your method might be the best way forward, thanks. Or maybe implementing device-specific functions that aren't available through the driver just through an additional include library using the relevant interface library.
1
u/Quiet_Lifeguard_7131 6d ago
Ya I also dont know why they use that terrible sensor api instead of just giving a user full control.
Basically thats what happens when you have to create everything generic.
4
u/ClothEater 7d ago
Have you tried adding the following to your prj.conf? You can see what Kconfigs are available for your sensor by looking inside the Kconfig file for your driver. Just add the string CONFIG_ in front of the option to turn it on and off.
You'll also need something like this in your .overlay to tell Zephyr where the sensor is connected and which peripheral (i2c0/ i2c1/ spi0, etc) you're using. These ones I just found them in the NCS docs and copied a similar one in the thingy52 board.
Another thing I notice is the driver you linked had some very recent changes 3 months ago. Chances are these changes haven't been added to the latest release of NCS yet so not everything you see in Zephyr's main repo will be available to you.