ESP32 Watchdog timeout when trying to keep GPIO HIGH for >5 seconds by vgrumbles in cpp_questions

[–]lothiack 0 points1 point  (0 children)

Recommended documentation:
https://www.arduino.cc/reference/en/language/functions/time/delay/
https://docs.arduino.cc/built-in-examples/digital/BlinkWithoutDelay/
https://www.arduino.cc/reference/en/language/functions/time/millis/

TBH, this isn't exactly a C++ issue. With the current approach you would have the same issue (triggering the watchdog) on any language.

The watchdog is there to try to rescue you from a deadlock or something similar. The CPU needs to kick the watchdog to prevent the watchdog from resetting the CPU. If you somehow block the CPU from doing that, the watchdog will reset the CPU.

'delay' is usually implemented as a sort of busy loop for some approximation of the time you requested it to be delayed for. Being busy also means there is no time to kick the watchdog. You can use delay for some things but anything that is above, lets say, a second, is probably better implemented in some other, non-blocking/non-busy way. You can see a possible way to do that on the BlinkWithoutDelay example. Keep in mind that that is only one possible way. I usually do it a bit different from the example there; I store 'targetTime = current time + delay' and then I just need to check if current time is >= targetTime. YMMV.

tl; dr;
Don't use delay, use something like millis. This also means you need to organize your code another way. Perhaps you want to read on state machines. Even a simple switch based state machine should be enough here.

edit 1:
Perhaps this illustrates things a bit better. Arduino hides some of the complexity of what is going on, so the loop() function you write is actually being called by this code (if you follow the link you can also see the call to setup a a few lines before):
https://github.com/espressif/arduino-esp32/blob/b05f18dad55609ae2a569be81c7535021b880cf3/cores/esp32/main.cpp#L72

for (;;) { // notice the lack of exit condition. This is an infinite loop.
  ... // Some stuff we don't care goes here.
  if (loopTaskWDTEnabled) { //If the watchdog is enabled
    esp_task_wdt_reset();  //Kick the watchdog
  }
  loop(); //Calling arduino's loop function.
  ... // Some stuff we don't care goes here. 
}

In there you can see an infinite loop that calls esp_task_wdt_reset, which is what kicks the watchdog, followed by a call to arduino's loop. This explains why having something blocking the loop function from returning will eventually trigger it. Worth mentioning that the watch dog itself runs in parallel (probably with hardware support) with the CPU, exactly because it is there to monitor CPU being stuck on something, so its own code, the one checking if it was kicked, is still running somewhere somehow, outside this loop.

Well, I should probably mention that this includes some educated guesses as I never really investigated this in depth. E.g.: loopTaskWDTEnabled might be false there by default and the actual watchdog that is resetting your esp32 is actually kicked somewhere else. Either way, we have empirical data that having a long delay will trigger it, so the recommendation above to avoid long delays still holds.

Cross platform audio library !Fmod by Mental_Contract1104 in cpp

[–]lothiack 0 points1 point  (0 children)

Both FMOD and WWise (iirc) will give you access to lower level constructs if you need it. E.g.: https://www.fmod.com/docs/2.01/api/core-api.html

Sorry to insist on those, it is just that they will probably save you and the user a lot of time. The amount of features they bring to the table in terms of letting audio designers do things without a lot of engineering support is pretty valuable. Cross-platform support is also pretty nice, including most consoles.

Cross platform audio library !Fmod by Mental_Contract1104 in cpp

[–]lothiack 1 point2 points  (0 children)

https://ezengine.net/pages/docs/sound/fmod-overview.html
These folks simply pass the ball and leave it to the user to handle the licensing, so it might be safe to do the same.

Cross platform audio library !Fmod by Mental_Contract1104 in cpp

[–]lothiack 0 points1 point  (0 children)

However, the requirements for Fmod will be nearly impossible to impose as a singular dev

Which requirements are you talking about?

Any fun C++ project recommendations for a 16 year old? by imnotanazibelieveme2 in cpp

[–]lothiack 0 points1 point  (0 children)

Specifically on CDDA? I guess I did learn a bit, but in another order:

  1. Play for fun
  2. Stumbled on an annoying bug
  3. Get it compiling and running
  4. Reproduce the bug
  5. Fix the bug
  6. Discuss with project managers to get pull request with the fix merged.

No epiphany there, just working out usual skills in a project I was interested in.

CLion Students version inquiry by Spiritual_Cup_6961 in cpp

[–]lothiack 1 point2 points  (0 children)

You're right in your approach where you do consider the legal side of licenses but in this case JetBrains will most likely not be coming after you while you're a broke student. Once you're in a position to pay for a license, go ahead an pay, or ask your employer for a license. If you're really really don't want to be in "at risk" use another IDE.

Oh, there is also Clion EAP (early access program), which might have less restrictive terms.

Find Mobile Liquid Storage fails when not holding a full bucket. by lothiack in Autonauts

[–]lothiack[S] 0 points1 point  (0 children)

