Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WS2812 driver does not work with XIAO SAMD21 #540

Closed
ysoldak opened this issue Apr 1, 2023 · 12 comments
Closed

WS2812 driver does not work with XIAO SAMD21 #540

ysoldak opened this issue Apr 1, 2023 · 12 comments

Comments

@ysoldak
Copy link
Contributor

ysoldak commented Apr 1, 2023

I've tried to drive RGB Led with XIAO board (SAMD21, 48MHz chip) and it does not work.

When trying the example, all 10 LEDs are very bright, almost white. One can see a hint of green and red, changing though.

Same example on a RP2040 (125MHz) board just works (blinking green and red).

@aykevl
Copy link
Member

aykevl commented Apr 1, 2023

I checked on the Circuit Playground Express (same chip) and it works fine.
Can you double check:

  • the wires (is it really connected correctly - perhaps try another pin)
  • power requirements (maybe it doesn't have enough power to drive these LEDs correctly), also note that the ground must be shared between the MCU and the LEDs.

If it's not a wire, it's hard to say what's wrong. It might be a faulty crystal oscillator or any number of other things. The way to know for sure is to connect it to a logic analyzer and look at the signal.

Something else you could try: testing the same setup but using the Arduino IDE and a library like FastLED.

@ysoldak
Copy link
Contributor Author

ysoldak commented May 17, 2023

I've verified again, here are results:
Control (XIAO RP2040) - Correct
XIAO_RP2040
Experiment (XIAO SAMD21) - Too bright
XIAO_SAMD21

Here is overview of the setup, wires indeed quite long and connections may be weak, but it works for control...
Setup

To make this work, I've added following two files to the ws2812 example.
And unmatched these tags in others.go

XIAO RP2040
./examples/ws2812/xiao-rp2040.go

//go:build xiao_rp2040

package main

import "machine"

var neo = machine.D8
var led = machine.LED

func init() {
	machine.NEOPIXEL_POWER.Configure(machine.PinConfig{Mode: machine.PinOutput})
	machine.NEOPIXEL_POWER.High()
}

tinygo flash -target=xiao-rp2040 -size=full ./examples/ws2812/

XIAO SAMD21
./examples/ws2812/xiao.go

//go:build xiao

package main

import "machine"

var neo = machine.D8
var led = machine.LED

tinygo flash -target=xiao -size=full ./examples/ws2812/

@ysoldak
Copy link
Contributor Author

ysoldak commented May 17, 2023

This was just something I've observed when working on a random project that runs on RP2040 now anyway.
So this bug(?) does not block me in any way and I'm too lazy to debug this further.
Let it be more as FYI and we can look at this closer if more cases like this emerge.

P.S. LED strip we can rule out from the equation, the problem first discovered with another strip (different size and brand), same result.

@aykevl
Copy link
Member

aykevl commented May 19, 2023

I don't have a Xiao so unfortunately I can't debug this issue myself. But here are some other ideas to narrow down this problem:

  • Can you try on another XIAO SAMD21 board (to rule out a hardware problem with the board)?
  • Do you have another samd21 based board that you can try? For example, one of the "M0" boards from Adafruit.

@ysoldak
Copy link
Contributor Author

ysoldak commented May 25, 2023

Tried with another XIAO board and another pin -- same result.
Also, tried with Arduino Nano 33 IoT board, same chip. Same bad result.
ArduinoNano33WS2812

An observation: on XIAO-RP2040 all output pins work fine, except D10. In D10 case only one LED is lit up, too bright and slightly pulsing. This in contrast with SAMD21 there all leds are brightly lit up.

Code of my experiments you can find in #575 pull request.

@aykevl
Copy link
Member

aykevl commented May 26, 2023

I have been able to reproduce this issue using an Arduino Nano 33 IoT. I'll see what I can do.

aykevl added a commit to tinygo-org/tinygo that referenced this issue May 26, 2023
The regular port access is around 4 cycles, instead of the usual 2
cycles for a store instruction on Cortex-M0+. The IOBUS however is
faster, I didn't measure exactly but I guess it's 2 cycles as expected.

This fixes a bug in the WS2812 driver that only happens on samd21 chips:
tinygo-org/drivers#540
@aykevl
Copy link
Member

aykevl commented May 26, 2023

Here is a fix: tinygo-org/tinygo#3751
Can you test it on the XIAO?

@aykevl
Copy link
Member

aykevl commented May 26, 2023

An observation: on XIAO-RP2040 all output pins work fine, except D10. In D10 case only one LED is lit up, too bright and slightly pulsing. This in contrast with SAMD21 there all leds are brightly lit up.

This is an unrelated issue, as it's an entirely different chip.
If this is a problem for you, you can open a new issue.

@ysoldak
Copy link
Contributor Author

ysoldak commented May 26, 2023

Can you test it on the XIAO?

I did, it works now, thank you.

@ysoldak
Copy link
Contributor Author

ysoldak commented May 26, 2023

This is an unrelated issue, as it's an entirely different chip.
If this is a problem for you, you can open a new issue.

Not a problem at all, just an observation I thought worth to share.
No fix needed as any other pin can be used for workaround.

@ysoldak
Copy link
Contributor Author

ysoldak commented May 26, 2023

Feel free to close this as fixed when you see fit, otherwise I do that after TinyGo v0.28 is released.

deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue May 29, 2023
The regular port access is around 4 cycles, instead of the usual 2
cycles for a store instruction on Cortex-M0+. The IOBUS however is
faster, I didn't measure exactly but I guess it's 2 cycles as expected.

This fixes a bug in the WS2812 driver that only happens on samd21 chips:
tinygo-org/drivers#540
@ysoldak
Copy link
Contributor Author

ysoldak commented Aug 2, 2023

Fixed in TinyGo v0.28

@ysoldak ysoldak closed this as completed Aug 2, 2023
LiuJiazheng pushed a commit to LiuJiazheng/tinygo that referenced this issue Aug 20, 2023
The regular port access is around 4 cycles, instead of the usual 2
cycles for a store instruction on Cortex-M0+. The IOBUS however is
faster, I didn't measure exactly but I guess it's 2 cycles as expected.

This fixes a bug in the WS2812 driver that only happens on samd21 chips:
tinygo-org/drivers#540
deadprogram pushed a commit to tinygo-org/tinygo that referenced this issue Sep 17, 2023
The regular port access is around 4 cycles, instead of the usual 2
cycles for a store instruction on Cortex-M0+. The IOBUS however is
faster, I didn't measure exactly but I guess it's 2 cycles as expected.

This fixes a bug in the WS2812 driver that only happens on samd21 chips:
tinygo-org/drivers#540
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants