Firefly Open Source Community

   Login   |   Register   |
New_Topic
12
New Topic
Print Previous Topic Next Topic

Hardware pwm in user space

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105

Hardware pwm in user space

Posted at 12/18/2015 05:33:15      View:7469 | Replies:10        Print      Only Author   [Copy Link] 1#
Hi there
http://wiki.t-firefly.com/index.php/Firefly-RK3288/PWM/en
That guide describes only kernel space.
How to control hardware pwm in user space?
/sys/class/pwm doesn't exist
Is there a way to enable sysfs pwm interface?
Thanks
Reply

Use props Report

2442

Credits

0

Prestige

0

Contribution

vip

Rank: 6Rank: 6

Credits
2442
Posted at 12/18/2015 08:59:44        Only Author  recommend
there is no ready-made  pwm in user space, need to write  interface by youself, just like the backlight's.
Reply

Use props Report

2442

Credits

0

Prestige

0

Contribution

vip

Rank: 6Rank: 6

Credits
2442
Posted at 12/23/2015 08:59:46        Only Author  recommend

[ 1716.354256] [<c028a3f4>] (pwm_config+0x40/0x60) from [<bf036050>] (x_init+0x50/0xc0 [sysfs])
[ 1716.362695] [<bf036050>] (x_init+0x50/0xc0 [sysfs]) from [<c00086a4>] (do_one_initcall+0x34/0xc8)

make sure your pwm0 is not NULL.
Reply

