Port-arm archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Support for PWM on RPI3 GPIO
thorpej%me.com@localhost (Jason Thorpe) writes:
>I see thereâ??s a â??bcmpwmâ?? driver, but Iâ??m not sure itâ??s what I wantâ?¦ Nothing appears to actually use it, as far as I can tell, and there doesnâ??t seem to be any API *to* use it, nor any obvious documentation on its function.
Since FDT'ization, the driver isn't usuable and you would need the
clock driver too that got junked. Both abstract only a little bit
from the hardware, you want to read BCM2835-ARM-Peripherals.pdf for
the hardware details.
The driver also wasn't exposed to userland and can conflict with
the vcaudio driver.
>Anybody have some advice for me?
The GPIO pin (18 left, 19 right) must be set to alternate
function 5 to route the PWM engine to the GPIO pin. Unfortunately
the GPIO driver works only from userland and doesn't configure
alternate functions. I had a patch somewhere....
This would have been kernel code to configure the PWM engine.
struct bcm_pwm_channel *pwm;
uint32_t oldctl, olddiv, mode, range, value, div;
/* Clock out 10 bits per value with 3 "on" and 7 "off" */
range = 10;
value = 3;
/* reserve channel and return handle (vcaudio "should" do similar) */
pwm = bcm_pwm_alloc(0); # 0 left, 1 right
/* save PWM clock */
bcm_cm_get(BCM_CM_PWM, &oldctl, &olddiv);
/* must stop PWM clock before configuring it */
bcm_cm_set(BCM_CM_PWM, CM_CTL_KILL, 0);
/* Configure clock for OSC = 19.2MHz, PWM = range * 800 kHz */
div = 19200000 / (range * 800000);
bcm_cm_set(BCM_CM_PWM, CM_CTL_SRC_OSCILLATOR | CM_CTL_ENAB, div << 12 | 0);
/* initialize defaults (i.e. "off") */
bcm_pwm_control(pwm, 0, 32);
/* PWM mode, mark space mode, true polarity, no FIFO, silence is 'off' */
mode = PWM_CTL_MSEN;
/* set mode and enable channel, set range */
bcm_pwm_control(pwm, mode | PWM_CTL_PWEN, range);
/* write PWM value to channel 0 */
bcm_pwm_set(pwm, value);
.....
/* turn hardware off */
bcm_pwm_control(pwm, 0, 32);
/* restore saved clock */
bcm_pwm_control(BCM_CM_PWM, oldctl, olddiv);
/* release channel */
bcm_pwm_free(pwm);
--
--
Michael van Elst
Internet: mlelstv%serpens.de@localhost
"A potential Snark may lurk in every tree."
Home |
Main Index |
Thread Index |
Old Index