jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.76k stars 615 forks source link

Support for Raspberry Pi 5 #528

Open Puetz opened 8 months ago

Puetz commented 8 months ago

Hi,

I just got a Raspberry Pi 5 and am getting an error that my hardware revision is not supported.

Here is some hardware information from cat /proc/cpuinfo:

Hardware    : BCM2835
Revision    : c04170
Model       : Raspberry Pi 5 Model B Rev 1.0

I also ran this coding to get paddr=10, baddr=C0000000.

I hope someone can use this information to add a new hardware type and support for the Raspberry Pie 5 🙂 I unfortunately don't know C and have no clue about hardware, so I can't create a PR myself.

Best regards, Thomas

Gadgetoid commented 8 months ago

The Pi 5 has significant hardware changes that might make some of this library difficult or impossible to migrate. I’m not qualified to know exactly how bad it is, but the changes are significant enough that a straight hardware ID addition isn’t going to cut it. We need one of the wizards involved in writing or extending the core functionality of rp_ws281x to step in and give us the lowdown.

I’ve talked to folks at Pi about creating a PIO-backed WS281X library for RP1, but there’s no telling when it if that - or the tools to make it happen - will materialise.

jgarff commented 8 months ago

I've definitely been wanting to add support for that, if possible. Unfortunately, I don't yet have a RPi 5 to actually work on.

Jeremy

On Sat, Nov 4, 2023 at 5:14 AM Thomas Pötz @.***> wrote:

Hi,

I just got a Raspberry Pi 5 and am getting an error that my hardware revision is not supported.

Can someone please add support for the Raspberry Pi 5 or give me a guideline on how to do it myself? I'd greatly appreciate it.

Best regards, Thomas

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G3XJNYO3S4VOUTRPTTYCYPQ3AVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43ASLTON2WKOZRHE3TOMRYGY2TANQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Gadgetoid commented 8 months ago

I've definitely been wanting to add support for that, if possible.

Wow, of all the things I expected- it wasn't the big guns! I hope you're well.

Unfortunately, I don't yet have a RPi 5 to actually work on.

That's something I can probably fix if you want to give support a shot!

jgarff commented 8 months ago

Hi Phillip! I'm good, thanks! I'm on a waiting list to get a RPi 5, but I have no idea when it'll ship. I'm definitely willing to give support a shot. Sounds kinda fun. Any help you can offer is greatly appreciated!

On Mon, Nov 6, 2023 at 6:16 AM Philip Howard @.***> wrote:

I've definitely been wanting to add support for that, if possible.

Wow, of all the things I expected- it wasn't the big guns! I hope you're well.

Unfortunately, I don't yet have a RPi 5 to actually work on.

That's something I can probably fix if you want to give support a shot!

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1794804928, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55GY2FJAJXYR2DBDML4DYDDPJFAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJUHAYDIOJSHA . You are receiving this because you commented.Message ID: @.***>

zytegalaxy commented 7 months ago

@jgarff If you are in Us/Canada, I can send you a RPi5 to support the port and any other way I can support this. I am getting a similar issue:

