Closed twinotter closed 5 years ago
The problem appears to be an issue with how memory is allocated in compilation. Either commenting out some of the code in the setup() OR commenting out test2 will make this work. The code below demonstrates the problem. Issue #900 seems to have this same problem, but is unsolved.
I tried to simplify the code as much as possible and still capture the issue. I found at some point that things just suddenly worked. The code below causes the boot loop. But you can make the code work by either removing the "test2" String or commenting out the code in the setup() routine. (You can leave the Serial port initialization and sample write and still see it work successfully.)
The SmartMatrix library I'm using is here. The FastLED library is here. Otherwise, it's just the libraries included with esp32.
/*
* This example shows how to display bitmaps that are exported from GIMP and
* compiled into the sketch and stored in the Teensy's Flash memory
* See more details here:
* http://docs.pixelmatix.com/SmartMatrix/library.html#smartmatrix-library-how-to-use-the-library-drawing-raw-bitmaps
*
* This example uses only the SmartMatrix Background layer
*/
//#include <SmartLEDShieldV4.h> // uncomment this line for SmartLED Shield V4 (needs to be before #include <SmartMatrix3.h>)
#include <SmartMatrix3.h>
#include <FastLED.h>
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = 64; // known working: 16, 32, 48, 64
const uint8_t kMatrixHeight = 64; // known working: 32, 64, 96, 128
const uint8_t kRefreshDepth = 24; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 2; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kPanelType = SMARTMATRIX_HUB75_64ROW_MOD32SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_NONE); // see http://docs.pixelmatix.com/SmartMatrix for options
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
String test1 = "test1";
String test2 = "test2";
void setup() {
Serial.begin(115200);
Serial.println("Hi!");
matrix.addLayer(&backgroundLayer);
matrix.begin();
matrix.setBrightness(128);
backgroundLayer.drawString(1,2,{255,255,255},"init...");
backgroundLayer.swapBuffers(true);
delay(2000);
}
void loop() {
}
I believe this issue was from allocating a large amount of memory globally before call_start_cpu()
is called. The memory likely spanned the boundaries of memory regions, even though the allocations were much smaller than the total amount of memory.
The macros SMARTMATRIX_ALLOCATE_BUFFERS()
and SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER()
allocate memory, one with malloc for DMA memory, and one with a static buffer. Changing the static buffer to a malloc call in the constructor didn't help. The malloc calls all had to be moved inside setup(), after (I'm assuming) call_start_cpu()
had properly set up the memory regions.
I committed fixes for the issue I was seeing (might be a similar issue, or might not be) to the SmartMatrix Library
Thanks, Louis! This is definitely in the right direction. I wonder if the underlying system could be smarter with allocations though.. it seems like it should fail more gracefully.
it seems like it should fail more gracefully.
I agree 100%
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
This stale issue has been automatically closed. Thank you for your contributions.
Hardware:
Board: ESP32 Dev Module C Core Installation/update date: 10/apr/2018 IDE name: Arduino IDE Flash Frequency: 80Mhz Upload Speed: 921600
I'm not sure where to begin debugging this problem. I'm trying to get SmartMatrix and FastLED working on an ESP32. Separately the components work, but when I combine together, I'm getting an assert that causes a rolling reboot before anything gets started. I'm guessing a memory problem, but I'm uncertain where.
Stack results: