Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPI4 PWM can't be used with Windows11 #1640

Open
ChesterHuang999 opened this issue Aug 19, 2021 · 12 comments
Open

RPI4 PWM can't be used with Windows11 #1640

ChesterHuang999 opened this issue Aug 19, 2021 · 12 comments
Labels
area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins blocked Issue/PR is blocked on something - see comments Priority:3 Work that is nice to have tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly

Comments

@ChesterHuang999
Copy link

ChesterHuang999 commented Aug 19, 2021

Describe the bug
When I execute the Sample code, I get an error message like the following.

Unhandled exception. System.ArgumentException: No PWM device exists for PWM chip at index 0. (Parameter 'chip')
at System.Device.Pwm.Channels.Windows10PwmChannel..ctor(Int32 chip, Int32 channel, Int32 frequency, Double dutyCycle)
at System.Device.Pwm.PwmChannel.CreateWindows10PwmChannel(Int32 chip, Int32 channel, Int32 frequency, Double dutyCyclePercentage)
at System.Device.Pwm.PwmChannel.Create(Int32 chip, Int32 channel, Int32 frequency, Double dutyCyclePercentage)
at GPIOTry.Program.Main(String[] args) in D:\Chester\Project\RPI4\Windows\GPIOTry\GPIOTry\Program.cs:line 16

I changed the boot/config.txt according to "https://github.com/dotnet/iot/blob/main/Documentation/raspi-pwm.md",
But the same problem still occurs.

// put sample code here
using System;
using System.Device.Gpio;
using System.Device.I2c;
using System.Device.Spi;
using System.Device.Pwm;
using System.Threading;
namespace GPIOTry
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var gpiocontroller = new GpioController();
            
            PwmChannel pwmcontroller = PwmChannel.Create(0,0,400,0);
            pwmcontroller.Start();
            gpiocontroller.OpenPin(2, PinMode.Output);
            byte bringth = 0;
            try
            {
                while (true)
                {
                    bringth++;
                    if (bringth == 11)
                        bringth = 0;
                    pwmcontroller.DutyCycle=bringth*0.1;
                    gpiocontroller.Write(2, PinValue.High);
                    Console.WriteLine("Duty is " + bringth.ToString());
                    Console.WriteLine("Set GPIO2 High");
                    Thread.Sleep(1000);
                    gpiocontroller.Write(2, PinValue.Low);
                    Console.WriteLine("Set GPIO2 Low");
                    Thread.Sleep(1000);
                }
            }
            finally
            {
                pwmcontroller.Stop();
                gpiocontroller.ClosePin(2);
            }
        }
    }
}

Platform: RPI4B
OS: Windows11
System.Device.Gpio: 1.5.0
@ChesterHuang999 ChesterHuang999 added the bug Something isn't working label Aug 19, 2021
@ghost ghost added the untriaged label Aug 19, 2021
@krwq
Copy link
Member

krwq commented Aug 19, 2021

@ChesterHuang999 Windows 11 is not supported at the moment. I'm not sure how could you have changed /boot/config.txt which is linux file on Windows 11... I believe the only scenarios which will work on Window at the moment are:

  • Windows IoT Core - @joperezr do you perhaps remember if you have to do anything special for PWM?
  • using GPIO/SPI/I2C with devices such as FT4222
  • using GPIO/SPI/I2C Firmata

then once you get I2C you can get Pca9685 for PWM.

I don't think anyone of us have tried to make it work with Win11 but supposedly we could make Linux /dev/mem implementation work on Windows with some tiny modifications... cc: @joperezr @Ellerbach @pgrawehr @raffaeler in case any of you have tried Win 11 on PI already

@raffaeler
Copy link
Contributor

Sorry, I did not try Win11 on the PI.

FWIW in my projects I always use a small external PWM card as I found to be more reliable (because of the timings) than the internal RPi PWM.

@pgrawehr
Copy link
Contributor

@ChesterHuang999 Please describe exactly on what kind of hardware and operating system you were trying to run the code. There's no PWM hardware on typical Windows desktop PCs, and there's no Windows 11 for Raspberry Pi.

