Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

fix support for recent pi models (Zero W etc) #100

Open
wants to merge 12 commits into
base: v2
Choose a base branch
from

Conversation

JamesGKent
Copy link

@JamesGKent JamesGKent commented Jul 28, 2017

this incorporates the fixes in Yackou's V2 branch that includes a more robust method of detecting the cpu on the pi to determine feature availability.
This includes updates for all known pi variants at this time.
I intend to test the following items before this pull request gets closed, if anyone can test any additional pi's or features it would be appreciated.

importable on:

  • pi zero w (9000c1 - BCM2835)
  • pi 3 (a02082 - BCM2835)
  • pi 2 (a01041 - BCM2835)
  • pi B (000e - BCM2835)

pwm functions on:

  • pi zero w
  • pi 3
  • pi 2
  • pi B

Yackou and others added 6 commits August 17, 2016 23:40
. Fix Raspberry Pi model detection
. Add model detection in GPIO module
. Try to fix mailbox char device detection on various kernels
. Fix compiler warnings
. Distinguish board revision from CPU model.
. Consider the board revision to be 3 (latest) by default.
. Use the CPU model (and not the board revision) to determine the GPIO base
address.
. Use the board revision to determine which pin/gpio mappings to use.
. Fix the pin to gpio mapping definition for revision 3 boards.
. Add all known models (according to http://elinux.org/RPi_HardwareHistory)
to the MODEL_DATA (sysinfo) definition.
. Only use the Pi revision (and no longer the sysinfo string) to determine
which GPIO list to use in the Python scripts.
added build recipes for python version 3.3, 3.4, 3.5 and 3.6, include directories may need to be changed if incorrect
@JamesGKent JamesGKent changed the title V2 fix support for recent pi models (Zero W etc) Jul 28, 2017
@JamesGKent
Copy link
Author

I've had a chance to test PWM on a pi zero W and somehow it completely locks up the pi, to the point where the console is completely unresponsive and all network traffic is dropped. not even a response to a ping.

@JamesGKent
Copy link
Author

ok so the problem is due to the base address used to control the GPIO in the pwm extension. in the main RPIO extension there are two defines for the peri_base address (BCM2708 and 2709) and a static integer to hold the one in use by the pi (depending on model) which is loaded in the call to setup, however this code does not appear in the PWM extension so only the BCM2708 base address is used which is wrong on newer pi models. I've manually changed the value to check that it works with the correct address, so no i will add the detection code.

the pwm extension was using the default 2708 base address no matter what pi was in use, leading to corrupted memory and freezing the pi.
Moved the cpuinfo files into a c_common directory so they can be used by both the RPIO extension and the PWM extension.
@JamesGKent
Copy link
Author

JamesGKent commented Jul 29, 2017

i have now tested pwm and normal functions on a pi 1B and a zero W at the latest commit level (ee17c8d) and both function normally, in addition when using an oscilloscope the pulses appear to be the right duration and frequency (saw one issue report claiming they were wrong?

@JamesGKent
Copy link
Author

can further report that the current method of determining the base memory address is wrong both in the main part of the module and in the original PWM module but in different ways. firstly the main module uses the revision to determine the base address, which on some of my Pi's gave an address of 0x2000000 where it should have given 0x3f00000 (pi 2 & 3)

however in the PWM module it was attempting to read the base address from a file in the filesystem, and using 0x2000000 as a fallback (not a bad thing) however the address retrieved from that file ended up wrong and created a handle to memory used for some other purpose, hence modifying it caused a crash.

I will attempt to work out why the file system method returns the wrong value (seems to be the suggested best practice?) however if that fails i will look at changing the address detection to something like this

@berknam
Copy link

berknam commented Aug 10, 2017

I have tried your v2 fork on Raspberry Pi 3B, but it was giving me an error "error: unknown type name ‘uint32_t’" on 'cpuinfo.h' and 'cpuinfo.c' when I tried to install.
After I added an #include <stdint.h> to 'cpuinfo.h' it worked! So far its working fine.

@hlc111
Copy link

hlc111 commented Oct 7, 2017

Hi James,

My name is Reik Hua, and i downloaded V2 from your respository: https://github.com/JamesGKent/RPIO/tree/v2
As you mentioned you have fixed pi zero W hang issue when use PWM.
But it seems still hang when i use it.
Could you kindly provide some information about it?

Thanks!

@hlc111
Copy link

hlc111 commented Oct 7, 2017

Sorry, it should be OK, because timestamp issue the RPIO not overwrite installed

@Yackou
Copy link

Yackou commented Nov 27, 2017

Hi,

I had to revisit this work on a newer kernel after a failed SD card forced me to reinstall.
Same comment as @berknam to compile/install.
Afterwards, everything worked fine, including PWM.

  • Pi 2 (a01041)
  • Kernel 4.9.59-v7+

Thanks!

@metachris
Copy link
Owner

Cool! I don't have time to work actively on RPIO anymore. Would you be interested in maintaining a fork, and I'll put a prominent link to it on top of the README?

Also would be great to test and merge support for Pi3, which I believe works in either the dev branch or other PRs.

@JamesGKent
Copy link
Author

@hlc111 sorry for not seeing this and replying sooner, using the PWM on DMA channel 0 i had the same crash, but if you use channel 1 or higher should be ok, please try this and report back?

@Yackou
Copy link

Yackou commented Nov 29, 2017

@metachris I wouldn't mind helping with pull requests and reviews, but I don't think I'd have time to maintain a fork and take care of releases all by myself either...

@JamesGKent If I'm not mistaken, your pull request seems to work on most Pi boards, provided a small #include fix is made, is that correct?

@JamesGKent
Copy link
Author

@Yackou I've made the include fix in another commit to this pull.
I've tested it on all Pi's i own and it appears to be fully functional as long as DMA channel 0 isn't used, using this on my Pi's seemed to cause a complete system freeze, but i wasn't sure where to even begin investigating why, may be OS specific? (debian and OSMC)

@adicarlo
Copy link

@JamesGKent sounds like the DMA channel 0 issue deserves its own ticket, no? Would hate to have that hold up a pull for this critical ticket...

I'd be happy to take a look at that if its filed separately with a sample snippet showing the lockup... just tag me somehow...

@Yackou
Copy link

Yackou commented Nov 30, 2017

Agree the DMA channel 0 issue should go into its own ticket.
I've seen reports that the DMA channel 0 may be in use when X is running. I'm running headless
so I cannot comment, except for the fact that channel 0 works on my board.

I was trying to find a way to determine which DMA channels are already used by the kernel, and I found this:
https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
https://stackoverflow.com/questions/29628602/how-to-allocate-dma-channel-in-user-space
=> Someday we should probably add a "get_channel" API that returns an available DMA channel.

@JamesGKent I haven't tested your last commit yet, but the diff is exactly the same as what I did, so I don't expect any issue. BTW, I am using PWM on a Pi2 (it's my main reason for using RPIO), so you can mark it as working (I do use the regular GPIO API as well).

@JamesGKent
Copy link
Author

@Yackou that would make sense about DMA 0, when i first noticed the crash i was working on a pi that was running a desktop (PIXEL) for unrelated reasons i ended up wiping and starting with a fresh image booting to command line (wanted more performance headroom and didn't need desktop) and the crash appeared to stop happening... i'll look into adding a get_channel function if i have time.

@Yackou
Copy link

Yackou commented Dec 1, 2017

@JamesGKent Actually, there might be a problem with your pull request, as I now get git errors when trying to check out your branch: in commit f861be9 (fix getting per_base for new pis in pwm extension), it looks like you turned 2 symlinks into files (conf.py, index.rst), or something similar (where you under windows maybe?). Linux git doesn't like that apparently...

Not sure why I didn't experience this before though.

@Yackou
Copy link

Yackou commented Dec 1, 2017

@JamesGKent FWIW, I think I have solved the symlink problem in my tree; check the branch JGK-v2.
(I had to play with "git config core.symlinks true" "git config core.symlinks false" and several hard resets to get it done).

@JamesGKent
Copy link
Author

most of my work has been either under windows or through the web interface, so entirely possible i broke it... as much as i like linux, too many things i use are windows only so i spend far more time on windows.

I've now got a little one at home so i get less time to tinker with things like this, but when i get a chance i'll try your branch and report back, although my original use case has vanished due to being unable to get a SPI device working (even though it looked right on a scope...) so driving everything through an arduino instead, including PWM

@Yackou Yackou mentioned this pull request Feb 27, 2018
@DEvil0000
Copy link

a02082 basic functionality works for me with your branch - thx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants