Repository navigation
Add RP2040 platform (Arduino IDE) - #1261
Conversation
|
Admittedly, I'm not really sure how I should be using some of the defines in led_sysdefs ( |
|
Ah, I should've realised this earlier, but the naive fastpin implementation may cause data races when performing multiple simultaneous writes. |
…d accidental use of wrong reg for hival,loval)
|
Okay, I've had more time to look at the code and think, and my conclusion is that the root cause of the data race issue is actually no different to that which FAST_SPI_INTERRUPTS_WRITE_PINS is intended for. Of course, there's still the matter of proper hardware SPI support, which for now is not a priority for me as I don't have a good way to check the output of it at high rates and the software implementation is at least functional. |
PIO-based/M0 generic implementation is controlled by FASTLED_RP2040_CLOCKLESS_PIO it *should* be able to automatically fall back to m0clockless from PIO automatically, but for some reason I'm having trouble getting that to work (requires more investigation, but at least this isn't a regression) CPU frequency should be set in F_CPU or VARIANT_MCK before including FastLED if overclocking (for m0clockless only) (becuase we need to know frequency at compile time, but pico sets it at runtime -- it might make sense to write a custom bitbang output to work around this) PIO timing and clock divider is now automatically scaled from input CLOCKLESS_FREQUENCY to the fastest rate possible with the PIO program's delay slots (this simplifies timing of m0clockless by having it use CPU frequency directly)
|
I decided to go ahead and add m0clockless output driver as an option for the platform. Details in latest commit message. |
avoiding sideset means that we double the max instruction delay, which should increase our timing resolution it also means that there's no longer a separately-licensed block of code included
|
Need any help with coding or testing? I've also been looking to use the rp2040 with FastLED. |
|
Help is always welcome! |
|
Sounds good! I am brushing up on the PIO documentation and will be forking soon. Definitely understand being busy, haha. I'll also go ahead and test with some LEDs, I have some neopixels, apa102's, and some sk2812s. |
|
I tried deleting my fastLED library and replacing it with the zip I got from your PR. When I try to "#include <FastLED.h>" and compile for my Raspberry pi pico it still gives the "This platform isn't recognized by FastLED... yet" error. I'm a little lost, am I doing something incorrectly? |
|
@LivingSynthesis That does sound correct, so I'm not entirely sure what's going on. You might want to check that you didn't accidentally download the master branch (zip file should be named Additionally, this PR was only tested with the official Arduino core ( Could you please check these things and let us know if you get it working? |
|
@somewhatlurker So I finally got around to messing around with it some more and when I try to use your branch(correctly this time, thanks) with the official Arduino Mbed OS board it compiles correctly without error. However I haven't been using the official Arduino pico board, instead I'm using the ones contributed by Earle F. Philhower because with the official one the board goes into some weird state and I could never get it to work correctly or run any code, even blink. So I'm a bit stuck, I can't use the library with the official board because that one doesn't work at all for me, and I can't use the library with the working board because for some reason they're not being recognized the same way! Here's the error info I get when using the Earle Board if that's helpful at all!
|
|
Well that's some progress for sure. The main error here is that it looks like m0clockless (existing FastLED code that I reused for operating without enough PIO state machines available) depends on I'll have to look into the possibility of directly accessing the hardware registers for it, or add an alternate implementation. |
|
I manually merged this PR into 3.5.0 and tested it on this LED project: and it worked as expected on an AdaFruit ItsyBitsy RP2040. |
|
@kriegsman What needs to happen to get this merged? |
I am currently using this with platform.io, using https://github.com/Wiz-IO/wizio-pico (which is based on a barebones pico-sdk) and was missing the Systick. typedef struct
{
io_rw_32 CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
io_rw_32 LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
io_rw_32 VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
io_rw_32 CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
#define SysTick ((SysTick_Type*)systick_hw)However, my issue now is that it seems this framework makes F_CPU a variable, as the cpu frequency can be changed at runtime. This breaks the CMinWait macro, as it depends on F_CPU but in this case F_CPU isn't a constant. Not really sure what the best way to fix that is. |
|
Just tested it, works for me 👍🏻 |
|
Also works fine for me. Demonstrated success with Pico 2040 zero which has built in WS2812 pixel. |
|
I've posted about this over on the FastLED forum - It seems that FastLED 3.6.0 is supported on the Adafruit RP2040 Scorpio board when running a single strip. (pin # 16) ...but seemingly when it comes to declaring multiple strips with FastLED.addleds as in the FastLED multiple examples (ArrayOfLedArrays, MultiArrays, MultipleStripsInOneArray) (using pins 16, 17,18) I get compile errors: 172 | # pragma message "Forcing software SPI - no hardware SPI for you!" as shown here: In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/led_sysdefs.h:38, from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:51, from C:\Users\mbiasotti\AppData\Local\Temp.arduinoIDE-unsaved2023116-31360-kpexyq.vccpc\ArrayOfLedArrays\ArrayOfLedArrays.ino:10: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:87: warning: "cli" redefined 87 | #define cli() (saved_interrupt_status = save_and_disable_interrupts()) | In file included from C:\Users\mbiasotti\AppData\Local\Temp\arduino\sketches\591ADB0B896052DFAB30F0519F463C9D\sketch\ArrayOfLedArrays.ino.cpp:1: C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:74: note: this is the location of the previous definition 74 | #define cli() noInterrupts() | c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:88: warning: "sei" redefined 88 | #define sei() (restore_interrupts(saved_interrupt_status)) | C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:73: note: this is the location of the previous definition 73 | #define sei() interrupts() | In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:75: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/fastspi.h:172:23: note: '#pragma message: Forcing software SPI - no hardware SPI for you!' 172 | # pragma message "Forcing software SPI - no hardware SPI for you!" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {standard input}: Assembler messages: {standard input}:1101: Error: invalid offset, value too big (0x00000494) exit status 1 |
|
I've posted about this over on the FastLED forum - It seems that FastLED 3.6.0 is supported on the Adafruit RP2040 Scorpio board when running a single strip. (pin # 16) ...but seemingly when it comes to declaring multiple strips with FastLED.addleds as in the FastLED multiple examples (ArrayOfLedArrays, MultiArrays, MultipleStripsInOneArray) (using pins 16, 17,18) I get compile errors: 172 | # pragma message "Forcing software SPI - no hardware SPI for you!" as shown here: In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/led_sysdefs.h:38, from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:51, from C:\Users\mbiasotti\AppData\Local\Temp.arduinoIDE-unsaved2023116-31360-kpexyq.vccpc\ArrayOfLedArrays\ArrayOfLedArrays.ino:10: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:87: warning: "cli" redefined 87 | #define cli() (saved_interrupt_status = save_and_disable_interrupts()) | In file included from C:\Users\mbiasotti\AppData\Local\Temp\arduino\sketches\591ADB0B896052DFAB30F0519F463C9D\sketch\ArrayOfLedArrays.ino.cpp:1: C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:74: note: this is the location of the previous definition 74 | #define cli() noInterrupts() | c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:88: warning: "sei" redefined 88 | #define sei() (restore_interrupts(saved_interrupt_status)) | C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:73: note: this is the location of the previous definition 73 | #define sei() interrupts() | In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:75: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/fastspi.h:172:23: note: '#pragma message: Forcing software SPI - no hardware SPI for you!' 172 | # pragma message "Forcing software SPI - no hardware SPI for you!" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {standard input}: Assembler messages: {standard input}:1101: Error: invalid offset, value too big (0x00000494) exit status 1 |
|
I've posted about this over on the FastLED forum - It seems that FastLED 3.6.0 is supported on the Adafruit RP2040 Scorpio board when running a single strip. (pin # 16) ...but seemingly when it comes to declaring multiple strips with FastLED.addleds as in the FastLED multiple examples (ArrayOfLedArrays, MultiArrays, MultipleStripsInOneArray) (using pins 16, 17,18) I get compile errors: `172 | # pragma message "Forcing software SPI - no hardware SPI for you!" as shown here: In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/led_sysdefs.h:38, from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:51, from C:\Users\mbiasotti\AppData\Local\Temp.arduinoIDE-unsaved2023116-31360-kpexyq.vccpc\ArrayOfLedArrays\ArrayOfLedArrays.ino:10: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:87: warning: "cli" redefined 87 | #define cli() (saved_interrupt_status = save_and_disable_interrupts()) | In file included from C:\Users\mbiasotti\AppData\Local\Temp\arduino\sketches\591ADB0B896052DFAB30F0519F463C9D\sketch\ArrayOfLedArrays.ino.cpp:1: C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:74: note: this is the location of the previous definition 74 | #define cli() noInterrupts() | c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/platforms/arm/rp2040/led_sysdefs_arm_rp2040.h:88: warning: "sei" redefined 88 | #define sei() (restore_interrupts(saved_interrupt_status)) | C:\Users\mbiasotti\AppData\Local\Arduino15\packages\rp2040\hardware\rp2040\3.6.1\cores\rp2040/Arduino.h:73: note: this is the location of the previous definition 73 | #define sei() interrupts() | In file included from c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/FastLED.h:75: c:\Users\mbiasotti\Documents\Arduino\libraries\FastLED\src/fastspi.h:172:23: note: '#pragma message: Forcing software SPI - no hardware SPI for you!' 172 | # pragma message "Forcing software SPI - no hardware SPI for you!" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ {standard input}: Assembler messages: {standard input}:1101: Error: invalid offset, value too big (0x00000494) exit status 1` |
|
It looks to me like the only real error is the one at the end, about an invalid offset in the assembly code. Very weird. |
|
UPDATE: I was over on Earle Philhowers's Github and took the advice to use the Arduino MBED RP2040 core and it corrects this problem. I'm now able to run multiple strips with my Adafruit RP2040 Scorpio using FastLED. |
As the title implies, this PR adds some level of support for the RP2040 platform (Raspbetty Pi Pico, etc).
Currently, I've ported fastpin for software SPI and created a version of clockless output using the platform's PIO feature (programmable state machines that let us create non-blocking output with very little overhead).
Apologies for any problems with this. I'm honestly not much of an embedded dev at all, and so far I've just been testing with a logic analyser. (don't have any spare LEDs at the moment, but that should change soon)
I'm interested in hearing any comments and feedback you may have, as well as the results of testing.
About the clockless PIO implementation:
The SDK-provided claims system is used so that resources can used without interfering with other code that behaves well and uses claims.
Resource usage per instance of ClocklessController:
Additionally, one interrupt handler for DMA_IRQ_0 (configurable as shared or exclusive via FASTLED_RP2040_CLOCKLESS_IRQ_SHARED) is used regardless of how many instances are created.
Known Limitations (updated 2021-08-07 to reflect changes)
Most of these are pretty minor in my opinion, but there's no point hiding them away.
FASTLED_RP2040_CLOCKLESS_PIOas0will force fallback to a regular blocking implementation (m0clockless). It might also be worth looking into adding parallel output (a version of FlexibleInlineBlockClocklessController?) to reduce state machines required for multiple strings (there's an sdk example for this), but I think that might be okay to leave until a later time.