raise RuntimeError(
RuntimeError: ws2811_init failed with code -3 (Hardware revision is not supported)
ebraraktas commented 7 months ago

Hi @jgarff , I tried to add HW spec and debug the library (with main.c after some modification for my led strip). I added the spec below:

    //
    // Raspberry Pi 5
    //
    {
        .hwver = 0xc04170,
        .type = RPI_HWVER_TYPE_PI5,
        .periph_base = PERIPH_BASE_RPI4,
        .videocore_base = VIDEOCORE_BASE_RPI2,
        .desc = "Pi 5 Model B - 4GB 1.0"
    },

where RPI_HWVER_TYPE_PI5 is defined as 4. And it failed to allocate memory in the lines below: https://github.com/jgarff/rpi_ws281x/blob/1f47b59ed603223d1376d36c788c89af67ae2fdc/ws2811.c#L939-L940 here is the dmesg output for that request:

[ 1884.471030] raspberrypi-firmware soc:firmware: Request 0x0003000c returned status 0x80000001

And ioctl errno corresponds to Invalid argument.

I know nothing about RPi (this is my first device) and mailboxes etc. but I tried to run a simpler code (info.c) in this library to identify the issue, and here is the output (I added Cannot get ... logs after failure):

root@raspberrypi:/home/ebraraktas/Projects/mailbox# ./build/test/info 
Firmware revision: Oct 18 2023 17:30:17
/home/ebraraktas/Projects/mailbox/src/fd.c:52:mailbox_property: error: ioctl: IOCTL_MBOX_PROPERTY: Invalid argument
Cannot get board model
/home/ebraraktas/Projects/mailbox/src/fd.c:52:mailbox_property: error: ioctl: IOCTL_MBOX_PROPERTY: Invalid argument
Cannot get board revision
/home/ebraraktas/Projects/mailbox/src/fd.c:52:mailbox_property: error: ioctl: IOCTL_MBOX_PROPERTY: Invalid argument
Cannot get mac address
Board serial: 0xc77d11596528bd61
ARM memory: 0x3f800000 bytes at 0x00000000
VC memory:  0x02100000 bytes at 0xfdb00000

And memflag.c(link) failed to allocate memory with the same errno, too.

I don't know if any of these helps to diagnose the issue, but I wanted to post my findings. If this issue seems to be resolved quickly, I would like to help it (but it seems way beyond my knowledge).

jgarff commented 7 months ago

That would be fantastic! I'm hoping to get a little time over the holidays to work on this a bit.

On Wed, Nov 8, 2023 at 11:22 AM Ubo Project @.***> wrote:

@jgarff https://github.com/jgarff If you are in Us/Canada, I can send you a RPi5 to support the port and any other way I can support this. I am getting a similar issue:

raise RuntimeError( RuntimeError: ws2811_init failed with code -3 (Hardware revision is not supported)

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1802422660, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G6US4J3ASQFP2KZOY3YDPEX5AVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBSGQZDENRWGA . You are receiving this because you were mentioned.Message ID: @.***>

zytegalaxy commented 7 months ago

Do you mind sending me an email to mehrdad@getubo.com so that I can arrange to have one shipped to you?

jgarff commented 7 months ago

I've now got hardware to play with. Many many thanks to @ubopod for the very generous donation! I've started looking into it, and have found the following so far:

I'll keep you guys posted with updates. Please be patient though, as I'm fairly busy, but hoping to work more on this over the holidays.

jgarff commented 7 months ago

Just a quick update.

mbevand commented 7 months ago

I was playing for a few hours with attempting (unsuccessfully) a port to work on the Pi 5.

I can confirm that most of the videocore firmware mailbox interfaces have been ripped out (https://forums.raspberrypi.com/viewtopic.php?t=359477) so definitely you need to drop that whole mechanism.

Another thing is the peripheral base address is now 0x107c000000 (instead of 0xfe000000 as on the Pi 4). I believe the new RP1 DMA/PIO will have to be configured through registers in that space, and because it's a base address over the 32-bit limit, you may need to #define _FILE_OFFSET_BITS 64 so that you can access it through /dev/mem

jgarff commented 7 months ago

Thanks @mbevand for the info. Since the RP1 is connected via PCIe, doesn't the base of the registers land in a PCIe BAR?

Region 0: Memory at 1f00410000 (32-bit, non-prefetchable) [size=16K]
Region 1: Memory at 1f00000000 (32-bit, non-prefetchable) [virtual] [size=4M]
Region 2: Memory at 1f00400000 (32-bit, non-prefetchable) [size=64K]

Are they remapping that somewhere else (0x107c000000?) in the rp1 driver?

mbevand commented 7 months ago

It doesn't conflict. Because the mapping goes from 0x107c000000 to 0x1080000000 while the BARs are much higher after 0x1f00000000

Per my understanding the mapping at 0x107c000000 is defined on line 90 here (the 64-bit value is represented as two 32-bit values "0x10 0x7c000000"): https://github.com/raspberrypi/linux/blob/29cc35f986a4e1e8671e68d0e363af636be243a2/arch/arm/boot/dts/bcm2712.dtsi#L90

jgarff commented 7 months ago

I'm not worried about a conflict. What I'm suggesting is that the peripherals that are built into the bcm2712 (dma/pcm/pwm/etc.) are no longer being used on the Pi5.

Instead the GPIOs are now wired to the RP1, not the SoC. The RP1 in turn is available to the SoC over PCIe, with all the registers mapped inside a RP1 BAR. Basically we can't use the peripherals in the 2712 anymore as they aren't wired to the actual pins anymore.

Seeing a schematic would be nice though. :)

mbevand commented 7 months ago

Doh! I wasn't thinking straight. You are right, of course. The register region at 0x107c000000 is useless to us. As you say, the RP1 PWM registers should be mapped inside a BAR region...

jgarff commented 7 months ago

No worries. I wish you were right. This would be much easier if the pins were still connected to the SoC IP.

mbevand commented 7 months ago

I don't know if that's useful or if you already know it, but the BAR can be accessed through sysfs. I wrote this sample code that shows how to read the FIFO_CTRL register of PWM0 on RP1. On my Pi 5 it prints FIFO_CTRL: 20000 since that's the default value of this register, as per page 39 of https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf . The RP1 is always at PCI address 0000:01:00.0, and the BAR region with the register is always resource1 so to access it:

#include <sys/ioctl.h>
#include <sys/mman.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>

#define OFFSET_PWM0 0x98000
#define OFFSET_PWM1 0x9c000

#define PWM_GLOBAL_CTRL 0x00
#define PWM_FIFO_CTRL   0x04

uint32_t my_read(void *base, ssize_t count, uint32_t offset)
{   
    assert(count == 4);
    return *(uint32_t *)((uint8_t *)base + offset);
}

int main() {
    const char *fname = "/sys/bus/pci/devices/0000:01:00.0/resource1";
    void *base;
    int fd;
    uint32_t reg;

    if (-1 == (fd = open(fname, O_RDWR | O_SYNC)))
        perror("open"), exit(1);
    // 0x400000 is the size in bytes of the "resource1" sysfs file
    base = mmap(NULL, 0x400000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (base == MAP_FAILED)
        perror("mmap"), exit(1);
    if (-1 == close(fd))
        perror("close"), exit(1);
    reg = my_read(base, 4, OFFSET_PWM0 + PWM_FIFO_CTRL);
    printf("FIFO_CTRL: %x\n", reg);
    return 0;
}
jgarff commented 7 months ago

Thanks. I'm well aware of these mechanisms. The tricky part isn't register access. It's the dma.

On Tue, Dec 5, 2023, 5:48 PM mbevand @.***> wrote:

I don't know if that's useful or if you already know it, but the BAR can be accessed through sysfs. I wrote this sample code that shows how to read the FIFO_CTRL register of PWM0 on RP1. On my Pi 5 it prints FIFO_CTRL: 20000 since that's the default value of this register, as per page 39 of https://datasheets.raspberrypi.com/rp1/rp1-peripherals.pdf :

include <sys/ioctl.h>

include <sys/mman.h>

include

include

include

include

include

include

define OFFSET_PWM0 0x98000

define OFFSET_PWM1 0x9c000

define PWM_GLOBAL_CTRL 0x00

define PWM_FIFO_CTRL 0x04

uint32_t my_read(void base, ssize_t count, uint32_t offset) { assert(count == 4); return (uint32_t )((uint8_t )base + offset); }

int main() { const char fname = "/sys/bus/pci/devices/0000:01:00.0/resource1"; void base; int fd; uint32_t reg;

if (-1 == (fd = open(fname, O_RDWR))) perror("open"), exit(1); base = mmap(NULL, 0x400000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (base == MAP_FAILED) perror("mmap"), exit(1); if (-1 == close(fd)) perror("close"), exit(1); reg = my_read(base, 4, OFFSET_PWM0 + PWM_FIFO_CTRL); printf("FIFO_CTRL: %x\n", reg); return 0; }

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1841892282, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G3QZE22TIHHP7R34DTYH66GVAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBRHA4TEMRYGI . You are receiving this because you were mentioned.Message ID: @.***>

O-O-O-84 commented 6 months ago

Hey guys, i've got the same issue. is there already a solution? Maybe an update for the RPI_WS281x?

ikke01 commented 6 months ago

I've now got hardware to play with. Many many thanks to @ubopod for the very generous donation! I've started looking into it, and have found the following so far:

  • Changing the hardware device ID is unfortunately insufficient to add support.
  • Using mailbox messages to allocate DMA coherent memory that we can access from userspace doesn't work apparently. I'm investigating, but this is likely due to API changes when communicating with the Videocore VII firmware (new in the RPi5). I could write a small kernel driver to map this type of memory to userspace, but I'm hoping to not have to do that.
  • The GPIOs now run through the new RPi5 RP1 chipset. Because of this they are not compatible with the previous PWM IP in the Broadcom SoC. Although, the RP1 has a neat IP that we can use instead. I'm looking into using the PIO controller in the RP1 along with DMA. I just need to get a cache free userspace buffer to work from.

I'll keep you guys posted with updates. Please be patient though, as I'm fairly busy, but hoping to work more on this over the holidays.

Hallo Jeremy, did you make any progress on this for the PI5, we are looking forward to it if you can fix it to get it working again. Thanks Raymond

jgarff commented 6 months ago

Hi Raymond, I was able to work on this some over the holidays. I have some open questions in a developer forum regarding the DMA that I'm hoping can be answered. Unfortunately, the specs available thus far are lacking in specific functionality of the RP1. Some of which are tied up behind non-public specifications for intellectual property from third parties used in the RP1.

ikke01 commented 6 months ago

Thank you for your fast response, let hope they respond, this makes the use of the pins not very usefull anymore if the cannot be addressed as in the PI4 and older versions.

Raymond

From: Jeremy Garff @.> Sent: Tuesday, 2 January 2024 17:18 To: jgarff/rpi_ws281x @.> Cc: Raymond Garnier @.>; Manual @.> Subject: Re: [jgarff/rpi_ws281x] Support for Raspberry Pi 5 (Issue #528)

Hi Raymond, I was able to work on this some over the holidays. I have some open questions in a developer forum regarding the DMA that I'm hoping can be answered. Unfortunately, the specs available thus far are lacking in specific functionality of the RP1. Some of which are tied up behind non-public specifications for intellectual property from third parties used in the RP1.

— Reply to this email directly, view it on GitHubhttps://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1874238059, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEFBLSKPAHWAAME4OIUC74TYMQXLDAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZUGIZTQMBVHE. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>

mehrdadfeller commented 6 months ago

@jgarff Thanks again for the efforts! I hope the necessary information come out soon. If you link to relevant developer forum questions here, we can collectively try to get that information for Raspberry Pi. I have a few contacts in the commercial side and can also ask around to get more attention to it.

jgarff commented 6 months ago

That would be great @mehrdadfeller. The specific questions I have are as follows:

jgarff commented 6 months ago

https://forums.raspberrypi.com/viewtopic.php?t=361457

GuyPerets106 commented 5 months ago

Hi , I'm following this issue. First of all , big thanks to @jgarff for working on this issue. Secondly , I saw this product from Adafruit - https://learn.adafruit.com/adafruit-neodriver-i2c-to-neopixel-driver?view=all that seemingly should allow NeoPixel to run on devices and microcontrollers which does not support it. Maybe I don't understand all the technical details , but someone can verify it can work on the RPi 5 until the current issue gets resolved? Thanks.

danic85 commented 5 months ago

Hi , I'm following this issue. First of all , big thanks to @jgarff for working on this issue. Secondly , I saw this product from Adafruit - https://learn.adafruit.com/adafruit-neodriver-i2c-to-neopixel-driver?view=all that seemingly should allow NeoPixel to run on devices and microcontrollers which does not support it. Maybe I don't understand all the technical details , but someone can verify it can work on the RPi 5 until the current issue gets resolved? Thanks.

I'm using this on a Raspberry Pi 5 currently, so I can confirm it does work. https://www.makerforge.tech/posts/pi5-build-log-4/#neopixel-i2c-support

madmongoose commented 5 months ago

Hi , I'm following this issue. First of all , big thanks to @jgarff for working on this issue. Secondly , I saw this product from Adafruit - https://learn.adafruit.com/adafruit-neodriver-i2c-to-neopixel-driver?view=all that seemingly should allow NeoPixel to run on devices and microcontrollers which does not support it. Maybe I don't understand all the technical details , but someone can verify it can work on the RPi 5 until the current issue gets resolved? Thanks.

I'm using this on a Raspberry Pi 5 currently, so I can confirm it does work. https://www.makerforge.tech/posts/pi5-build-log-4/#neopixel-i2c-support

Hi! My bad, I installed not as sudo. Could you please provide your script for test?

danic85 commented 5 months ago

Hi , I'm following this issue. First of all , big thanks to @jgarff for working on this issue. Secondly , I saw this product from Adafruit - https://learn.adafruit.com/adafruit-neodriver-i2c-to-neopixel-driver?view=all that seemingly should allow NeoPixel to run on devices and microcontrollers which does not support it. Maybe I don't understand all the technical details , but someone can verify it can work on the RPi 5 until the current issue gets resolved? Thanks.

I'm using this on a Raspberry Pi 5 currently, so I can confirm it does work. https://www.makerforge.tech/posts/pi5-build-log-4/#neopixel-i2c-support

Hi! My bad, I installed not as sudo. Could you please provide your script for test?

The sample code in Guy's link works for me - I have a more complex implementation but that isn't needed for the basic functionality.

Would still be great to see this repo working on the Pi 5 as the i2c module is a bit of a workaround for the issue for me.

madmongoose commented 5 months ago

Hi , I'm following this issue. First of all , big thanks to @jgarff for working on this issue. Secondly , I saw this product from Adafruit - https://learn.adafruit.com/adafruit-neodriver-i2c-to-neopixel-driver?view=all that seemingly should allow NeoPixel to run on devices and microcontrollers which does not support it. Maybe I don't understand all the technical details , but someone can verify it can work on the RPi 5 until the current issue gets resolved? Thanks.

I'm using this on a Raspberry Pi 5 currently, so I can confirm it does work. https://www.makerforge.tech/posts/pi5-build-log-4/#neopixel-i2c-support

Hi! My bad, I installed not as sudo. Could you please provide your script for test?

The sample code in Guy's link works for me - I have a more complex implementation but that isn't needed for the basic functionality.

Would still be great to see this repo working on the Pi 5 as the i2c module is a bit of a workaround for the issue for me.

Thanks for reply.

Maybe it doesn't work for me because I connect led through this board to rpi5.

Screenshot 2024-01-09 at 14 31 27

What bus number you used?

Gadgetoid commented 5 months ago

the specs available thus far are lacking in specific functionality of the RP1

It's not much use in the near term, but I am discussing (with Pi) the feasibility of WS281x support, or perhaps some userspace tools and interfaces to make it possible, that leverages the RP1's PIO. It's not a "no", but more a "this will be complicated and requires some thought and a fair bit of work."

I remain optimistic, since there's a desire to show off the RP1's PIO, that the Pi 5 will be able to support WS281x strips on arbitrary pins using a simple PIO program and the same DMA-a-bunch-of-carefully-crafted-bytes trick we use currently. This could potentially even extend to custom PIO code to emit the correct pulses for 1s/0s, but right now I can only really speculate based on a few brief discussions of our requirements.

Sorry I didn't get a Pi 5 out to you quickly- I am absolutely mired in getting everything else to work!

mehrdadfeller commented 5 months ago

@Gadgetoid That's great! I am trying to get some support from Raspberry Pi on this as well and I am also optimistic that they will come out with something cool.

BTW, do you know what clock speed these PIOs can toggle at? If RP1 on Pi 5, could support DMA on arbitrary PINs, does that mean you can drive multiple long strips in parallel as well? I wonder what is the bottleneck...

@danic85 @madmongoose: I might be mistaken but I think I2C speed (400KHz) could limit how fast you can drive LED strips but it works for many applications. This won't be noticeable if you are showing static patterns but if you are transitioning fast between colors/patterns or you are piping too much on long strips, DMA can offer must faster transfer speeds. Also, with DMA you don't need the extra hardware (MCU) in between.

Thee's another type of LED that Adafruit calls DotStart that you do not have to do DMA. Adafruit NeoPixel is the terminology used for WS281X LEDs. There's a good comparison here.

I have always used WS281X LEDs because they are much cheaper (<$0.01 at large volumes), you can buy them easily in various types of packagings (right angle, fused lens, etc).

madmongoose commented 5 months ago

@mehrdadfeller hi! I can't use a led without MCU in between, because https://github.com/Freenove/Freenove_Robot_Dog_Kit_for_Raspberry_Pi

I built this constructor instead of the recommended rpi4 on rpi5, corrected the code a bit, replaced GPIO with gpiozero. Servo drives, buzzer, ultrasonic work well. All that's left is to fix the led. =)

jgarff commented 5 months ago

the specs available thus far are lacking in specific functionality of the RP1

It's not much use in the near term, but I am discussing (with Pi) the feasibility of WS281x support, or perhaps some userspace tools and interfaces to make it possible, that leverages the RP1's PIO. It's not a "no", but more a "this will be complicated and requires some thought and a fair bit of work."

I remain optimistic, since there's a desire to show off the RP1's PIO, that the Pi 5 will be able to support WS281x strips on arbitrary pins using a simple PIO program and the same DMA-a-bunch-of-carefully-crafted-bytes trick we use currently. This could potentially even extend to custom PIO code to emit the correct pulses for 1s/0s, but right now I can only really speculate based on a few brief discussions of our requirements.

Sorry I didn't get a Pi 5 out to you quickly- I am absolutely mired in getting everything else to work!

Thanks Gadgetoid! I was planning on actually using the new PIO to do this as it will be more flexible, allow for more GPIO ports, and sounds fun anyway. We can also leverage some of the microcode for it from the microcontroller projects.

The questions I have open (without reply unfortunately) are with regard to getting the DMA working with the PIO controller. Would you mind involving me in your discussions with Raspberry Pi? I would greatly appreciate it, and would very much like to be involved. Thanks!

orsemdev commented 5 months ago

the specs available thus far are lacking in specific functionality of the RP1

It's not much use in the near term, but I am discussing (with Pi) the feasibility of WS281x support, or perhaps some userspace tools and interfaces to make it possible, that leverages the RP1's PIO. It's not a "no", but more a "this will be complicated and requires some thought and a fair bit of work." I remain optimistic, since there's a desire to show off the RP1's PIO, that the Pi 5 will be able to support WS281x strips on arbitrary pins using a simple PIO program and the same DMA-a-bunch-of-carefully-crafted-bytes trick we use currently. This could potentially even extend to custom PIO code to emit the correct pulses for 1s/0s, but right now I can only really speculate based on a few brief discussions of our requirements. Sorry I didn't get a Pi 5 out to you quickly- I am absolutely mired in getting everything else to work!

Thanks Gadgetoid! I was planning on actually using the new PIO to do this as it will be more flexible, allow for more GPIO ports, and sounds fun anyway. We can also leverage some of the microcode for it from the microcontroller projects.

The questions I have open (without reply unfortunately) are with regard to getting the DMA working with the PIO controller. Would you mind involving me in your discussions with Raspberry Pi? I would greatly appreciate it, and would very much like to be involved. Thanks!

Hi there,

I have just switched from my Raspberry Pi 2 --> Raspberry Pi 5 and my ws2812b scripts are no longer running without an error (Hardware revisions not supported). I assume that the problem is the outdated library, do you have any updates on the update for Raspberry Pi 5?

Thanks.

zytegalaxy commented 5 months ago

@orsemdev this issue is blocked due to lack of documentation on certain features of RP1 chip that handles IO on Raspberry Pi 5. We need to wait til the specs are released.

felixfeliciz commented 5 months ago

Until then, is there any way to use the WS2812B with a limited range of functions, such as simple switching on and off or simple color changes without fancy gradients or animations?

felixfeliciz commented 5 months ago

Until then, is there any way to use the WS2812B with a limited range of functions, such as simple switching on and off or simple color changes without fancy gradients or animations?

without using Adafruit NeoDriver - I2C to NeoPixel Driver

jgarff commented 5 months ago

Unfortunately no. Setting any color at all requires transferring a complicated sequence of signals over the wire. The timing required for these signals isn't possible from a software only implementation on Linux due to context switches, driver interrupts, etc..

On Wed, Jan 17, 2024 at 4:25 PM felixfeliciz @.***> wrote:

Until then, is there any way to use the WS2812B with a limited range of functions, such as simple switching on and off or simple color changes without fancy gradients or animations?

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1897423871, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55G4J56P375UBL3ZOGW3YPBMXZAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXGQZDGOBXGE . You are receiving this because you were mentioned.Message ID: @.***>

zytegalaxy commented 5 months ago

I have not personally tried that but you could potentially use SPI option which should not pose any issues on Pi 5. I believe the issue is using DMA mainly which can be used to do fast PWM/PCM.

Since I use an LCD display on SPI bus already that is not an option for me but that could work in your case if you are not currently using it to drive something else.

On Wed, Jan 17, 2024, 3:28 PM felixfeliciz @.***> wrote:

Until then, is there any way to use the WS2812B with a limited range of functions, such as simple switching on and off or simple color changes without fancy gradients or animations?

without using Adafruit NeoDriver - I2C to NeoPixel Driver

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1897437915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWNI3HATELOTVBGSJ527T73YPBNCJAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXGQZTOOJRGU . You are receiving this because you were mentioned.Message ID: @.***>

jgarff commented 5 months ago

That's a great idea as well! I haven't tried it, and I know the SPI hardware is also different on the RPi5, but in theory it should be able to output the right waveform.

On Wed, Jan 17, 2024 at 4:34 PM Ubo Project @.***> wrote:

I have not personally tried that but you could potentially use SPI option which should not pose any issues on Pi 5. I believe the issue is using DMA mainly which can be used to do fast PWM/PCM.

Since I use an LCD display on SPI bus already that is not an option for me but that could work in your case if you are not currently using it to drive something else.

On Wed, Jan 17, 2024, 3:28 PM felixfeliciz @.***> wrote:

Until then, is there any way to use the WS2812B with a limited range of functions, such as simple switching on and off or simple color changes without fancy gradients or animations?

without using Adafruit NeoDriver - I2C to NeoPixel Driver

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1897437915,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/AWNI3HATELOTVBGSJ527T73YPBNCJAVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXGQZTOOJRGU>

. You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/jgarff/rpi_ws281x/issues/528#issuecomment-1897463969, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB55GY2WQC4B3C7JD6ZGZ3YPBNX7AVCNFSM6AAAAAA65QFT3CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJXGQ3DGOJWHE . You are receiving this because you were mentioned.Message ID: @.***>

cleverca22 commented 5 months ago

Need to get access to the synopsys DMA controller documentation.

https://github.com/cleverca22/rp1-kernel-example/blob/23fcd99ef40d2968d22f29cd808634814cc6d584/rp1-kernel-test.c#L80-L106

this is an example of using all of the proper kernel api's to manage the dma controller

Need to get the channel mappings for each peripheral (PWM/PIO/etc.) as it relates to the DMA. These are typically used for things like flow control/backpressure/etc. This is how the DMA controller knows that the given channel FIFO is full and whatnot. It's hard to know the specifics without the DMA docs though.

https://github.com/librerpi/rp1-lk/blob/757fbcb8f2554643989aac719e0cdb56a052f247/platform/rp1/pio.c#L48 this is a pio uart example that pairs up with that

https://github.com/MichaelBell/rp1-hacking/blob/main/PIO.md this documents most of the pio differences

https://github.com/MichaelBell/rp1-hacking/blob/main/launch_core1/core1_test.c and this temporarily hijacks core0 to get rp1-lk running on core1

the biggest issue, is that the PIO control registers are up at 0xf000_0000 in the private peripherals of the cortex-m3 pair and there is currently no proper way to gain control of either M3 core1_test.c will overwrite some of the assembly in core0's firmware, so when a main control loop gets to that function, it runs some custom assembly, which can kick-start core1

rp1-lk is then a fairly standard cortex-m style binary, with the initial sp/cp at the start, and core1_test.c will launch that on core1 that then configures the PIO for whatever your desired task is, and enables DREQ

then the rp1-kernel-example can rig up dma and perform copies to/from the fifo's

i'm currently working on a logic analyzer type project, and i can get it to capture up to 581mbit from PIO

you can also find me over at ##raspberrypi-internals on libera if you want some more realtime questions

oh, and also read jdb's statement at https://forums.raspberrypi.com/viewtopic.php?p=2181672#p2181672

jgarff commented 5 months ago

This is great information @cleverca22, thank you. It's unfortunate however that the Cortex-M3's are required to read/write the PIO registers, which necessitates the need to get them involved. I'll dig into the links you've provided.

For what it's worth, I do have a lot of Cortex-M microcontroller experience, so I at least know how that works. If you're curious, I have a OS that I wrote specifically for Cortex-M parts (mostly Atmel) here: https://github.com/westerndigitalcorporation/FissionOS.

Thanks again.

ethomas997 commented 5 months ago

I hope support for the Pi 5 can be resolved. Over at our RotorHazard Race Timer project we depend on this library for running LED strips and panels.

cleverca22 commented 5 months ago

@jgarff having a second look at the rp1 datasheet, the PWM block has a serializer mode, like the bcm SoC's

so it should just be a matter of rigging up dma to feed duty-cycles to the pwm controller and putting it in serializer mode the pwm dreq channel is in include/dt-bindings/mfd/rp1.h along with all of the other dreq's

jgarff commented 5 months ago

Yeah, I've thought about that as well. Do you think it's possible to use the DMA to write to the PIO registers to setup the PIO without having to go through the Cortex-Ms? I don't like messing with the Cortex-M's if they're used for things like fan speed control, resets, and whatnot. Obviously using the DMA to write registers is inefficient, but would mean not having to use the Cortex-Ms.

MichaelBell commented 5 months ago

Unfortunately as far as we can tell the PIO can only be configured directly from the Cortex-Ms.

Given what @cleverca22 and I have done so far it would be fairly easy to make a kernel module that patched the code on the Cortex-M to configure the PIO with a ws2812 pio program, and then exposed a character device that you could use to DMA data to the PIO SM.

But the patching is very fragile and likely break with future firmware updates - it's not really suitable for something that lots of people are likely to use. We really need Raspberry Pi to give us some kind of mechanism to safely perform this configuration - until then it's possible to make a demo, but not really something that would be wise to distribute widely.

In the meantime, PWM ought to be a reasonable stop gap solution, although it obviously only works on some of the available header pins.

jgarff commented 5 months ago

Yeah, using the PWM is one of the methods that we used to support the previous Raspberry Pis.

cleverca22 commented 5 months ago

I don't like messing with the Cortex-M's if they're used for things like fan speed control, resets, and whatnot.

luckily, only core 0 is used for the fan rpm (and some unknown pcie duties) the fan pwm is entirely linux hitting pwm regs directly

core 1 is entirely unused but you need to temporarily hijack core0, to get core1 bootstrapped

cleverca22 commented 5 months ago

oh, and i forgot about @G33KatWork 's older stuff, before @MichaelBell found the core0 hack

https://github.com/G33KatWork/RP1-Reverse-Engineering

basically, you can just hard-reset the entire RP1, and re-load the core0 and core1 firmware over i2c, and reboot it that would have better compatibility with the core0 firmware both because your not patching it, and because you choose which core0 version is in use

but linux currently doesnt handle removal of the rp1 cleanly so you need a dtoverlay that disables the rp1, reset it, then a runtime dtoverlay to allow rp1 access and you can only do that once per host boot, so linux has to reboot to do it again

given that hard-reset, it would best be done from the initrd, before linux needs to mount any usb rootfs and it would be best to have a flexible core1 payload, that can do different jobs