• Re: Baremetal programiing the Pimoroni Tiny2040 RGB LED

    From Single Stage to Orbit@3:633/10 to All on Saturday, January 17, 2026 15:04:30
    On Sun, 2026-01-11 at 18:52 +0000, Daniel James wrote:


    However: There is a section on hardware PWM in the Pico-series C/C++
    SDK, have you seen that?

    Oh interesting, I can take a look at that. Hopefully the sources will
    clarify what's required.

    I confess it's not something I've played with, but it doesn't look
    too impenetrable ... it doesn't require PIO programming (something
    else I haven't played with yet) like another example I found.

    No, you're right, thankfully I don't need to go down that PIO rabbit
    hole yet. Just to demysterify how to do the PWM in assembly.

    I'm not sure how long ago I downloaded this SDK so it may not be
    quite current ... but it's section 4.1.18 on P249.

    If you used a capable search engine you might stumble across this:

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

    which seems to shed some light ...

    Thanks.
    --
    Tactical Nuclear Kittens


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michael Schwingen@3:633/10 to All on Sunday, January 18, 2026 10:32:40
    On 2026-01-17, Single Stage to Orbit <alex.buell@munted.eu> wrote:
    I'd suggest to have a look at the manual and SDK and see how to do it
    from C then hand translate the C code into ASM...

    I've found the following:

    https://github.com/thejpster/rp-hal-rp2350-public/blob/main/rp235x-hal/examples/pwm_blink.rs

    Why not go to the primary source?

    I believe the RP2xx0 datasheet has all you need in the PWM chapter (CH 4.5
    for RP2040, or CH 12.5 for RP2350).

    There is a list of registers with all the relevant bits explained.

    The funny thing is that the Pimoroni tiny2040 that I also have has a
    RGB LED on it, there's no data sheet for it but it appears to be
    reversed, in that all the GPIO pins attached to this LED are all active
    low, (i.e ~R GPIO18, ~B GPIO19, ~G GPIO20) so works in the opposite way
    to the LED on GPIO 25 on rp2040!

    This is quite common - they probably used a 4-pin LED package with common anode, so you have to drive the individual lines low to activate the LED.
    You could use 3 external inverters or transistors to make them active high,
    but why bother (the parts cost money and take up PCB space) when all it
    takes to fix this is a single line of code on the software side?

    cu
    Michael
    --
    Some people have no respect of age unless it is bottled.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Daniel James@3:633/10 to All on Sunday, January 18, 2026 12:37:31
    On 17/01/2026 15:21, Single Stage to Orbit wrote:
    The funny thing is that the Pimoroni tiny2040 that I also have has a
    RGB LED on it, there's no data sheet for it but it appears to be
    reversed, in that all the GPIO pins attached to this LED are all active
    low, (i.e ~R GPIO18, ~B GPIO19, ~G GPIO20) so works in the opposite way
    to the LED on GPIO 25 on rp2040!

    Did you read Pimoroni's own website entry for that part?

    https://shop.pimoroni.com/products/tiny-2040

    where it says:

    *Notes*

    * The RGB LED is connected to GP18-GP20 and active low (so the
    on/off state will work in the opposite way to the LED on a
    Raspberry Pi Pico). You can PWM the pins to dim the LED - check
    out Tonygo2's MicroPython example.

    The example cited is Python, so not directly of use to you, but here is
    the link, anyway:

    https://forums.pimoroni.com/t/tiny-2040-rgb-led-control-tutorial/16604


    --
    Cheers,
    Daniel.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)