• Baremetal programiing the Pimoroni Tiny2040 RGB LED

    From Single Stage to Orbit@alex.buell@munted.eu to comp.sys.raspberry-pi on Sun Jan 11 16:15:59 2026
    From Newsgroup: comp.sys.raspberry-pi

    Hi chaps
    Does this group also include the Raspberry rp2040/rp2350 as well? I'm
    in need of resources or the knowledge of how to program the PWMs on the
    rp2040. If not, are there any online resource I can consult.
    The rp2040 datasheets are instrutable on the subject of the PWMs. I can
    easily blink an ordinary LED, likewise for a RGB LED via three GPIO
    pins, but for doing cool tricks like fading/brightening the separate
    RGB components on a RGB LED it's beyond me, I think PWMs are needed for
    this but all I could find was micropython stuff and that works but I'd
    like to know how to do it baremetal with ARM thumb assembly.
    Many thanks,
    Alex
    --
    Tactical Nuclear Kittens
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Daniel James@daniel@me.invalid to comp.sys.raspberry-pi on Sun Jan 11 18:52:17 2026
    From Newsgroup: comp.sys.raspberry-pi

    On 11/01/2026 16:15, Single Stage to Orbit wrote:
    Does this group also include the Raspberry rp2040/rp2350 as well?

    I don't see why not ...

    The rp2040 datasheets are instrutable on the subject of the PWMs.

    Agreed. The official documentation for everything but Python is sketchy
    at best. Superficially it looks great, but on closer inspection it is
    found to present all the right words without imbuing them with any meaning.

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

    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.

    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 ...
    --
    Cheers,
    Daniel.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From The Natural Philosopher@tnp@invalid.invalid to comp.sys.raspberry-pi on Sun Jan 11 19:36:45 2026
    From Newsgroup: comp.sys.raspberry-pi

    On 11/01/2026 16:15, Single Stage to Orbit wrote:
    Hi chaps

    Does this group also include the Raspberry rp2040/rp2350 as well? I'm
    in need of resources or the knowledge of how to program the PWMs on the rp2040. If not, are there any online resource I can consult.

    I certainly have been playing with these in a C context.

    I klooked into PWM in some detail but have not yet implemented it.

    The rp2040 datasheets are instrutable on the subject of the PWMs. I can easily blink an ordinary LED, likewise for a RGB LED via three GPIO
    pins, but for doing cool tricks like fading/brightening the separate
    RGB components on a RGB LED it's beyond me, I think PWMs are needed for
    this but all I could find was micropython stuff and that works but I'd
    like to know how to do it baremetal with ARM thumb assembly.

    Cant help with assembly, only C.

    IIRC there are a couple of places you just wrote data to to set the
    thing up and these can be rewritten live to vary the pulse width

    Easy way to do that is to run a sleep_ms(loop) and every iterations
    change something for a fade up down.

    From: https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#group_hardware_pwm


    The RP2040 PWM block has 8 identical slices, the RP2350 has 12. Each
    slice can drive two PWM output signals, or measure the frequency or duty
    cycle of an input signal. This gives a total of up to 16/24 controllable
    PWM outputs. All 30 GPIOs can be driven by the PWM block.

    The PWM hardware functions by continuously comparing the input value to
    a free-running counter. This produces a toggling output where the amount
    of time spent at the high output level is proportional to the input
    value. The fraction of time spent at the high signal level is known as
    the duty cycle of the signal.

    The default behaviour of a PWM slice is to count upward until the wrap
    value (pwm_config_set_wrap) is reached, and then immediately wrap to 0.
    PWM slices also offer a phase-correct mode, where the counter starts to
    count downward after reaching TOP, until it reaches 0 again.

    // Output PWM signals on pins 0 and 1

    #include "pico/stdlib.h"
    #include "hardware/pwm.h"

    int main() {

    // Tell GPIO 0 and 1 they are allocated to the PWM
    gpio_set_function(0, GPIO_FUNC_PWM);
    gpio_set_function(1, GPIO_FUNC_PWM);

    // Find out which PWM slice is connected to GPIO 0 (it's slice 0)
    uint slice_num = pwm_gpio_to_slice_num(0);

    // Set period of 4 cycles (0 to 3 inclusive)
    pwm_set_wrap(slice_num, 3);
    // Set channel A output high for one cycle before dropping
    pwm_set_chan_level(slice_num, PWM_CHAN_A, 1);
    // Set initial B output high for three cycles before dropping
    pwm_set_chan_level(slice_num, PWM_CHAN_B, 3);
    // Set the PWM running
    pwm_set_enabled(slice_num, true);

    // Note we could also use pwm_set_gpio_level(gpio, x) which looks
    up the
    // correct slice and channel for a given GPIO.
    }

    Now that references a c library, but easy enough to pull assembler
    source out of it


    Many thanks,
    Alex
    --
    rCLIt is dangerous to be right in matters on which the established
    authorities are wrong.rCY

    rCo Voltaire, The Age of Louis XIV

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Gordon Henderson@gordon+usenet@drogon.net to comp.sys.raspberry-pi on Mon Jan 12 10:57:56 2026
    From Newsgroup: comp.sys.raspberry-pi

    In article <d03091c18c489926db7aef8286bf865162298441.camel@munted.eu>,
    Single Stage to Orbit <alex.buell@munted.eu> wrote:
    Hi chaps

    Does this group also include the Raspberry rp2040/rp2350 as well?

    I'd like to think so, but it's somewhat niche (Baremetal that is)
    however...

    like to know how to do it baremetal with ARM thumb assembly.

    ... my use is the RISC-V cores in the rp2350, so bare metal RISC-V
    asembly.... But the principle for programming the PWM generators
    is more or less the same from eith CPU, so I understand, but it's
    something I've not gotten round to.

    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...

    Gordon
    --- Synchronet 3.21a-Linux NewsLink 1.2