Use props Report

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105
Posted at 12/20/2015 20:06:22        Only Author  3#
ok. i did it. I wrote a linux kernel module. when I tried insmode i got error in function pwm_config: Unable to handle kernel paging request at virtual address fffffe0b
dmesg

  1. [ 1715.682095] rock-pwm [I]: Start module
  2. [ 1715.682185] rock-pwm [I]: Pwm request
  3. [ 1715.682222] rock-pwm [I]: Pwm request: success!
  4. [ 1715.682252] rock-pwm [I]: Pwm config
  5. [ 1715.682341] Unable to handle kernel paging request at virtual address fffffe0b
  6. [ 1715.689537] pgd = ed784000
  7. [ 1715.692594] [fffffe0b] *pgd=2e7f6821, *pte=00000000, *ppte=00000000
  8. [ 1715.698963] Internal error: Oops: 17 [#1] PREEMPT SMP ARM
  9. [ 1715.704320] Modules linked in: sysfs(+) mali_kbase
  10. [ 1715.709186] CPU: 3 PID: 1712 Comm: insmod Not tainted 3.10.0 #46
  11. [ 1715.715147] task: ec42ee00 ti: ec858000 task.ti: ec858000
  12. [ 1715.720569] PC is at pwm_config+0x40/0x60
  13. [ 1715.724586] LR is at x_init+0x50/0xc0 [sysfs]
  14. [ 1715.728938] pc : [<c028a3f4>]    lr : [<bf036050>]    psr: 60070013
  15. [ 1715.728938] sp : ec859f10  ip : 00000000  fp : 00000000
  16. [ 1715.740269] r10: 00000000  r9 : ec858000  r8 : c0d80000
  17. [ 1715.745442] r7 : 00000000  r6 : ec858000  r5 : bf036000  r4 : 0007a120
  18. [ 1715.751898] r3 : 000f4240  r2 : 00000000  r1 : fffffdfb  r0 : fffffdfb
  19. [ 1715.758376] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
  20. [ 1715.765425] Control: 10c5387d  Table: 2d78406a  DAC: 00000015
  21. [ 1715.771110]
  22. [ 1715.771110] PC: 0xc028a374:
  23. [ 1715.775350] a374  e3530000 03a03002 05803054 059f3004 05803058 eaffff3e c028a2e0 eafffd29
  24. [ 1715.783621] a394  e3500000 15801014 03e00015 13a00000 e12fff1e e3500000 15900014 e12fff1e
  25. [ 1715.791872] a3b4  e1a03002 e2702001 e92d4010 33a02000 e1a04001 e1a01000 e1922fa4 13e00015
  26. [ 1715.800121] a3d4  18bd8010 e3530000 c3a02000 d3a02001 e1540003 c3822001 e3520000 1a000005
  27. [ 1715.808370] a3f4  e5910010 e590200c e592c008 e1a02004 e12fff3c e8bd8010 e3e00015 e8bd8010
  28. [ 1715.816617] a414  e1a02001 e2501000 e92d4008 0a00000c e5910010 e590300c e3530000 0a000008
  29. [ 1715.824864] a434  e593300c e3530000 03e00025 08bd8008 e591c004 e31c0004 1a000003 e12fff33
  30. [ 1715.833113] a454  e8bd8008 e3e00015 e8bd8008 e3e0000f e8bd8008 e5903010 e5d30024 e12fff1e
  31. [ 1715.841366]
  32. [ 1715.841366] SP: 0xec859e90:
  33. [ 1715.845603] 9e90  00000000 60070013 00000000 c002f8fc 00000000 00000000 00000000 00000000
  34. [ 1715.853849] 9eb0  c0d9c8d0 c028a3f4 60070013 ffffffff ec859efc c000d598 fffffdfb fffffdfb
  35. [ 1715.862096] 9ed0  00000000 000f4240 0007a120 bf036000 ec858000 00000000 c0d80000 ec858000
  36. [ 1715.870341] 9ef0  00000000 00000000 00000000 ec859f10 bf036050 c028a3f4 60070013 ffffffff
  37. [ 1715.878586] 9f10  bf0342d8 bf036050 bf034170 c00086a4 bf036000 00000000 bf034170 00000003
  38. [ 1715.886827] 9f30  b6f1c398 0000017b c000db84 c0080d34 bf034170 00000000 00000000 00000003
  39. [ 1715.895072] 9f50  b6f1c398 c00819bc f1a21000 00000fa5 f1a21664 f1a21551 f1a21e5c 000002e8
  40. [ 1715.903319] 9f70  000003d8 00000000 00000000 00000000 00000017 00000018 0000000f 00000000
  41. [ 1715.911576]
  42. [ 1715.911576] R0: 0xfffffd7b:
  43. [ 1715.915813] fd78  ******** ******** ******** ******** ******** ******** ******** ********
  44. [ 1715.924113] fd98  ******** ******** ******** ******** ******** ******** ******** ********
  45. [ 1715.932363] fdb8  ******** ******** ******** ******** ******** ******** ******** ********
  46. [ 1715.940619] fdd8  ******** ******** ******** ******** ******** ******** ******** ********
  47. [ 1715.948871] fdf8  ******** ******** ******** ******** ******** ******** ******** ********
  48. [ 1715.957116] fe18  ******** ******** ******** ******** ******** ******** ******** ********
  49. [ 1715.965368] fe38  ******** ******** ******** ******** ******** ******** ******** ********
  50. [ 1715.973620] fe58  ******** ******** ******** ******** ******** ******** ******** ********
  51. [ 1715.981867] fe78  ******** ******** ******** ******** ******** ******** ******** ********
  52. [ 1715.990123]
  53. [ 1715.990123] R1: 0xfffffd7b:
  54. [ 1715.994360] fd78  ******** ******** ******** ******** ******** ******** ******** ********
  55. [ 1716.002609] fd98  ******** ******** ******** ******** ******** ******** ******** ********
  56. [ 1716.010859] fdb8  ******** ******** ******** ******** ******** ******** ******** ********
  57. [ 1716.019114] fdd8  ******** ******** ******** ******** ******** ******** ******** ********
  58. [ 1716.027364] fdf8  ******** ******** ******** ******** ******** ******** ******** ********
  59. [ 1716.035609] fe18  ******** ******** ******** ******** ******** ******** ******** ********
  60. [ 1716.043858] fe38  ******** ******** ******** ******** ******** ******** ******** ********
  61. [ 1716.052112] fe58  ******** ******** ******** ******** ******** ******** ******** ********
  62. [ 1716.060364] fe78  ******** ******** ******** ******** ******** ******** ******** ********
  63. [ 1716.068617]
  64. [ 1716.068617] R6: 0xec857f80:
  65. [ 1716.072853] 7f80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  66. [ 1716.081097] 7fa0  00000000 00000000 00000000 00000000 2e7f3841 2e7f3c41 00000000 00000000
  67. [ 1716.089340] 7fc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  68. [ 1716.097587] 7fe0  00000000 00000000 00000000 00000000 00000000 00000000 2e7f6821 2e7f6c21
  69. [ 1716.105833] 8000  00000002 00000001 00000000 ec42ee00 c0d03af8 00000003 00000015 ec42ee00
  70. [ 1716.114079] 8020  c1ef1f40 ec858000 ed417180 00000000 0000018f ee19d500 ec859cb4 ec859c30
  71. [ 1716.122321] 8040  c079ce74 00000000 00000000 00000000 00000000 00000000 01000000 00000000
  72. [ 1716.130566] 8060  b6f00850 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  73. [ 1716.138807]
  74. [ 1716.138807] R8: 0xc0d7ff80:
  75. [ 1716.143044] ff80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  76. [ 1716.151283] ffa0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  77. [ 1716.159526] ffc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  78. [ 1716.167769] ffe0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  79. [ 1716.176011] 0000  00000000 c1ed1cb2 c0957b4f eda5c800 c1ed1c00 00000000 00000000 00000000
  80. [ 1716.184262] 0020  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  81. [ 1716.192507] 0040  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  82. [ 1716.200757] 0060  00000000 00000000 00000000 00000000 00000000 00000000 00275b8f 00000000
  83. [ 1716.209002]
  84. [ 1716.209002] R9: 0xec857f80:
  85. [ 1716.213238] 7f80  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  86. [ 1716.221481] 7fa0  00000000 00000000 00000000 00000000 2e7f3841 2e7f3c41 00000000 00000000
  87. [ 1716.229728] 7fc0  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  88. [ 1716.237974] 7fe0  00000000 00000000 00000000 00000000 00000000 00000000 2e7f6821 2e7f6c21
  89. [ 1716.246219] 8000  00000002 00000001 00000000 ec42ee00 c0d03af8 00000003 00000015 ec42ee00
  90. [ 1716.254465] 8020  c1ef1f40 ec858000 ed417180 00000000 0000018f ee19d500 ec859cb4 ec859c30
  91. [ 1716.262717] 8040  c079ce74 00000000 00000000 00000000 00000000 00000000 01000000 00000000
  92. [ 1716.270964] 8060  b6f00850 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  93. [ 1716.279226] Process insmod (pid: 1712, stack limit = 0xec858238)
  94. [ 1716.285169] Stack: (0xec859f10 to 0xec85a000)
  95. [ 1716.289494] 9f00:                                     bf0342d8 bf036050 bf034170 c00086a4
  96. [ 1716.297579] 9f20: bf036000 00000000 bf034170 00000003 b6f1c398 0000017b c000db84 c0080d34
  97. [ 1716.305661] 9f40: bf034170 00000000 00000000 00000003 b6f1c398 c00819bc f1a21000 00000fa5
  98. [ 1716.313743] 9f60: f1a21664 f1a21551 f1a21e5c 000002e8 000003d8 00000000 00000000 00000000
  99. [ 1716.321825] 9f80: 00000017 00000018 0000000f 00000000 0000000c 00000000 bee8c6b4 bee8c834
  100. [ 1716.329907] 9fa0: 8dec7500 c000da00 bee8c6b4 bee8c834 00000003 b6f1c398 00000000 00000000
  101. [ 1716.337989] 9fc0: bee8c6b4 bee8c834 8dec7500 0000017b b6f28ee0 00000000 b6f18b60 00000000
  102. [ 1716.346071] 9fe0: bee8c660 bee8c650 b6f13177 b6e81982 80070030 00000003 00000000 00000000
  103. [ 1716.354256] [<c028a3f4>] (pwm_config+0x40/0x60) from [<bf036050>] (x_init+0x50/0xc0 [sysfs])
  104. [ 1716.362695] [<bf036050>] (x_init+0x50/0xc0 [sysfs]) from [<c00086a4>] (do_one_initcall+0x34/0xc8)
  105. [ 1716.371523] [<c00086a4>] (do_one_initcall+0x34/0xc8) from [<c0080d34>] (do_init_module+0x44/0x168)
  106. [ 1716.380401] [<c0080d34>] (do_init_module+0x44/0x168) from [<c00819bc>] (SyS_finit_module+0x6c/0x94)
  107. [ 1716.389374] [<c00819bc>] (SyS_finit_module+0x6c/0x94) from [<c000da00>] (ret_fast_syscall+0x0/0x30)
  108. [ 1716.398323] Code: e1540003 c3822001 e3520000 1a000005 (e5910010)
  109. [ 1716.405119] ---[ end trace 6daea3937796a980 ]---
Copy the code


in this module i use code from example http://wiki.t-firefly.com/index.php/Firefly-RK3288/PWM/en  :
struct pwm_device *pwm0=NULL;
pwm0= pwm_request(0, "backlight-pwm");
pwm_config(pwm0, 500000, 1000000);

What is wrong?
Reply

Use props Report

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105
Posted at 12/23/2015 18:11:55        Only Author  5#
pwm_request() used  to return bad structure because device name was incorrect .
Thank you for your answers , but i have some more questions)
1. In dts file I found, that pwm1 used by pwm_regulator. Is it safe to disable this device?
2. Is it possible to use pwm2 and pwm3? How to assign them with the pins?

