I’m using a Pico 2040W for testing - it’ll be ported to a Pimoroni Plasma 2350W - and my control web page allows the user to set how many LEDs in a string, and what GPIO to use for data. The first time through, everything works Ok: “new WS2812()” works, and I can see a bit pattern on the scope coming from the pin. The second time, I delete the current WS2812 object to reassign the pointer a new WS2812, but I get the following:
(gdb) back
#0 \_exit (status=status@entry=1) at /Users/aaronm/bin/dev/raspi-pico/pico-sdk/src/rp2_common/pico_clib_interface/newlib_interface.c:45
#1 0x100042d4 in \__assert_func (file=file@entry=0x1001cad4 “/Users/aaronm/bin/dev/raspi-pico/pico-sdk/src/common/hardware_claim/claim.c”, line=line@entry=51,
func=func@entry=0x10022790 <**func**.0> “hw_claim_clear”, failedexpr=failedexpr@entry=0x1001cab4 “hw_is_claimed(bits, bit_index)”)
at /Users/aaronm/bin/dev/raspi-pico/pico-sdk/src/rp2_common/pico_clib_interface/newlib_interface.c:173
#2 0x10000f2a in hw_claim_clear (bits=bits@entry=0x200010c4 “\\020”, bit_index=0) at /Users/aaronm/bin/dev/raspi-pico/pico-sdk/src/common/hardware_claim/claim.c:51
#3 0x10012870 in pio_sm_unclaim (pio=, sm=) at /Users/aaronm/bin/dev/raspi-pico/pico-sdk/src/rp2_common/hardware_pio/pio.c:45
#4 0x1000034c in plasma::WS2812::\~WS2812 (this=0x2002dfe0, \__in_chrg=) at /Users/aaronm/bin/dev/raspi-pico/pimoroni-pico/drivers/plasma/ws2812.hpp:78
#5 0x10000464 in core0_mainTask (pvParameters=) at /Users/aaronm/bin/dev/raspi-pico/my-projects/20251203-kiddos-ws2812-leds/my-ws2812/main.cpp:158
#6 0x100180d8 in xPortPendSVHandler () at /Users/aaronm/bin/dev/raspi-pico/RPI-pico-FreeRTOS/picoFreeRTOS-Kernel/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/port.c:613
Here’s the relevant code:
if ( ledStrip1 != NULL ) {
//ledStrip1->start();
delete ledStrip1;
vTaskDelay( 500 );
}
ledStrip1 = new WS2812( ledCt, pio0, 0, pin, WS2812::DEFAULT_SERIAL_FREQ, false, WS2812::COLOR_ORDER::RGB );
ledStrip1->start();
I see in the class definition for WS2812, there’s already a problem with pio_sm_unclaim() if using Python:
~WS2812() {
stop();
clear();
update(true);
dma_channel_unclaim(dma_channel);
pio_sm_set_enabled(pio, sm, false);
pio_remove_program(pio, &ws2812_program, pio_program_offset);
#ifndef MICROPY_BUILD_TYPE
// pio_sm_unclaim seems to hardfault in MicroPython
pio_sm_unclaim(pio, sm);
#endif
if(managed_buffer) {
// Only delete buffers we have allocated ourselves.
delete[] buffer;
}
}
Any suggestions to fix or get around this? Being able to redefine an LED string on the fly is kind of important in this application.
Thanks!