adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.11k stars 1.22k forks source link

Trellis M4 latest build causing issue with NeoPixel code #1326

Closed kattni closed 5 years ago

kattni commented 5 years ago

I updated CircuitPython on my Trellis M4 and any code involving the NeoPixels is failing to function properly.

The failure is:

  1. All of the NeoPIxels will turn bright white (evidently (255, 255, 255)).
  2. After a seemingly consistent period of time (a few seconds), CIRCUITPY will disconnect, all of the NeoPixels will become a dimmer white (as though it's more like (45, 45, 45) or something), and the status DotStar LED on the back will turn a slightly purple-tinged red (which is to say, you can see that there is a little blue to it, but it is primarily red).
  3. If connected to the serial console, no errors show up, there is nothing there to indicate what happened.
  4. Pressing buttons on the front does nothing at this point.
  5. A single reset returns it to the bootloader and TRELM4BOOT mounts.
  6. However, attempting to load the same or a different version of CircuitPython at this point does not change the state of the board - copy the build, TRELM4BOOT will disconnect, and then the board will restart with the same purple-red status LED on the back and no CIRCUITPY drive will mount.

The resolution is:

  1. Unplug the board.
  2. Plug it back in.
  3. IMMEDIATELY double-tap reset to get into the bootloader.
  4. Load an earlier version of CircuitPython onto the TRELM4BOOT drive. This returns it to a functional state.

Tested with the following examples:

Issue reproduced with the following versions: adafruit-circuitpython-trellis_m4_express-en_US-20181110-50f5d27.uf2 adafruit-circuitpython-trellis_m4_express-en_US-20181109-97bc951.uf2

The following versions do not have the issue: adafruit-circuitpython-trellis_m4_express-en_US-20181107-d08747d.uf2 adafruit-circuitpython-trellis_m4_express-en_US-20181105-283e072.uf2

jerryneedell commented 5 years ago

Just a thought. I found that setting all of the pixels white causes an over current condition so some of this issue may be masked by that. I have reproduced this issue on my trellis m4.

tannewt commented 5 years ago

Thank you for the detailed report. I was able to reproduce this on my end. I believe @jerryneedell is right that the bad failure mode is a result of overdrawing the usb line with all white pixels.

The question is, why the white pixels? Well, I haven't figured it out. It appears that the neopixel clocking is slightly slower than in d08747d. The zero high time is 0.5 us instead of 0.38 us which is enough to be a one. I get these numbers on a Metro M4 without neopixels attached so it isn't a fundamental power issue on the Trellis. I also tested the sleep duration between neopixel writes and its consistently 1.004 seconds between both commits. So, this makes me think we're hitting some sort of caching boundary or memory bus contention we weren't hitting before. I have no idea exactly what it is.

dhalbert commented 5 years ago

I wonder if the instruction/data cache is on at the right time? Maybe that got lost in some refactoring? It gets turned on in the beginning, and also gets turned off/on during some external flash operations.

estiens commented 5 years ago

I still have this issue. Currently my board is in a bricked state from accidentally turning all the pixels white. They turn white for a second, then the drive disappears and the board is stuck with all yellowish looking pixels

dhalbert commented 5 years ago

@estiens The problem is getting your board into bootloader mode. Then you can load the Trellis M4 .uf2 listed in the Trellis learn guide that does not have this problem. What I'd suggest trying is this:

  1. Unplug the board from USB.
  2. Hold down the reset button.
  3. Continuing to hold down the reset button, plug the board into USB.
  4. Release and quickly double-click the reset button, so that CircuitPython does not get a chance to start. I've tried this and gotten it into TRELM4BOOT without entering CircuitPython.

If this doesn't work it may be possible to pull down the input to the first NeoPixel to ground with, say a 1k resistor, to avoid illuminating them, and then double-click.

tannewt commented 5 years ago

@estiens If your code is the source of all white pixels we can give you a safe-mode only build to use to change it.

dhalbert commented 5 years ago

Here is a safe-mode build. I built this last night but then thought you probably had a clock issue. Unzip before using. trellis_m4-SAFE-MODE.uf2.zip