0

"documentation" on Banana Pi Zero M2 is so chaotic it's even funny. goal: get PWM working.

so I installed armbian, waited a week till my usb OTG cable came (because you'll just fail default SSH into it), configured ssh and followed steps in here to install modified wiring pi -- gpio utility. I can confirm setting pin L/H works.

next step is to verify PWM works, so here fun begins. pinout looks to be the same as on Raspberry Pi and so they claim: enter image description here

I designed my board with last RPI 0 I had and I was using pin GPIO 12 (wiringPi 1) so I did:

# gpio mode 1 pwm
the pin you choose is not surport hardware PWM
you can select PA6 for PWM pin
or you can use it in softPwm mode

so as you can read it's not 'surpot' and I should try PA6.

no idea what is PA6 so I was searching and found this on-the-topic thread.

so I set :

# gpio mode 7 pwm
you choose the hardware PWM:1

and it informed me I have choosen PWM:1 whatever that should mean. (1 being on?) sure enough I tried to set duty cycle and waited to see my led come on, but just like the gentleman in the foermentioned thread I got:

# gpio pwm 7 100
val pwmWrite 0 <= X <= 1024
Or you can set new range by yourself by pwmSetRange(range

error that doesn't change with ducy cycle value I input it with.

next best bet I found got me to adding pwm overlay, activating pwm, setting period and duty cycle. commands passed without an error but LED did not light up. as suggested at the begginging of the tread in limitations, my PWM line is now connected to GPIO 15 (UART_TXD) --is this correct??.

this is my armbianEnv.txt

# cat /boot/armbianEnv.txt 
verbosity=1
bootlogo=false
console=both
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
rootdev=UUID=986b3dcb-01f8-4965-8a16-03b55c7341fd
rootfstype=ext4
overlays=i2c0 pwm w1-gpio
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

and I just have noticed i2c0 and w1-gpio were added to overlays probably by armbian-config utility so that might be ok.

but if you ask me:

root@bananapim2zero:~# ls /boot/dtb/ | grep pwm
root@bananapim2zero:~# ls /boot/dtb-6.1.11-sunxi/ | grep pwm

shows no such overlay so I don't know.

at the end, I would like to make sense of all that abbreviations as: PA, all the GPIO pin names listed in here mean, I mean there seem st be some logic in there, but I just don't know why are there two separate tables that prefix those names once with CON2- then CON3- following P{0-24} like there would be two different GPIOs? Why and what is UART jumper?

and mainly: how do I get PWM work? i2c and w1 to follow.

I'm sure answers will shed light to many more lost ones looking for RPI replacement.

Thanks!

greengold
  • 103
  • 4

1 Answers1

0

alright got it.

yesterday late night I didn't notice 3 separate pins outside of GPIO 40pin header that vendor marked as UART: enter image description here

mind you, there are 2 different UARTs you can find: enter image description here

gpio utility points you to the one of them: enter image description here but that's just visually, if you noticed, pin that you set as PWM: 7 is not marked as such. at least it is not lying in the output. and it's not working, on either so no cigar; i would just wonder why is that cause i can see dev bontago has adapted the utility specifically for this board purposes.

to strip the pinout confusion, the Rx UART pin from the side of the memory card is your PWM as marked on first picture.

here you can find how you enable and work with PWM on OS level:

# activate the PWM. On H3 only 1 PWM is supported, so exporting PWM 0
echo 0 > /sys/class/pwm/pwmchip0/export
# set period to 10ms
echo 10000000 > /sys/class/pwm/pwmchip0/pwm0/period
# set normal polarity. needs to be reset explicitly. Bug?
echo "inversed" > /sys/class/pwm/pwmchip0/pwm0/polarity
echo "normal" > /sys/class/pwm/pwmchip0/pwm0/polarity
# enable the PWM
echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable
# set duty cycle to 1ms
echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle
  • yes, you PWM starts as 1 so, you need to export it, set 'normal' polarity first and then you can operate as you are used to

# uname -a Linux bananapim2zero 6.1.11-sunxi #23.02.2 SMP Sat Feb 18 05:52:53 UTC 2023 armv7l GNU/Linux

greengold
  • 103
  • 4