BBB autostart and PWM config

Hi,

I am having trouble with configuring my PWM at start-up.
A C progam b1, which include the setup of the PWMs, is called at start-up by a System Service.
The cape get well installed. But the periods, duty cycles and polarity won’t be set correctly.

  • If I restart the service afterwards, it works !
  • I tried adding awfully long delays inside the c program (like 30 seconds), thinking that maybe the device tree was not yet set fully. But still, it doesn’t work.

My debug imagination reachs its limits. Any idea, suggestion would be much appreciated :slight_smile:

Here are the details:

`
BeagleBoard.org BeagleBone Debian Image 2014-05-14
Rev board: A6A

`

slots details:

`
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
7: ff:P-O-L Override Board Name,00A0,Override Manuf,GPIO-Cape
8: ff:P-O-L Override Board Name,00A0,Override Manuf,am33xx_pwm
9: ff:P-O-L Override Board Name,00A0,Override Manuf,bone_pwm_P9_14
10: ff:P-O-L Override Board Name,00A0,Override Manuf,bone_pwm_P9_22
11: ff:P-O-L Override Board Name,00A0,Override Manuf,bone_pwm_P8_13

`

Anybody has a clue ?

The cape manager is well installed but a C program run by the system service at bootup will not access the PWM device tree correctly.
How are you guys doing ? I would believe I am not the first person starting some PWM at boot up.

Have a good day

Anybody has a clue ?

The cape manager is well installed but a C program run by the system service at bootup will not access the PWM device tree correctly.
How are you guys doing ? I would believe I am not the first person starting some PWM at boot up.

Start by telling us which OS, OS Version, Kernel Version and then tell us what you tried and what results you got.

Regards,
John

Actually all the details were given in the first message.
I even had the impression that I put too much of details and made it unreadable … which may explain why I didn’t get any answer :slight_smile:

Let me know if you need any detail which is not in the initial message.

Find out the proper service to make it start after using After= for example (will not solve yours) After=systemd-user-sessions.service There is a bunch of things for much further control I would recommend further reading of systemd service files. For example you have no Type You have things like Wants= Requires= Things like Requires= does not imply After=

Thanks Don for the suggestions.

I tried different flavours:
1- relative delays: start after (what I believe to be) late services

`
After=syslog.target network.target

`

2- absolute delays:

`
ExecStartPre=/bin/sleep 60
TimeoutSec=100s

`

3- including large delays inside C before reaching the device trees.

None worked. It’s like it is not linked to the timing…
Could some access grant stuff be defined at the time the service is scheduled, rather than at the time the service actually starts ?

Or is my C code not adequate ?

`
fd_len = snprintf(buf, sizeof(buf), “%s/period”, “/sys/devices/ocp.3/pwm_test_P9_14.16”);
fd = open(buf, O_WRONLY);
if (fd < 0) {
perror(“pwm/period”);
printf(“pwm/period, %s”, buf);
return fd;
}

`

Additional help would be much appreciated :slight_smile:

FYI, the problem got resolved by adding delays between the individual PWM cape activation and the first access to their directories. Had to be around 500ms.
Thanks.