8000 ESP32-S2: Add Neopixel support by hierophect · Pull Request #3232 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

ESP32-S2: Add Neopixel support #3232

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

Merged
merged 7 commits into from
Aug 11, 2020
Merged

ESP32-S2: Add Neopixel support #3232

merged 7 commits into from
Aug 11, 2020

Conversation

hierophect
Copy link
Collaborator

This PR adds Neopixel support to the ESP32_S2, and adds the onboard WS2812B as a status LED neopixel to the board profile of the Saola1-wrover.

This module utilizes the RMT (Remote Control) peripheral on the ESP32, which will also be used for PulseIn/PulseOut and possibly other purposes - thus, a simple channel reservation system has been added to peripherals, which these other modules will share. Neopixels reserve their channel every time they are written and automatically free it after writes. Up to 4 channels can be active at a time.

Tested on the Saola1-wrover dev board.

@hierophect hierophect added the espressif applies to multiple Espressif chips label Jul 31, 2020
@hierophect hierophect requested a review from tannewt July 31, 2020 19:35
@ladyada
Copy link
Member
ladyada commented Jul 31, 2020

rad!

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good but the CI isn't happy.

@jerryneedell
Copy link
Collaborator

I tried to build with this PR but it fails ```-- Build files have been written to: /home/pi/projects/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf
QSTR updated
common-hal/neopixel_write/init.c: In function 'common_hal_neopixel_write':
common-hal/neopixel_write/init.c:105:9: error: implicit declaration of function 'mp_raise_ValueError' [-Werror=implicit-function-declaration]
mp_raise_ValueError(translate("Could not retrieve clock"));
^~~~~~~~~~~~~~~~~~~
common-hal/neopixel_write/init.c:105:9: error: nested extern declaration of 'mp_raise_ValueError' [-Werror=nested-externs]
cc1: all warnings being treated as errors
make: *** [../../py/mkrules.mk:55: build-espressif_saola_1_wrover/common-hal/neopixel_write/init.o] Error 1

@hierophect
Copy link
Collaborator Author

I wonder why this didn't come up on my local machine? Weird.

@hierophect hierophect requested a review from tannewt August 1, 2020 13:18
@hierophect
Copy link
Collaborator Author

@tannewt these CI failures are kind of all over the place - right now I see a DE translation failure on the Gemma M0 and Trinket due to flash constraints, and an IDF failure for the ESP32-S2 boards that seems to be related to the virtualenv. Before that it was a server issue with AWS? I don't think any of them are related to my code though.

@jerryneedell
Copy link
Collaborator
jerryneedell commented Aug 1, 2020

I tried building with the updated PR. The build succeeds, but when I put it on my board, it does not boot.
attached is the log from the USB Debug port
esp32s2_crash.txt

Edited to add;
also note that when I checkout the PR there are some submodules that are changed.

 $ git checkout pr_3232
M	extmod/ulab
M	lib/tinyusb
M	ports/atmel-samd/peripherals

I built it both after syncing the submodes and not -- same results

If I build the tip of main ,it works normally

@fede2cr
Copy link
fede2cr commented Aug 1, 2020

I was able to build, and no crashes yet, but in circuitpython I can't get the LED to initialize. On the REPL:

import board
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'NeoPixel'

@jerryneedell
Copy link
Collaborator

I was able to build, and no crashes yet, but in circuitpython I can't get the LED to initialize. On the REPL:

import board
import neopixel
pixels = neopixel.NeoPixel(board.NEOPIXEL, 1)
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'NeoPixel'

odd -- not at all clear why it won't even boot for me...

@dhalbert
Copy link
Collaborator
dhalbert commented Aug 1, 2020

Try merging from main; it should fix the breaking builds, due to build cache changes in #3230.

@hierophect
Copy link
Collaborator Author

@dhalbert merged. Would having just restarted the jobs had the same effect, since my code doesn't impact the changes on main?

@fede2cr @jerryneedell Thanks for testing! I'm unable to replicate any issues on either the old unmerged version or the merged one - my builds connect the REPL and the status LED changes as appropriate. I'm also able to override it in code.py as board.NEOPIXEL without issues. There shouldn't be any submodule changes associated with this PR as per the changelog. Could you double check that your main branch is fully up to date and give this another shot?

@hierophect
Copy link
Collaborator Author

I always use this bash alias to update submodules after changing branches as per @dhalbert's recommendation: alias gitsubupdate='git submodule sync --quiet --recursive && git submodule update --init'

@jerryneedell
Copy link
Collaborator

@hierophect I am baffled. I do the same for syncing submodules but you PR still fails the same way for me every time -- tried 2 different boards. If i then checkout main and rebuild, it works normally.

I am working from the tip of main.


Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 6.0.0-alpha.2-139-g034b1bb90 on 2020-08-03; Saola 1 w/Wrover with ESP32S2
>>> 
>>> 

@jerryneedell
Copy link
Collaborator
jerryneedell commented Aug 3, 2020

on a failed boot, I see this in the debug USB port

E (1598) rmt: rmt_driver_install(893): RMT driver already installed for channel
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40096ab6  PS      : 0x00060630  A0      : 0x8009c6c2  A1      : 0x3ffde100  
A2      : 0x00000000  A3      : 0x3f004e54  A4      : 0x3f0072d0  A5      : 0x3f006f8c  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x8009cc02  A9      : 0x3ffde0e0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x40028fbd  

Backtrace:0x40096ab3:0x3ffde100 0x4009c6bf:0x3ffde120 0x4009b9f0:0x3ffde140 0x4009bc47:0x3ffde190 0x4009bdef:0x3ffde1b0 0x400b2c45:0x3ffde1d0 0x4002d995:0x3ffde200


ELF file SHA256: f6a434ef52346827

CPU halted.

@hierophect
Copy link
Collaborator Author
hierophect commented Aug 3, 2020

@jerryneedell I see various reports of "RMT driver already installed for channel" - I didn't use the debug port when developing this so I didn't make any note of these, they don't seem problematic for me. What I'm not getting is your Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.1. Is it possible you have some kind of flag on that halts the CPU when it gets one of these messages, and I haven't set it so it keeps running normally on my board?

I will try to figure out why it is making these messages in the first place.

@jerryneedell
Copy link
Collaborator

Since mine builds for main, I assume that exonerates any issue with the esp-idf, correct? Your PR does not depend on any additions to it, does it?

@jerryneedell
Copy link
Collaborator

@hierophect and yes, the "RMT driver already installed for channel" errors one only reported with the PR, not with main.

@hierophect
Copy link
Collaborator Author

@jerryneedell I don't think it's something wrong with the IDF, but I'm thinking it might be an IDF setting. It seems suspicious to me that we're both getting the same error flags but it is only halting the CPU for you. I'm wondering if that's an internal flag within the IDF that changes behavior when dealing with exceptions. In any case it would be good if we don't get exceptions over the debug port at all, but I'd like to figure out why we are getting different results.

@tannewt
Copy link
Member
tannewt commented Aug 3, 2020

@jerryneedell I have a script in ports/esp32s2/tools/ that will produce a nice backtrace out of that backtrace line. Run the python with the board name as the first param and then copy the backtrace into the prompt. (It runs addr2line and gives you a useful location for the error.)

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! It worked after I enabled pixelbuf. Please also add the neopixel board support for the wroom board too. Thanks!

@@ -12,6 +12,8 @@ USB_SERIAL_NUMBER_LENGTH = 12
# Longints can be implemented as mpz, as longlong, or not
LONGINT_IMPL = MPZ

CIRCUITPY_NEOPIXEL_WRITE = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this below in alphabetical order. That way it'll be easier to find.

Please also turn on CIRCUITPY_PIXELBUF. (It worked for me in my testing.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this meant to be alphabetical?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tannewt It's actually not supposed to need to be there at all - CIRCUITPY_NEOPIXEL_WRITE is supposed to be on by default but it'd bug out if I didn't put it here. You've reminded me I need to look into why that's happening.

@jerryneedell
Copy link
Collaborator
jerryneedell commented Aug 4, 2020

deleted previous example -- I realized the the backtrace may not have been from the same build the was used to run the tool.

fresh build with newly installed esp-idf.... still crashes but the backtrace is a bit different



E (1598) rmt: rmt_driver_install(893): RMT driver already installed for channel
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40096ab6  PS      : 0x00060630  A0      : 0x8009c6c2  A1      : 0x3ffde100  
A2      : 0x00000000  A3      : 0x3f004e54  A4      : 0x3f0072d0  A5      : 0x3f006f8c  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x8009cc02  A9      : 0x3ffde0e0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x40028fbd  

Backtrace:0x40096ab3:0x3ffde100 0x4009c6bf:0x3ffde120 0x4009b9f0:0x3ffde140 0x4009bc47:0x3ffde190 0x4009bdef:0x3ffde1b0 0x400b2c45:0x3ffde1d0 0x4002d995:0x3ffde200


ELF file SHA256: aab93b0a9a305fdb

CPU halted.





pi@gjnpi4desk:~/projects/circuitpython/ports/esp32s2 $ python3 tools/decode_backtrace.py espressif_saola_1_wrover
espressif_saola_1_wrover
? 0x40096ab3:0x3ffde100 0x4009c6bf:0x3ffde120 0x4009b9f0:0x3ffde140 0x4009bc47:0x3ffde190 0x4009bdef:0x3ffde1b0 0x400b2c45:0x3ffde1d0 0x4002d995:0x3ffde200
got ['0x40096ab3', '0x4009c6bf', '0x4009b9f0', '0x4009bc47', '0x4009bdef', '0x400b2c45', '0x4002d995']
/home/pi/projects/circuitpython/ports/esp32s2/../../py/objtype.c:1366
/home/pi/projects/circuitpython/ports/esp32s2/../../supervisor/shared/rgb_led_status.c:389
/home/pi/projects/circuitpython/ports/esp32s2/../../main.c:289
/home/pi/projects/circuitpython/ports/esp32s2/../../main.c:494
/home/pi/projects/circuitpython/ports/esp32s2/supervisor/port.c:164
/home/pi/projects/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/esp32s2/cpu_start.c:423
/home/pi/projects/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/freertos/xtensa/port.c:143
jerryneedell:/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/esp-idf/components/freertos$ 

this may make a bit more sense
https://github.com/tannewt/esp-idf/blob/160ba4924d8b588e718f76e3a0d0e92c11052fa3/components/freertos/xtensa/port.c#L143

@jerryneedell
Copy link
Collaborator
jerryneedell commented Aug 4, 2020

FYI - From the espressif docs: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/fatal-errors.html#loadprohibited-storeprohibited

For those who have this working, are you doing anything spec 9E88 ial in your forks so that when I pull the PR ,there is something incompatible? I am getting the PR by using

git fetch origin pull/3232/head:pr_3232
git checkout pr_3232

then build as normal

make BOARD=espressif_saola_1_wrover clean
make BOARD=espressif_saola_1_wrover 
make BOARD=espressif_saola_1_wrover flash   (for Mac, for RPI add PORT=/dev/ttyUSB0)

that all goes as expected

as noted, by build of "main" works fine. It is not at all clear what is wrong when I build the pr_3232 branch.

@hierophect
Copy link
Collaborator Author

@jerryneedell @tannewt so if I'm understanding this error correctly, there's an attempt to dereference a null pointer somewhere in the Status LED code? I'm going to dig for it so please correct me if you think I'm wrong.

@jerryneedell
Copy link
Collaborator

@hierophect That seems to be what it is suggesting, but why only when I build it? Are you enabling DEBUG when you build?

@hierophect
Copy link
Collaborator Author

No, I have no special settings. It's definitely unusual. Do you have a sketch in the filesystem that you can access, or does it never even get that far? Is it possible that it could be something in code.py?

@tannewt
Copy link
Member
tannewt commented Aug 4, 2020

@jerryneedell What is the top commit in your git log? Maybe you are getting an auto-merge commit that I didn't when I checked out the branch directly.

Maybe code.py is throwing a weird exception? https://github.com/adafruit/circuitpython/blob/main/supervisor/shared/rgb_led_status.c#L389

F438
@jerryneedell
Copy link
Collaborator
jerryneedell commented Aug 4, 2020

@tannewt

jerryneedell:/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2$ git log
commit 490066877878a7917ec99742a13a7687785ef614 (HEAD -> pr3232)
Merge: 94b256186 034b1bb90
Author: Lucian Copeland <hierophect@gmail.com>
Date:   Mon Aug 3 12:26:37 2020 -0400

    Merge remote-tracking branch 'upstream/main' into esp32-neopixel

commit 034b1bb9035d60f6e0aa862f3bc60aafb1fd6e07
Merge: 16b7d9904 9b3af2b7e
Author: Jeff Epler <jepler@gmail.com>
Date:   Mon Aug 3 07:10:11 2020 -0500

    Merge pull request #3240 from jerryneedell/jerryn_frozen
    
     update frozen libraries

there is no code.py

I also tried downloading the "artifact" build from CI adafruit-circuitpython-espressif_saola_1_wrover-en_US-20200803-b4c0707.bin -- and loaded it to my board and it fails the same way as my builds :-(

@hierophect
Copy link
Collaborator Author

@jerryneedell try giving my latest build a shot. I added protections to remove the idf error messages, and added in an extra include to see if that null reference problem goes away. Tomorrow I may try getting gdb working with the ESP32-S2 since tracking null reference exceptions is kind of a pain without it.

@hierophect hierophect requested a review from tannewt August 4, 2020 22:42
@fede2cr
Copy link
fede2cr commented Aug 5, 2020

And just to confirm, with the latest chances, it is working fine in one of my saolas. Great work!

I got 3 from digikey, on the other two I'm getting backtraces.
(output through tools/decode_backtrace.py)
Board N° 2 and N° 3:

? 0x40097beb:0x3ffde0e0 0x4009e64b:0x3ffde100 0x4009d938:0x3ffde120 0x4009db93:0x3ffde170 0x4009dd3b:0x3ffde190 0x400b60f9:0x3ffde1b0 0x4002d995:0x3ffde1e0
got ['0x40097beb', '0x4009e64b', '0x4009d938', '0x4009db93', '0x4009dd3b', '0x400b60f9', '0x4002d995']
/home/alvaro/neop/circuitpython/ports/esp32s2/../../py/objtype.c:1366
/home/alvaro/neop/circuitpython/ports/esp32s2/../../supervisor/shared/rgb_led_status.c:390
/home/alvaro/neop/circuitpython/ports/esp32s2/../../main.c:289
/home/alvaro/neop/circuitpython/ports/esp32s2/../../main.c:494
/home/alvaro/neop/circuitpython/ports/esp32s2/supervisor/port.c:164
/home/alvaro/neop/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/esp32s2/cpu_start.c:423
/home/alvaro/neop/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/freertos/xtensa/port.c:143

I have not used board No 2&3 much, but I got the 3 of them on digikey on the same order, in the same plastic case that they ship them in, so there should be no difference with 1 and 2-3, other than I've use 1 in testing previous images of cpy.

@fede2cr
Copy link
fede2cr commented Aug 5, 2020

Trying to decode this weirdness. I tested the boards with other circuitpython versions, and after formatting by hand the filesystem, I got them to work.
Then I tested the neopixel version, same know error.
So I went back to a working version, created a code.py with an infinite loop so that it doesn't end. Flashed back the neopixel version, and now there is no error.

I looks like it is the lack of code.py, and the crash seems to happen "after" code.py or if it is missing. If I reformat, I start getting the errors again.

I hope this saves a bit of time debugging it.

@jerryneedell
Copy link
Collaborator

@fede2cr Wow! That works! I'm not imagining things!
If a code.py is present, it boots just fine, if not it crashes as before. As you noted, it has to be a code.py with an infinite loop. I tried one taht just printed something and exited and it still crashed.

With an infinite loop, I can break out from the REPL with control-C and everything is happy!!

Thanks for finding this

@hierophect -- FYI - with the latest PR, there are still a few IDF errors at start -- here is the end of the crash log with a non-infinite-loop code.py

I (428) spi_flash: flash io: dio
I (428) cpu_start: Starting scheduler on PRO CPU.
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2142) ledc: ledc_stop(428): LEDC is not initialized
E (2142) ledc: ledc_stop(428): LEDC is not initialized
E (2152) ledc: ledc_stop(428): LEDC is not initialized
E (2162) ledc: ledc_stop(428): LEDC is not initialized
Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x40097bfe  PS      : 0x00060630  A0      : 0x8009e63e  A1      : 0x3ffde0e0  
A2      : 0x00000000  A3      : 0x3f0055c8  A4      : 0x3f007c9c  A5      : 0x3f007958  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x8009eb8e  A9      : 0x3ffde0c0  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000001f  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x40028fbd  

Backtrace:0x40097bfb:0x3ffde0e0 0x4009e63b:0x3ffde100 0x4009d934:0x3ffde120 0x4009db8b:0x3ffde170 0x4009dd33:0x3ffde190 0x400b60c1:0x3ffde1b0 0x4002d995:0x3ffde1e0


ELF file SHA256: 0ec76b16f9bde9a0

CPU halted.

jerryneedell:/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2$ python3 tools/decode_backtrace.py espressif_saola_1_wrover
espressif_saola_1_wrover
? 0x40097bfb:0x3ffde0e0 0x4009e63b:0x3ffde100 0x4009d934:0x3ffde120 0x4009db8b:0x3ffde170 0x4009dd33:0x3ffde190 0x400b60c1:0x3ffde1b0 0x4002d995:0x3ffde1e0
got ['0x40097bfb', '0x4009e63b', '0x4009d934', '0x4009db8b', '0x4009dd33', '0x400b60c1', '0x4002d995']
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/../../py/objtype.c:1366
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/../../supervisor/shared/rgb_led_status.c:390
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/../../main.c:289
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/../../main.c:494
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/supervisor/port.c:164
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/esp32s2/cpu_start.c:423
/Volumes/CircuitPythonBuild/circuitpython/ports/esp32s2/build-espressif_saola_1_wrover/esp-idf/../../esp-idf/components/freertos/xtensa/port.c:143
? 

and here is the log from a boot boot with a looping code.py


ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3ffe8100,len:0x4
load:0x3ffe8104,len:0x1910
load:0x40050000,len:0x14b0
load:0x40054000,len:0x210c
entry 0x400502d8
I (48) boot: ESP-IDF v4.2-dev-1665-g160ba4924 2nd stage bootloader
I (48) boot: compile time 05:46:46
I (48) boot: chip revision: 0
I (52) boot.esp32s2: SPI Speed      : 40MHz
I (56) boot.esp32s2: SPI Mode       : DIO
I (61) boot.esp32s2: SPI Flash Size : 4MB
I (66) boot: Enabling RNG early entropy source...
I (71) boot: Partition Table:
I (75) boot: ## Label            Usage          Type ST Offset   Length
I (82) boot:  0 otadata          OTA data         01 00 0000d000 00002000
I (90) boot:  1 ota_0            OTA app          00 10 00010000 00080000
I (97) boot:  2 ota_1            OTA app          00 11 00090000 00080000
I (104) boot:  3 phy_init         RF data          01 01 00110000 00001000
I (112) boot:  4 nvs              WiFi data        01 02 00111000 00006000
I (120) boot:  5 user_fs          Unknown data     01 81 00200000 00200000
I (127) boot: End of partition table
I (131) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f000020 size=0x16a78 ( 92792) map
I (166) esp_image: segment 1: paddr=0x00026aa0 vaddr=0x3ffc3ce0 size=0x01df8 (  7672) load
I (169) esp_image: segment 2: paddr=0x000288a0 vaddr=0x40028000 size=0x00404 (  1028) load
I (173) esp_image: segment 3: paddr=0x00028cac vaddr=0x40028404 size=0x0736c ( 29548) load
I (192) esp_image: segment 4: paddr=0x00030020 vaddr=0x40080020 size=0x5196c (334188) map
I (285) esp_image: segment 5: paddr=0x00081994 vaddr=0x4002f770 size=0x04570 ( 17776) load
I (297) boot: Loaded app from partition at offset 0x10000
I (297) boot: Disabling RNG early entropy source...
I (298) cache: Instruction cache        : size 16KB, 4Ways, cache line size 32Byte
I (305) cpu_start: Pro cpu up.
I (309) cpu_start: Application information:
I (314) cpu_start: Project name:     circuitpython
I (319) cpu_start: App version:      6.0.0-alpha.2-143-g14b3b51c5
I (326) cpu_start: Compile time:     Aug  5 2020 05:46:23
I (332) cpu_start: ELF file SHA256:  0ec76b16f9bde9a0...
I (338) cpu_start: ESP-IDF:          v4.2-dev-1665-g160ba4924
I (345) cpu_start: Single core mode
I (349) heap_init: Initializing. RAM available for dynamic allocation:
I (356) heap_init: At 3FFDA9C8 len 00021638 (133 KiB): D/IRAM
I (362) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
I (369) cpu_start: Pro cpu start user code
I (428) spi_flash: detected chip: generic
I (428) spi_flash: flash io: dio
I (429) cpu_start: Starting scheduler on PRO CPU.
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2132) ledc: ledc_stop(428): LEDC is not initialized
E (2142) ledc: ledc_stop(428): LEDC is not initialized
E (2142) ledc: ledc_stop(428): LEDC is not initialized
E (2152) ledc: ledc_stop(428): LEDC is not initialized
E (2162) ledc: ledc_stop(428): LEDC is not initialized

@jepler
Copy link
jepler commented Aug 5, 2020

Seems like result->exception_type must have an inappropriate value, like being a NULL pointer?

@hierophect
Copy link
Collaborator Author

@fede2cr @jerryneedell thanks for your help in testing this! Seems like you've tracked down the way to repro it and it explains why I wasn't getting it since I already had a sketch loaded.

@jepler yes, the docs for the error imply this is dereferencing a NULL. I'm not super used to tracking down things like NULL exceptions without GDB, so either I'll figure out how to get GDB running on the ESP32 today based on Scott's video or I'll try just eyeballing it.

@tannewt
Copy link
Member
tannewt commented Aug 5, 2020

I've got a fix for the LEDC spew in my working code. It's resetting everything even it's not in use.

@hierophect
Copy link
Collaborator Author
hierophect commented Aug 5, 2020

@tannewt Yeah I've also fixed that edge case, I had to add a flag for first time reset. I'm working on tracking down the null reference now

@hierophect
Copy link
Collaborator Author

I found the error. At this line in main.c, result.exception_type is still at its default value of NULL, and thus causes an exception later in the call stack. One way to resolve it is to only set the exception color in rgb_led_stats if result->exception_type is not null.

But what I don't understand is why this does not occur for every other board? I don't see how this is in any way specific to the ESP32-S2. In any case, @tannewt could you take a look and let me know if you'd like me to maybe set a default exception, instead of NULL, or something else along those lines?

@hierophect
Copy link
Collaborator Author

Also, why do we lock the serial_write_compressed(translate("\nCode done running. Waiting for reload.\n")); message behind the user not having a serial connection? I don't see the purpose in not displaying that message, it's informative.

@jerryneedell
Copy link
Collaborator

Yay!! Works for me! Thank you @hierophect!

@hierophect
Copy link
Collaborator Author
hierophect commented Aug 5, 2020

I think this was actually an error on every board, but most of them don't throw errors for dereferencing null pointers. This should have caused a hardfault, I really don't know why it worked on them.

@jerryneedell
Copy link
Collaborator

I am so relieved that this turned out to be a real issue. The toolchains can be such "black boxes" and I was really worried that something was wrong in my configuration but it was baffling as to where it might have been.

@hierophect
Copy link
Collaborator Author

@jerryneedell Yeah for sure, it's always stressful when you're worrying about whether your meta-level setup is correct. Thanks to @fede2cr for figuring out it only occurred when code.py is empty!

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for hunting down the code.py issue.

@@ -12,6 +12,8 @@ USB_SERIAL_NUMBER_LENGTH = 12
# Longints can be implemented as mpz, as longlong, or not
LONGINT_IMPL = MPZ

CIRCUITPY_NEOPIXEL_WRITE = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this meant to be alphabetical?

< 1241 !-- -->

status->exception_color = MPY_ERROR;
} else {
status->exception_color = OTHER_ERROR;
if (result->exception_type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the first case the inverse of this and set the exception color to other in that case? Then you get an exception color and no if nesting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was found_main true in this case? With code.py it should be false and we can just skip all of the exception flashing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can check out found_main and see what the value is - I'm not that familiar with this portion of Circuitpython so I was kind of blundering around here. exception_type is the problematic element - it's initialized to NULL in main.c and never changed, so anything based off of it will fail. We could set it to a proper default instead, if you'd like - the problematic stuff starts here. Still not sure why STM and the other ports don't trigger a null reference crash too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is found_main supposed to do? I'm very confused by this whole section. Circuitpython runs with start_mp, then it tries to find the file afterwards? And you say that it should be false for code.py, but code.py is in the list of filenames it matches?

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is waiting for the rgb status change we talked about earlier @hierophect

Copy link
Member
@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you!

@tannewt tannewt merged commit bbac68e into adafruit:main Aug 11, 2020
@hierophect hierophect deleted the esp32-neopixel branch August 11, 2020 18:08
@hierophect hierophect mentioned this pull request Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
0