BeagleBone PWM configuration in kernel space - c

I'm beginner in kernel module development.
I'm running Debian 8 in BeagleBone Black with cape-universaln loaded. The module pwm_tiehrpwm is loaded. I can configure pwm signal through the respective /sys/class/pwm/pwmchipN. I have checked the signal using a scope. Everything is working.
My question is how can I configure pwm channel, duty/period, enable and disable in kernel space, in the other words, inside of the kernel module?

Related

How to use custom device tree source correctly in buildroot?

I made a copy of the dts from <linux>/board/arch/arm/boot/dts/imx28-evk.dts for using with my custom board. My custom device-tree is named imx28-custom.dts and is pointed in the Out of tree custom DTS menu entry (BR2_LINUX_KERNEL_CUSTOM_DTS_PATH) in the Buildroot config.
However u-boot is configured to use the existing MX28 board config. After building a kernel I have imx28-custom.dtb and zImage in the <buildroot>/output/images folder.
When the system boots, u-boot tells that imx28-evk.dtb is not found. Why was imx28-custom.dtb built but is not found by u-boot? Why u-boot doesn't find its own device-tree (imx28-evk.dtb) for itself and my custom device-tree for the kernel? I assumed that BR2_LINUX_KERNEL_CUSTOM_DTS_PATH relates only to the kernel. How can my custom device-tree be passed to the kernel if u-boot tries to use its own imx28-evk.dtb for this?
u-boot complaining about not finding the device-tree is related to the Linux kernel: when booting, u-boot loads the device-tree and kernel image from the storage to specified addresses in the memory and then passes control to the kernel. The default configuration for the i.MX28-EVK board is to pass the imx28-evk.dtb file.
The BR2_LINUX_KERNEL_CUSTOM_DTS_PATH only serves to include the custom device-tree in the files to build and install but does not configure u-boot to use it.
Which device-tree u-boot passes to the kernel is defined by u-boot's CONFIG_DEFAULT_FDT_FILE option (you can edit this by typing make uboot-menuconfig (see my note at the end) then going under Boot to set the Default fdt file). This option should be set to something like imx28-custom.dtb.
How to configure u-boot from Buildroot is described here and here to make them permanent.
In the case of the i.MX28-EVK, Buildroot uses the Legacy build system (which is to be used up to u-boot 2015.04, but the config uses 2020.04) which does not allow the use of the make uboot-menuconfig command. You should safely be able to change that. You need to set the Build system to Kconfig and set the Board defconfig to mx28evk.

Using Pulse Width Modulation (PWM) interface in kernel module

I'm new in kernel development driver and I'm trying to develop a Linux kernel module, using the this module information:
http://lxr.free-electrons.com/source/drivers/pwm/pwm-tiehrpwm.c
But I didn't understand how to use it. How could adapt this module or better, how to create a new module using functions contained in this file like ehrpwm_pwm_config, ehrpwm_pwm_enable?
PS:I don't want to use sysfs, I would configure the pwm signal programmatically. I'm using a Beaglebone Black board running a Debian distribution , and cape-universaln.
Thanks
You need to enable CONFIG_PWM_TIEHRPWM in your .config file of your linux-kernel. By default, CONFIG_PWM_TIEHRPWM is not set and you need to enable it as CONFIG_PWM_TIEHRPWM=y, if you want to build it as a part of kernel image, or as CONFIG_PWM_TIEHRPWM=m, if you want to build it as a LKM.
Then, build your kernel as make -j12 and insmod your module as:
#insmod /lib/modules/$uname -r/drivers/pwm/pwm_tiehrpwm.ko if you have built it as a LKM. Check Linux kernel documentation on how to configure pwm!

How to add my source code to Kernel source tree

I've an I2C storage CHIP attached with system, A kernel space driver program of that CHIP is functioning with insmod / rmmod from running system.
But I would like to add this program with kernel source, so that on Kernel booting (from zImage) it will read from I2C CHIP, and Print something (e.g. Serial #) from it.
My question is, is it enough to add the driver object with kernel/Makefile
as obj-y += ?
while searching for Kernel module writing and so on, you'll find a hundreds of thousands "hello_world.c" program, that will describe how you can print
hello_world at kernel log, when your kernel and system all working and up. Which are called loadable kernel module, using program like insmod to load and rmmod to unload.
But, I was searching how to load my own script (i.e. that hello_world.c) when kernel is booting, and wanna see something on console that exactly coming from kernel at booting time, then google is almost silent.
Well, its just not difficult, and quite easy. What I've done by myself to get the printk() message at kernel booting is -
Kept the hello_world.c program inside ./kernel/driver (You can keep it almost anywhere inside Kernel source folder also can make your own folder, but that will require your own Makefile).
And edit the ./kernel/driver/Makefile to add obj-y += hello_world.o
at the end of the Makefile.
Then compile the full kernel and generated zImage transferred to sd-card.
While booting, just after USB HID core driver, I am able to see my custom message from hello_world printk().
[ 3.652944] usbcore: registered new interface driver usbhid
[ 3.657253] usbhid: USB HID core driver
[ 3.660152] HELLO: HELLOING WORLD from KERNEL BINARY
NOTE:- Unlike, loadable module, function maked with __exit would never called by compile when subjected code is in-built with kernel source.
i.e. in Such case hello_world.c is "Programmed to received (read include) but can't never leave"

Usb to Ethernet driver compilation on linux kernel 3.0 and above

I cross compiled USB to Ethernet driver in the Linux Kernel source tree at drivers/net/usb/smsc75xx.c for Android Kernel 3.0.8. Cross compilation worked fine as well as inserting the Kernel module using insmod. But the ethernet interface does not show up nor dmesg detects module's insertion (using insmod) or removal (using rmmod). Since dmesg is silent about its insertion or removal, something seems not right?
How to debug this non-working driver in a non-verbose environment?
Check the drivers/net/usb/smsc75xx.c. It seems the driver is already in the upstream.

Embedded Linux Porting On ARM-Cortex-A8(beagle board)

I am porting Embedded linux os on Beagle Board with ARM-Cortex A8 processor.
I wanted to add the functionality of insmod and rmmod and my driver as well in os.
Please help me in doing this, so that my driver can work over my board properly.
Thank you
Himanshi
You will Have to include Your drivers with the Image BUILD insmod and rmmod will not keep your driver there after a reboot inserting your drivers every boot sure is inappropriate

Resources