P.S. sorry for my bad english

Reply

Use props Report

2442

Credits

0

Prestige

0

Contribution

vip

Rank: 6Rank: 6

Credits
2442
Posted at 12/25/2015 09:21:59        Only Author  6#
pwm_regulator is disabled, pwm1 can be used by yourself.
pwm2 and pwm3 can also be used, enable them in dts file as  pwm1.
Reply

Use props Report

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105
Posted at 12/28/2015 05:51:25        Only Author  7#
Last edited by Key In 12/28/2015 05:53 Editor

I need to achieve 10000 microseconds period.
pwm_config(1000000,10000000) didn't work(
How to change timer resolution?
Reply

Use props Report

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105
Posted at 12/29/2015 17:43:14        Only Author  8#
ok. prescale parameter is calculating in pwm-rockchip driver automatically. there is no reason to recalculate.
but...
When I set a period more than 850 microseconds,  something strange is happening.
For example I set a period of 900 microseconds(pwm_config(500000,900000)). but according to oscilloscope real period is 450 microseconds. Is there a way to fix it?
Reply

Use props Report

82

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
82
Posted at 1/4/2016 11:05:38        Only Author  9#
Hi,
You can use this pwm-rockchip.c (see attachment) to replace the /kernel/drivers/pwm/pwm-rockchip.c, then recompile, this is can be normal use, the main reason is that # define PWMDCR_MAX_DUTY length is too small。

pwm-rockchip.zip

3.9 KB, Down times: 10

Reply

Use props Report

105

Credits

0

Prestige

0

Contribution

registered members

Rank: 2

Credits
105
Posted at 1/11/2016 23:14:00        Only Author  10#
madman Posted at 1/4/2016 11:05
Hi,
You can use this pwm-rockchip.c (see attachment) to replace the /kernel/drivers/pwm/pwm-rockchi ...

hi, madman. it's not working(
I got 670 microsends period with pwm_config parameters: duty: 1600000, period: 2000000...

P.S. I tried to put the printk("test_pwm\n") code in each pwm_config function in pwm-rockchip.c, but the message didn't appear in dmseg... wtf
Reply

Use props Report

Return to List
12
You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list