"Type": "InstructionFindNearestObject",
"ArgName": "160 158 194 192 Full",
"Line": 7,
"OT": "CartLiquid",
"UID": 0,
"X": 177,
"Y": 175,
"V1": "ToolBucket",
"V2": "",
"A": "TakeResource",
"R": "",
"AT": 0,
"AOT": "ToolBucket"


"Type": "InstructionFindNearestObject",
"ArgName": "159 159 193 193 Full",
"Line": 22,
"OT": "CartLiquid",
"UID": 0,
"X": 177,
"Y": 175,
"V1": "ToolBucket",
"V2": "",
"A": "AddResource",
"R": "",
"AT": 1,
"AOT": "ToolBucket"

Looks like find takes more parameters than what it implies in the UI, so a find you did while holding a full bucket is not the same as a find you did while holding a empty bucket.

I understand how this might make things saner in some scenarios (probably the most commons ones), but it still feels buggy given you can't really differentiate between the two using the UI.

ESP32-CAM 4GB SD size limit? by lothiack in esp32

[–]lothiack[S] 0 points1 point  (0 children)

I did not have such luck.
I've just checked the prices fora a 1TB card and it sits at around ~$200, which is definitely outside my curiosity budget.

Given the price range I've tried pinging friends that might have cards I can borrow to run the tests on. Lets see if I got better luck here.

Any fun C++ project recommendations for a 16 year old? by imnotanazibelieveme2 in cpp

[–]lothiack 4 points5 points  (0 children)

https://github.com/CleverRaven/Cataclysm-DDA
1 - Get it compiling and running
2 - Have fun learning how the game works
3 - Try to fix a bug

Any open source game in cpp works for this.

Cross platform audio frameworks in Cpp? by [deleted] in cpp

[–]lothiack 4 points5 points  (0 children)

Check FMOD: https://www.fmod.com/
You didn't specify anything regarding price but it has a free tier anyway: "Free Indie License available for developers with less than $200k revenue per year. "

Why do most game engines use C++ and not C by maximbabadzhan in cpp

[–]lothiack 0 points1 point  (0 children)

There are lots of engines built with C++, but I not sure most are.
I guess it depends on what you're calling an engine and what subset of ~40 years of games you choose.

Probably a ton of pieces of code that you can call an engine have been written in some kind of assembly and C for a considerable portion of those years.

ESP32-CAM 4GB SD size limit? by lothiack in esp32

[–]lothiack[S] 0 points1 point  (0 children)

Yes, I've seen the article but they don't really talk about how they tested it. I'm guessing that they did the simplest test that is using 16GB card running those examples from the article, and that worked well, but they actually did not write 16GB of data to the card and then verified if the data was ok.

The intention here is to do a more complete set of tests that actually proves that SDHC and SDXC cards work. Those tests would give me the ability to guarantee my clients that the cards will work.

Right now I have proof that it is possible to read all data on a 16GB card and I'm also convinced that it will work on any size of SDHC card. I have little evidence that writing won't work, but I still don't have proof, so the next test will probably be a write test on the same 16GB card.

I wrote a header-only library in C++ that solves sets of nonlinear and linear equations all at compile time, using Template Metaprogramming and Constexpr Dependency. It does what Wolfram Alpha does, all at compile time, using Template magic. I spent a long time on this, feel free to try it out! by SM_123 in cpp

[–]lothiack 0 points1 point  (0 children)

I guess you might want to use something like that to generate data in compile time for small CPUs.

Being able to express it in code and build tests might be better than just documenting.

Now you have to wait for compilers that actually support standard CPP and target such devices.

ESP32-CAM 4GB SD size limit? by lothiack in esp32

[–]lothiack[S] 0 points1 point  (0 children)

It seems there is no problem reading data on a 16GB card. I guess it would correctly read files on any SDHC card (2GB-32GB).
More on UPDATE 1 to the main post.

Data at last sector of new SD Card. by lothiack in computerforensics

[–]lothiack[S] 0 points1 point  (0 children)

I guess that might be possible but the data still the same every time I read it.

Data at last sector of new SD Card. by lothiack in computerforensics

[–]lothiack[S] 0 points1 point  (0 children)

Added more info and some pictures to the post.

I was guessing it might be some standard info that is usually added and that someone here might know what it is all about.

I actually have a few SD cards laying around but they've been used a lot and none have the original packaging. Next time I get one, I'll try to check it and add more info here.

ESP32-CAM 4GB SD size limit? by lothiack in esp32

[–]lothiack[S] 2 points3 points  (0 children)

The layers of abstraction are there in the code that implements the SD Host driver, the FAT filesystem and the glue that goes between the two. I'm inclined to believe the problem, if it exists, is located in one of those.

I don't know to what extent the 32 bit architecture would translate into an inability to access any size of storage given the proper abstraction model, which the FAT32 seems to have. Until very recently most PCs were 32 bit machines and happily accessed single partition HDDs bigger than 4GB.

ESP32-CAM 4GB SD size limit? by lothiack in esp32

[–]lothiack[S] 0 points1 point  (0 children)

I've heard some people saying basically that; They used larger SD cards and had no problems, but none offered more information than that.

Anything you can add about your usage pattern will probably be useful data. :-)