arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.26k stars 230 forks source link

Support of Stm32duino (STM32F103C) #53

Closed NickNifontov closed 5 years ago

NickNifontov commented 6 years ago

Can you add support of Stm32duino?

http://www.stm32duino.com/ http://wiki.stm32duino.com/index.php?title=Main_Page

arkhipenko commented 6 years ago

It should work on it for the most part. What's probably not going to do anything is Sleep On Idle because every chip has a different way of entering power saving idle mode. Please try to compile examples and post error messages if any.

GitMoDu commented 6 years ago

I am unable the run the OO example. Static callbacks seem to work ok.

GitMoDu commented 6 years ago

OO example uses MemoryFree.h, which doesn't exist on most non-AVR ICs. Removing that gives no compilation errors, but the example also doesn't work. I've done a separate project using the scheduler in OO fashion and it does work! I think the example might just have something that's stopping the scheduler.

arkhipenko commented 6 years ago

Yes, it's unfortunate that such a simple and needed function as getting free memory info does not exist as a standard and had to be done via a "hack". Curious to learn more about your project (if OK of course). I found the OO route a bit tedious and not necessary for the small MC purposes. Too many files to track to my taste. But it is there.

Q: Currently it is one or the other - OO or static binding. I am thinking there is a use case for a combined approach. What do you think?


From: André notifications@github.com Sent: Thursday, May 24, 2018 11:25 AM To: arkhipenko/TaskScheduler Cc: Anatoli Arkhipenko; Comment Subject: Re: [arkhipenko/TaskScheduler] Support of Stm32duino (STM32F103C) (#53)

OO example uses MemoryFree.h, which doesn't exist on most non-AVR ICs. Removing that gives no compilation errors, but the example also doesn't work. I've done a separate project using the scheduler in OO fashion and it does work! I think the example might just have something that's stopping the scheduler.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/TaskScheduler/issues/53#issuecomment-391755828, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AATGTbXehq2uFi6QJds10Q8kb3VpWetNks5t1tDNgaJpZM4TEqES.

GitMoDu commented 6 years ago

I've yet to use static functions with schedulers since I stopped playing in all globals and moved a library approach: hence the need for a OO centered scheduler. No more static instances just to access some variable in memory, all is contained within a few inherited member functions.

Now I just pass the scheduler pointer during instancing, and a library can have an arbitrary number of "processes" to run inside of it, so there's zero coupling between the project and the library.

So my suggestion would be to keep the separated approach: the declarations are already very complicated as it is.

My project is nearing "good enough for github" soon, keep a watch and you'll see it. I make extensive use of the scheduler to do all kinds of things, like firing a static function asynchronously from an interrupt, keep a low priority health checker running in the background and, most importantly for me, have a way to do stuff in a class and then wait an arbitrary amount of time before the next run. As long as my classes behave (more than 500us processing is the limit I accept), then it's cooperative scheduler magic in action. I already tried implementing the same stuff (successfully) over FreeRTOS (with an appropriate OO wrapping), but the overhead was tremendous and the Heap massaging is just noise when developing.

arkhipenko commented 6 years ago

Can I close this issue? I do not have Stm32duino and am not planning on getting one. If you could create a PR with the code to put Stm32duino to sleep, that'd be great. Here is the point to do it:

https://github.com/arkhipenko/TaskScheduler/blob/6501258c99db5d1f481c098f20dc6535e3839c19/src/TaskScheduler.h#L891

GitMoDu commented 6 years ago

I can do a few tests, but the OO example is currently not even compiling, so I wouldn't call it closed. I can make PR on that.

arkhipenko commented 6 years ago

You mean this one does not compile? https://github.com/arkhipenko/TaskScheduler/tree/testing/examples/Scheduler_example21_OO_Callbacks

On which board? (And please do confirm you are using the testing branch)

It compiles for me on Uno/Nano and Teensy.

GitMoDu commented 6 years ago

If you could create a PR with the code to put Stm32duino to sleep, that'd be great.

I'm implementing the sleep functionality for my projects, after some testing I'll provide a pull-request, no problem.

You mean this one does not compile?

Yes. I found out that there is a way to check free memory in Stm32duino, I'll see if I can easily add that so that your example remains intact.

GitMoDu commented 6 years ago

I've implemented the suggested changes. I'll need to do some more testing, before creating a PR or two.

https://github.com/GitMoDu/TaskScheduler

arkhipenko commented 6 years ago

Sounds good! Looking forward to it.

GitMoDu commented 6 years ago

The sleep on idle seems to be working fine. I have yet to test power consumption to validate, but since this is the test branch, I'm confident in merging.

As for the OOP example, I still get a segfault when iCalc is enabled in iCalc->waitFor(iMeasure), even when I've stripped down the iCalc to do nothing. Any ideas? My simpler (in terms of scheduler feature use) projects have been working just fine otherwise.

arkhipenko commented 6 years ago

The sleep on idle seems to be working fine. I have yet to test power consumption to validate, but since this is the test branch, I'm confident in merging.

You can use my example 6 to validate without power consumption measurement. The counts with and without #define _TASK_SLEEP_ON_IDLE_RUN should be different.

As for the OOP example,

Do you mean my own example for the OOP does not work? What are you running it on? I only tested on UNO I think.

GitMoDu commented 6 years ago

You can use my example 6 to validate without power consumption measurement.

Excellent, I will, thanks.

Do you mean my own example for the OOP does not work?

Yes, example 21. I'm running on a STM32F1 (a.k.a. Mapple Mini, BluePill) with arduinoSTM32.

arkhipenko commented 6 years ago

Yes, example 21. I'm running on a STM32F1 (a.k.a. Mapple Mini, BluePill) with arduinoSTM32.

I don't know what to do! I don't have STM32F1, so can't test. Could it be the Arduino implementation on STM? Does it generate any additional messages you can send to me?

The most frequent causes of segmentation faults are generally pointer related: dereferencing an uninitialized pointer, a null pointer, or a previously freed pointer; accessing beyond the end (or in front of the beginning, but that's less frequent) of an object (array or other); using the results of an illegal pointer

A null pointer should have segfaulted on other platforms, however, it is not uncommon for MC's to say nothing and just silently die. It is possible that creation of the Calculator object fails for some reason, and then pointer is null. Could you print the address of the Calculator here: after it is created?

https://github.com/arkhipenko/TaskScheduler/blob/testing/examples/Scheduler_example21_OO_Callbacks/Scheduler_example21_OO_Callbacks.ino#L56

GitMoDu commented 6 years ago

I don't know what to do! I don't have STM32F1, so can't test.

You don't have to, but they cost 1.5€ with shipping included (throw in a few more cents and they'll come with the mapple mini bootloader already flashed, so you can use it with just a usb cable ), so there's really no reason not to get one 👍 Otherwise, I'l probably use the hell out of your scheduler in near future, so I'll be testing and fixing things, if I can.

It is possible that creation of the Calculator object fails for some reason, and then pointer is null.

I agree, it's most likely.

Meanwhile I realized I am dumb: I cannot test sleep with a USB Serial being emulated by the host CPU, obviously. I'll try with a external serial adapter to see if I can test it properly. But you were right, the difference is visible with the Example 6, tried it with an AVR for reference.

arkhipenko commented 6 years ago

@GitMoDu

You don't have to, but they cost 1.5€ with shipping included (throw in a few more cents and they'll come with the mapple mini bootloader already flashed, so you can use it with just a usb cable ), so there's really no reason not to get one

Do you have a link to the one you use with a bootloader? There are so many varieties - I want to test with your exact model

GitMoDu commented 6 years ago

On ebay, just search for Maple Mini STM32.

I have bought a few dozen, all came with bootloader.

I haven't forgotten this issue, I will report when I get the chance to do some testing.

Edit: Introduction to STM32Duino

arkhipenko commented 6 years ago

On ebay, just search for Maple Mini STM32.

Thank you! I just bought 3. Will play with it when it comes.

GitMoDu commented 5 years ago

Start without idle sleep. c1=4634635 c2=1001 Start with idle sleep. c1=4407173 c2=1001

Ok, this is the best I got with sleep. I believe USB would have to be disabled for optimal results.

arkhipenko commented 5 years ago

You can run without serial and save to eeprom. If you start with serial, just report the results. The numbers are too close, as if sleep does not do anything.

I have 2 STM32's on the way, will test!

GitMoDu commented 5 years ago

You can check out my attempts at https://github.com/GitMoDu/TaskScheduler/commits/testing

arkhipenko commented 5 years ago

So my example 21 stopped working on Uno/esp8266 as well. I traced it all the way to actually calling overloaded OnEnable() method of the calculator class - but for the life of me, I don't understand why it does not work! I start questioning my understanding of polymorphism! Still debugging.

GitMoDu commented 5 years ago

I am unable to test right now, but isn't that related to the other issue regarding constructors? I say this because my tasks are explicitly constructed and I never ran into this issue. Ex: MyTask(*Scheduler): Task( 0, TASK_FOREVER, scheduler, true).

arkhipenko commented 5 years ago

I say this because my tasks are explicitly constructed and I never ran into this issue. Ex: MyTask(*Scheduler): Task( 0, TASK_FOREVER, scheduler, true).

I don't think so! I am checking the construction process - the task is constructed. But when the enable explicitly calls OnEnable() method, which is a virtual function, and should call the overloaded one, the whole thing hangs. Just hangs. On esp8266 it throws Exception(2), which according to this: https://links2004.github.io/Arduino/dc/deb/md_esp8266_doc_exception_causes.html is Processor internal physical address or data error during instruction fetch So my theory is it throws execution pointer to some incorrect address and it tries to execute random bytes as processor instructions. I just don't understand why....

arkhipenko commented 5 years ago

Got STM32F103RCBT6 but can't upload a single sketch to it - can't make the USB COM to work!

Failed to init device.
stm32flash STM32duino_0.5.1

https://github.com/stm32duino/stm32flash

Using Parser : Raw BINARY
Interface serial_w32: 115200 8E1

An error occurred while uploading the sketch
GitMoDu commented 5 years ago

When connected to USB, do you find a DFU USB device listed in your computer? If so, ignore the fact the current program has no serial (which is really used in the upload to reset the board), and press the reset button when you're uploading. If not, and you find an unknown device, then you need to install the drivers. If nothing shows up, you need to burn the bootloader at least once using a ST-Link.

Also, try uploading using the Maple Mini board selected, instead of the generic STM32.

arkhipenko commented 5 years ago

Pushed to testing

arkhipenko commented 5 years ago

Also, try uploading using the Maple Mini board selected, instead of the generic STM32.

Got the board working and LOVING IT so far. Thanks for the tip!

arkhipenko commented 5 years ago

On ebay, just search for Maple Mini STM32.

These have become my favorite MCs! I have bought 3, already burnt 2 and ordered 4 more! Thanks again for the tip. They are awesome!

GitMoDu commented 5 years ago

I see the bug has bitten you too. Speaking of, I'm gonna order another box of them :p

arkhipenko commented 5 years ago

But Maple Labs discontinued those, and even the forum is closing down... What's the next thing?

chrisalbertson commented 5 years ago

Yes, the "Maple" has been gone for a while. The "Blue Pill" has pretty much replaced it and it costs about half as much. These things cost $2 each and have pretty much taken over the market. ebay.com/itm/STM32-ARM-Tafel-STM32F103C8T6-ARM-Minimum-System https://www.ebay.com/itm/STM32-ARM-Tafel-STM32F103C8T6-ARM-Minimum-System-Entwicklung-Tafel-Module-BBC/143225408524?hash=item2158e64c0c:g:NToAAOSwl-FZjqUX

The search terms are either "stm32 minimum system" or you can try "blue pill" (the name is something to do with the Matrix movie) This board is very well supported by the Arduino IDE now.

On Tue, May 7, 2019 at 8:27 AM Anatoli Arkhipenko notifications@github.com wrote:

But Maple Labs discontinued those, and even the forum is closing down... What's the next thing?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/arkhipenko/TaskScheduler/issues/53#issuecomment-490128650, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQKNRX7372M5E5LGMEKM4TPUGNXFANCNFSM4EYSUEJA .

--

Chris Albertson Redondo Beach, California

arkhipenko commented 5 years ago

Yes, the "Maple" has been gone for a while. The "Blue Pill" has pretty much replaced it and it costs about half as much. These things cost $2 each and have pretty much taken over the market. ebay.com/itm/STM32-ARM-Tafel-STM32F103C8T6-ARM-Minimum-System https://www.ebay.com/itm/STM32-ARM-Tafel-STM32F103C8T6-ARM-Minimum-System-Entwicklung-Tafel-Module-BBC/143225408524?hash=item2158e64c0c:g:NToAAOSwl-FZjqUX The search terms are either "stm32 minimum system" or you can try "blue pill" (the name is something to do with the Matrix movie) This board is very well supported by the Arduino IDE now. On Tue, May 7, 2019 at 8:27 AM Anatoli Arkhipenko @.***> wrote: But Maple Labs discontinued those, and even the forum is closing down... What's the next thing? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#53 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQKNRX7372M5E5LGMEKM4TPUGNXFANCNFSM4EYSUEJA . -- Chris Albertson Redondo Beach, California

Thank you. I saw them. Don't remember what stopped me - I should order a few and test with TaskScheduler just to make sure it works on this as well...

arkhipenko commented 5 years ago

Don't remember what stopped me

Ah! This thing did not have a bootloader initially - but you can burn one, while Mini comes with it already.

GitMoDu commented 5 years ago

Yup, that's it. You just need an ST-Link and you can burn the bootloader. Or you can just flash your program directly (this way it will NOT include the USB-Serial).

arkhipenko commented 5 years ago

Too much work!! Haha. I am lazy. :)))