forkineye / ESPAsyncE131

Asynchronous E1.31 (sACN) library for Arduino ESP8266 and ESP32
128 stars 28 forks source link

Ringbuffer library has issues with ESP32 #29

Open drvkmr opened 1 year ago

drvkmr commented 1 year ago

Hello, This has been already mentioned in #8 , I spent a significant amount of time trying to figure this out. Basically the problem is with using ringbuffer which for some reason breaks ESP32 sooner or later. Apparently it's because of the way ESP32 uses multiple cores but I don't really knpw.

I am transferring a relatively large amount of data (24 universes), which works surprisingly well generally until it suddenly stops. It can happen within a few seconds or after a couple of minutes. The interesting thing is lot of other parts of the program still keep working and I have no clue why.

For a long time, I tried to fix the issue in my code, but eventually the warnings-

"This library only fully supports AVR and ESP8266 Boards."
 "Operations on the buffer in ISRs are not safe!"

drew my attention I decided to get rid of ringbuffer. This took some time but once it was done there have been no issues even if I run at 60fps for hours.

I have a larger bytearray wsRawData in my code and am simply using memcpy in the callback like this -

void onNewPacketReceived(e131_packet_t* packet, void* userInfo) {
    uint16_t offset = (htons(packet->universe) - 1) * CHANNELS_PER_UNIVERSE;
    memcpy(wsRawData+offset, packet->property_values + 1, CHANNELS_PER_UNIVERSE);  // +1 to skip the start code }

Here packet is sbuff (which I made public) not pbuff.

Now I don't know what's the best way to fix this for the library itself because my implementation is similar to #9 but it does force you to go to a lower level and deal with the data yourself which is not ideal.

I found this from Espressif but not sure how to implement this or if it's even possible.

riwalker commented 9 months ago

is this bug still valid ? drvkmr what was the fix you made ? can you share ?

drvkmr commented 9 months ago

Yes I simply eliminated the use of ring buffer which fixed the issue. Here is the fork if you want to try out. Did not open any pull request because it doesn't look like the repository is being maintained anymore.

riwalker commented 9 months ago

anyone ported to esp-idf ?

UnexpectedMaker commented 2 months ago

Yes I simply eliminated the use of ring buffer which fixed the issue. Here is the fork if you want to try out. Did not open any pull request because it doesn't look like the repository is being maintained anymore.

I tried your fork (thanks for that) but you didn't update the example which still uses the ring buffer, and you didn't provide a working working example of how to get the packets now.

Can you update the example so it uses no ring buffer?

Thanks :)

drvkmr commented 2 months ago

@UnexpectedMaker I'll do that later this week. Btw love your boards!

UnexpectedMaker commented 2 months ago

Oh, thanks for the quick reply!!!
Wicked, I appreciate it :) My first time planing with DMX/sACN - in WAY over my head, hahahahaha

drvkmr commented 2 months ago

Hey @UnexpectedMaker , do you want to try it now?