Problem switching between GPIO and PWM

Hi all,
I am working on a DC motor control application using the builtin PWM. I am using a an H-bridge to control a DC motor. I am using Pin 22 and Pin 21 on P9 to control the H-bridge.
When the motor is rotating in the forward direction, I need Pin21 to be in pwm mode and Pin22 to be a simple digital output. When the motor is rotating in the reverse direction I need Pin22 to be in pwm mode and Pin21 to be a simple digital output. So as the command to the motor changes I will have to alternate between the pins being in GPIO mode and PWM mode.
Working only with pin 22 I tried this:

#echo am33xx_pwm >$SLOTS #install pwm cape
#echo 2 > /sys/class/gpio/export #export pin 22 on P9 as gpio
#echo out >/sys/class/gpio/gpio2/direction #set pin as output
#echo 1 > /sys/class/gpio/gpio2/value #set pin high

I can set pin 22 high or low, works fine.
Then I configure pin 22 as a pwm output:

#echo 2 > /sys/class/gpio/unexport #unexport pin 22
#echo bone_pwm_P9_22 > $SLOTS #configure pin as PWM
#echo 10000 >/sys/devices/ocp.2/pwm_test_P9_22.14/period #set period
#echo 5000 >/sys/devices/ocp.2/pwm_test_P9_22.14/duty #set duty cycle

This also works fine, with a measured voltage of 1.7V as I have set the duty cycle to 50%.
But then:

#echo -8 >$SLOTS #remove the bone_pwm_P9_22 cape
#echo 2 > /sys/class/gpio/export #export pin 22 on P9 as gpio
#echo out >/sys/class/gpio/gpio2/direction #set pin as output
#echo 1 > /sys/class/gpio/gpio2/value #set pin high

Now I measure 0V at the pin regardless of how I set the value in gpio2.

Thanks for any help.
Monzie

So, which board is this?

Gerald

I have a beaglebone black

I forgot to mention I’m running Robert Nelson’s debian.