Use PWM and UART at the same time

Hello,

I am developing a ROS project and I am using Ubuntu 16.04.1 on Beaglebone Black with 4.4.23-ti-r51 kernel.
I have a setup which uses the following pins:

Analog: P9_40, P9_39, P9_38, P9_37, P9_36
PWM: P9_16, P8_13
UART2, UART4 ,
GPIO: P9_41

In /boot/uEnv.txt I only have the line cape_universal=enable

and in /etc/default/capemgr
CAPE=cape-universaln

as a result cat /sys/devices/platform/bone_capemgr/slots command reports:
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,cape-universaln

I am using Adafruit_BBIO library to control PWM and ADC and UART.

With the above settings ADC and PWM works fine, but not UART…
Although /dev/ttyO2 and /dev/ttyO4 are present it doesn’t work.

If I, on the other hand, if I add on /boot/uEnc.txt the following
cape_enable=bone_capemgr.enable_partno=BB-UART2,BB-UART4,BB-PWM1,BB-PWM2

Then UART ports are fine, but PWM has the following error.
Traceback (most recent call last):
File “/home/ubuntu/catkin_ws/src/robot_core/scripts/wheel_controller.py”, line 17, in
PWM.start(LEFT_MOTOR_PIN, PWM_DUTY_CYCLE, PWM_NEUTRAL_FREQUENCY, 1)
RuntimeError: Problem with the cape manager

I am having trouble understanding dts files in order to create my own overlay.
Also when i tried to run config-pin i get command not found
and with sudo sh -c “echo ‘BB-UART2’ > /sys/devices/platform/bone_capemgr/slots” i get sh: echo: I/O-error

i am a bit confused!

With the above settings ADC and PWM works fine, but not UART...
Although /dev/ttyO2 and /dev/ttyO4 are present it doesn't work.

You have to set the pins to the proper pinmux values for UART and PWM,
not just load the overlay.

I am having trouble understanding dts files in order to create my own overlay.
Also when i tried to run config-pin i get command not found

You are running a non-standard distribution. The universal overlays
are part of the BBB kernels, but the config-pin utility is probably
not getting installed. Just grab it from github:

...or you can directly play with the sysfs entries created by the overlay.

and with sudo sh -c "echo 'BB-UART2' > /sys/devices/platform/bone_capemgr/slots"
i get sh: echo: I/O-error

This generally means the cape couldn't be loaded. You can sometimes
find more detail at the end of dmesg output, but failures when trying
to load capes are usually pretty cryptic.

and with sudo sh -c “echo ‘BB-UART2’ > /sys/devices/platform/bone_capemgr/slots”
i get sh: echo: I/O-error

This generally means the cape couldn’t be loaded. You can sometimes
find more detail at the end of dmesg output, but failures when trying
to load capes are usually pretty cryptic.

I’ve seen this happen several time when loading a cape, that is trying to configure pins that have already been configured. For me, this happened after unloading the previous cape. There still seems to be a “bug” when unloading capes.

You have to set the pins to the proper pinmux values for UART and PWM,
not just load the overlay.

How do you suggest i should enable all the pins needed?
If i try to enable BB-PWM0,1,2 overlays pwm still doesn’t work from Adafruit_BBIO library…

You are running a non-standard distribution. The universal overlays
are part of the BBB kernels, but the config-pin utility is probably
not getting installed. Just grab it from github:

https://github.com/cdsteinkuehler/beaglebone-universal-io

…or you can directly play with the sysfs entries created by the overlay.

I will try this also…
I hope i will eventually find out how.

Should i report this “bug” somewhere?

No, I think it's a known issue already.

Use the universal overlay. I created it specifically because it is
difficult or impossible to load several of the individual overlays for
various functions (like PWM and UART) because they conflict.

...or craft your own custom overlay with exactly what you want, but
that is a fairly high barrier to entry for most users. The universal
overlay allows selecting specific pin functions on a per-pin basis,
while enabling most of the commonly used special hardware features.

So if this continues to be a problem for you. Once you unload a cape, you should instead just reboot. This is not ideal, but it’s what we have right now . . .

What I did was take a couple of Charles' universal IO capes, and strip out
what I did not need, then combine what I needed into two files. So, I have
all 3 "dual channel" PWMs, and UART4 working in the same file.

So like if a pin had the ability to be muxed 5, or 6 different ways. I only
left the one I needed, then changed that one to "default" for the pinmux
naming. Do also keep in mind I did not get this right the first time, I had
to experiment a few times. . . . So you should experiment youself(
Theodosis ) to get a better understanding of what's going on.

I tried twice to implement my own overlay but I gave up because I had a significant lack of knowledge at this point.

Finally i used cape-universala (in which pwm works fine) and enabled uart2 and uart4 pins by using config-pin.
Now it works! (hope nothing else has broken!)

Thank you very much!

one last question:
pins enabled using config-pin command are enabled until reboot.

how can i keep these pins after reboot?

there. Which will be applied at boot.

Thank you again!

Theodosis, did you get it to work?
I have a small test.sh file containing
#!/bin/bash config-pin P9.11 uart

I tried both, systemd and rc.local, but in both cases i get “P9_xx pinmux file not found”.
If I run the script after logging in everything works fine.