nxtv2.0 Posted October 8, 2016 Share Posted October 8, 2016 There are python libraries for the raspberry pi that use its dma channels to output pwm on any pin chosen? How do i get PWM out of the allwinner h3? In the allwinner h3 datasheet it says "12 dma channels". thanks in advance. Link to comment Share on other sites More sharing options...
StaLeWaR Posted October 9, 2016 Share Posted October 9, 2016 Unfortunately I have not seen such a library. A small community in the H3 devices. Link to comment Share on other sites More sharing options...
jock Posted October 10, 2016 Share Posted October 10, 2016 There is a python library to access the GPIO based on WiringPI/WiringOP around, but I didn't use the PWM feature. I successfully used this WiringOP fork (but this is only C) with software PWM: https://github.com/zhaolei/WiringOP You may give a try to wrap using ctypes python module to gain access to the C library from python. I didn't try the hardware PWM, Orange PI H3 devices have just one hardware PWM exposed via GPIO, and it has to be activated via script.bin Link to comment Share on other sites More sharing options...
tkaiser Posted October 10, 2016 Share Posted October 10, 2016 Orange PI H3 devices have just one hardware PWM exposed via GPIO AFAIK it's on the UART header so you have to deactive most probably uart0 too: http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=1153 Link to comment Share on other sites More sharing options...
fatboyatdesk Posted October 11, 2016 Share Posted October 11, 2016 Mainline Kernel has just received PWM patch for H3 for target release 4.9 possibly. http://www.gossamer-threads.com/lists/linux/kernel/2514899#2514899 https://patchwork.kernel.org/patch/9306623/ https://patchwork.kernel.org/project/linux-arm-kernel/list/?page=30 Link to comment Share on other sites More sharing options...
fatboyatdesk Posted October 11, 2016 Share Posted October 11, 2016 There is also code in their Matrix framework that shows how to use the PWM driver. I thought it would be a GPIO implementation but appears to use pwm Peripheral. This is on their Lichee so possibly needs a patch forArmbian. https://github.com/friendlyarm/matrix/blob/master/lib/pwm.c Link to comment Share on other sites More sharing options...
StaLeWaR Posted October 12, 2016 Share Posted October 12, 2016 It would be cool!!!I think if it will be possible to control neopixel. (ws2811, ws2812) Link to comment Share on other sites More sharing options...
Igor Posted October 12, 2016 Share Posted October 12, 2016 Added. I only test building. https://github.com/igorpecovnik/lib/commit/c47bdf2cc9d608470b1404484175c67f47344126 1 Link to comment Share on other sites More sharing options...
fatboyatdesk Posted October 12, 2016 Share Posted October 12, 2016 Added. I only test building. https://github.com/igorpecovnik/lib/commit/c47bdf2cc9d608470b1404484175c67f47344126 Thank you, Very much appreciated! There are many examples for their matrix code. which appear to be just shims around the kernel driver userland stuff here http://wiki.friendlyarm.com/wiki/index.php/Main_Page#Matrix I will try and test some ASAP. Link to comment Share on other sites More sharing options...
tkaiser Posted October 12, 2016 Share Posted October 12, 2016 I will try and test some ASAP. In case you already build you should retry, patch was not active (fixed now). You should also keep in mind that you might need adjustments to fex file (which might be in conflict with audio settings, see these changes and check for pin PA06) Link to comment Share on other sites More sharing options...
StaLeWaR Posted October 13, 2016 Share Posted October 13, 2016 how so? Last documentation H3 says that PA06 no pwm. It's a lie? Link to comment Share on other sites More sharing options...
tkaiser Posted October 13, 2016 Share Posted October 13, 2016 how so? Last documentation H3 says that PA06 no pwm. It's a lie? I don't know. Neither interested in PWM nor Audio but I can remember that FriendlyARM fiddled around PA06 for reasons unknown to me. Just wanted people looking into it save some time but can't answer any detail questions. Link to comment Share on other sites More sharing options...
StaLeWaR Posted October 13, 2016 Share Posted October 13, 2016 @fatboyatdesk There are the results? Link to comment Share on other sites More sharing options...
fatboyatdesk Posted October 14, 2016 Share Posted October 14, 2016 @fatboyatdesk There are the results? I tried last night. First i tried on FA's Lichee. I could get that running without errors . I didn't actuall hook up a LED to ensure the PWM was getting to the pin yet. But I can see driver load and test program thinks all is well. However for a fresh build that included the patch I see the driver loading but the library FAHW-Lib complains that it failed to set pwm. dmesg shows nothing more of use. I need to dig deep and gain a better understanding of driver installation. Link to comment Share on other sites More sharing options...
StaLeWaR Posted October 15, 2016 Share Posted October 15, 2016 I would be grateful if you write about your attempts Link to comment Share on other sites More sharing options...
fatboyatdesk Posted October 17, 2016 Share Posted October 17, 2016 Not much to add. Looking at the source it appears that the PWM initialized ok but the attempt to do ioctrol failed. One thing I noted is the pwm demo file is opened with read only which seems odd as it will be writing the PWM pin, duty cycle and period. if ((devFD = openHW("/dev/pwm", O_RDONLY)) == -1) { setLastError("Fail to open pwm device"); return -1; } if (ioctl(devFD, PWM_IOCTL_SET_FREQ, arg) == -1) { setLastError("Fail to set pwm"); // This is the message I see. closeHW(devFD); return -1; } I checked the fex file and there is entries there. I don't know how to check them... https://github.com/igorpecovnik/lib/blob/master/config/fex/nanopineo.fex Next thing up will be to recompile Armbian with RW. Also going to put an LED on PIN 6 to see some flashing. Also read the data sheet section on the PWM for the H3. Straightforward with not very many options if compared to a PIC Slow going as I am cutting my teeth on Linux Device Driver development. Will keep you posted. Also noted from the code the H3 is compiled the same for M1 and Neo. 2 PWM channels. Channel 1 is the on one on PA06/GPIO6. The other channel is on a pin used by UART0 RX so not possible to use console IO at the same time. Might try putting some printk statements in to see what the PWM driver shows. It also has a debug setting if I can figure out how to turn it on. Link to comment Share on other sites More sharing options...
erazor Posted November 12, 2016 Share Posted November 12, 2016 The manual states there is only one PWM so, any idea how a PWM1 is supposed to work? I tried to add pin stuff on the DTS and changed some lines in pwm-sun4i.c without success. I was able to export pwm1 and change duty and so on but it didn't change the LED. However exporting the GPIO and writing the value changed the LED state. Link to comment Share on other sites More sharing options...
fatboyatdesk Posted December 14, 2016 Share Posted December 14, 2016 So I managed to get back to this but am still unable to get the pwm working on the 3.4 kernel legacy build. I am trying pwm1 (H3 supports 0 and 1) on linux GPI0 5 and 6 respectively. PWM0 GPIO 5 is multiplexed with UART0_RX which is the uart for the serial console and therefore not available on the neo. the code loads the driver fine using modprob matrix-pwm and /dev/pwm is available. This file can be opened and the failure is on the ioctl call to set the frequency. Actually it is writing the pwm pin (linux 6), pwm index (1), frequency(period) and duty cycle All seems to work well until it hits the pwm_request call in the driver which fails. dmesg shows me "request pwm1 failed" which is coming from the driver. At this point I am stuck. I also loaded the FA lichee build to see if the pwm demo actually works on that. The program runs but I don't think it is actually making it to the pin as I can't get the LED to light. I can get the GPIO to output (neo 12) so not a pin numbering issue. Any suggestions appreciated. File /home/allan/armbianneo4.7.6/lib/patch/kernel/sun8i-default/matrix-support-Matrix-starter-kit.patch static int matrix_pwm_hw_init(int index, int pin)+{+ int ret=0;++#if 0+ ret = gpio_request(pin, DEVICE_NAME);+ if (ret) {+ printk("request gpio %d for pwm failed\n", pin);+ return ret;+ }+ gpio_direction_output(pin, 0);+#endif++ matrix_pwm[index] = pwm_request(index, DEVICE_NAME);+ if (IS_ERR(matrix_pwm[index])) {+ printk("request pwm%d failed\n", index);+#if 0+ gpio_free(pin);+#endif+ return -ENODEV;+ } Link to comment Share on other sites More sharing options...
fatboyatdesk Posted February 23, 2017 Share Posted February 23, 2017 There was a post on PWM for Legacy where the UART has to be disable due to multiplexing with the PWM.The post talked about tweaks to the .fex files and recompiling the kernel.https://github.com/igorpecovnik/lib/issues/498https://forum.armbian.com/index.php/topic/3611-nanopi-neo-pwm-pin/ Link to comment Share on other sites More sharing options...
DoubleHP Posted January 8, 2018 Share Posted January 8, 2018 How to improve handling of PWM: https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=200793 My tutorial to drive WS2812 with an Orange Pi zero: http://www.orangepi.org/orangepibbsen//forum.php?mod=viewthread&tid=3318&page=1&extra=#pid21903 Both links contain clues which may be usefull for those who are playing with the PWM, even if you are not driving LEDs. Link to comment Share on other sites More sharing options...
Recommended Posts