I am working to expose PWM capabilities in Python on the Beagle Bone, which uses the AM3358 processor. I'm basing my work on Alex Hiam's PyBBIO library, which I have successfully used to manipulate the device's GPIOs. As you can see, Alex uses the mmap module to directly access system memory through the mounted /dev/mem device.
My own forked code is viewable here. The PWMSS requires more configuration than the GPIO subsystem. I was experiencing a bus error when reading or writing from PWMSS memory until I came across this post by Alex which helped me see how to enable the module's clock. I'm able to do so, and to subsequently read from the PWMSS registers.
However, while setting those registers' values does not produce errors, the values don't appear to be written and the system doesn't alter its behavior. You can find my attempts to manipulate the registers in the _init() function of this file, but the simplest example is probably this: having written 0x2 to CM_PER_EPWMSS1_CLKCTRL to enable the clock (see constants below), the following behavior is observed:
>>> _getReg(EPWM1+EPWM_CMPA)
0
>>> _setReg(EPWM1+EPWM_CMPA, 0xffff)
>>> _getReg(EPWM1+EPWM_CMPA)
0
_getReg() and _setReg() are known to work both for initializing CM_PER_EPWMSS1_CLKCTRL and for manipulating the GPIO subsystem. My suspicion is that I'm failing to initialize some vial part of the PWMSS, but at this point I have no idea what. Could anyone offer advice about what I'm missing? I'd be grateful for any insights you can provide.
I've also posted about this to the Beagle Board mailing list -- if any of the above is unclear, this thread might be helpful.
constants:
MMAP_OFFSET = 0x44c00000 # base address of registers
MMAP_SIZE = 0x48ffffff-MMAP_OFFSET # size of the register memory space
EPWM1 = 0x48302200-MMAP_OFFSET
EPWM_CMPA = 0x12
CM_PER_BASE = 0x44e00000 - MMAP_OFFSET
CM_PER_EPWMSS1_CLKCTRL = CM_PER_BASE + 0xcc