@joperezr
Copy link
Member

[Triage]: If you could share steps on how to install windows 11 on Pi4 then we can try to get a repro environment and investigate.

@ChesterHuang999
Copy link
Author

ChesterHuang999 commented Aug 20, 2021

Thank you all for your replies.

The hardware platform is RPI4 B which ram is 4GB.
Hardware details: https://www.raspberrypi.org/products/raspberry-pi-4-model-b/

First, in addition to PWM, I experimented using "System.Device.GPIO" to control GPIO. The GPIO can work normally.

For how to install Windows 11 on RPI4, please refer to:
https://www.tomshardware.com/how-to/install-windows-11-raspberry-pi

@krwq "I'm not sure how could you have changed /boot/config.txt which is linux file on Windows 11"
When you have an SD Card made according to "https://www.tomshardware.com/how-to/install-windows-11-raspberry-pi". Use the "WoR-Boot-Mounter" program, you can Modify "Boot\Config.txt".
It is possible to modify Config.txt because I have to modify it to adjust the default output screen resolution.

@raffaeler
Copy link
Contributor

@ChesterHuang999 I rapidly read the article and, at a certain point, it says "The Raspberry Pi’s onboard Wi-Fi, Bluetooth and GPIO do not work so you’ll need to use Ethernet or a USB Wi-Fi dongle to get online".
If there are those limitations, they will also affect PWM as well. I can't exclude there may be a way to enable them (as raspiconfig does under Linux) but I have no clue how to do it under Windows.

BTW, you could give a try with Windows 10 and see if this is a Win11 specific issue or, as I believe, you need the "Windows IoT" specific SKU to make the peripheral work.

@pgrawehr pgrawehr added blocked Issue/PR is blocked on something - see comments arch-arm64 area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins and removed bug Something isn't working untriaged labels Aug 21, 2021
@pgrawehr
Copy link
Contributor

I think there's nothing we can do here, until the low-level drivers are in place.

@fkromer
Copy link

fkromer commented Oct 25, 2021

Relates to this issue: #1705

@Ellerbach
Copy link
Member

@ChesterHuang999 as @pgrawehr and @raffaeler wrote, there is no PWM drivers. So this is not supported on an already not supported scenario (Windows 11 on the Raspberry Pi). So changes you have to make it working are quite low honestly. Any strong reason why Windows on this non supported scenario and why not simply Raspberry Pi OS?

@raffaeler
Copy link
Contributor

One more point. This thread was created before the RTM Windows build.
I never tried Windows on a RPi, but it would definitely be better to test the latest available build and not relying on a pre-release.

Said that, there is a third-party project that I never tested and found by surfing the web. I don't know the author and it has nothing to do with Microsoft of Raspberry PI Foundation.
He created a website to run Windows on the Raspberry PI and the following is his repository: https://github.com/worproject/RPi-Windows-Drivers
GitHub marked the author as "Verified" but frankly I don't know what does this imply.
On his repository there is a list of drivers, including the PWM one. They are unsigned (this is a reason for me to not trust them) but you may eventually download the sources and compile+sign by yourself if you trust the sources.
The damage would eventually be restricted to just the RPi, but be aware of the potential risks.
All of this is out of support and not recommended or endorsed.

@pgrawehr
Copy link
Contributor

@raffaeler Pretty complex task to get that installed, but since Windows 11 will (very likely) be officially available for ARM64 (see here: https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewARM64) we should start investigating this setup. Not sure if I find time to do this, but it does sound interesting.

@raffaeler
Copy link
Contributor

Yes, it sounds complicated but it looks like being the only practical solution at the moment.
I am not familiar with the previous support in Windows 10, but I would expect those drivers to be provided by the Windows team (if they will continute to support the RPi HW in the IoT scenario).

As it is definitely interesting, I'll investigate as well and see.

@krwq krwq added tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly Priority:3 Work that is nice to have labels Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins blocked Issue/PR is blocked on something - see comments Priority:3 Work that is nice to have tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Projects
None yet
Development

No branches or pull requests

7 participants