freeRTOS900 hangs

Post here first, or if you can't find a relevant section!
Post Reply
sankarAMP2
Posts: 27
Joined: Mon Feb 10, 2020 2:50 pm
Answers: 1
Location: India

freeRTOS900 hangs

Post by sankarAMP2 »

Hello guys,
I wrote a code with freeRTOS multi threading and gsm mqtt.
My environment:
using Harware:
https://github.com/rogerclarkmelbourne/Arduino_STM32

using libraries:
https://github.com/rogerclarkmelbourne/ ... reeRTOS900
https://github.com/knolleary/pubsubclient
https://github.com/vshymanskyy/TinyGSM


And my issue is: Code with freeRTOS900 or pubsubclient individually working fine but when I’m using both together the controller hangs unexpectedly…
Please help me to find reasons for RTOS hanging?


Thanq,
Sankar
User avatar
Pito
Posts: 94
Joined: Tue Dec 24, 2019 1:53 pm

Re: freeRTOS900 hangs

Post by Pito »

That description of your problem is not enough to help you.
Porting existing libraries into an Rtos is not easy - you have to create tasks which interacts, etc.
Best you will publish your entire code and it could be somebody helps you then..
Pukao Hats Cleaning Services Ltd.
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: freeRTOS900 hangs

Post by ag123 »

a blue pill has only 20k of memory, of which part of it is used by usb and partly the core itself, then freeRTOS further sub-divide memory into smaller fixed sized compartments for each vtask. so most likely you've run out of memory either for the vtasks or the overall shared memory
sankarAMP2
Posts: 27
Joined: Mon Feb 10, 2020 2:50 pm
Answers: 1
Location: India

Re: freeRTOS900 hangs

Post by sankarAMP2 »

as we already discussed in github, you can refer that topic for more details
https://github.com/rogerclarkmelbourne/ ... issues/723
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: freeRTOS900 hangs

Post by stevestrong »

I think you should track the issue by sequentially adding new features / libraries to a stable working simple example.
Then you can find out which software component is causing the issue.

For example, take a simply blinky example in freeRTOS.
Then add the MQTT client to that, using the simplest example. Check if it works.
If it does not work, then you have an implementation problem of MQTT clinet for freeRTOS.
Finally, add the GPS code to it. Check if it works.
If it does not work, then you have an implementation problem of GPS code for freeRTOS.

You may check this project for your reference:
http://www.atakansarioglu.com/how-to-io ... -freertos/
ag123
Posts: 1657
Joined: Thu Dec 19, 2019 5:30 am
Answers: 25

Re: freeRTOS900 hangs

Post by ag123 »

try to do without FreeRTOS, FreeRTOS troubles are discussed rather frequently
viewtopic.php?f=7&t=179
viewtopic.php?f=24&t=166

there are different ways to do thing without a context switching RTOS

Demonstration code for several things at the same time
https://forum.arduino.cc/index.php?topic=223286.0
Multi-tasking the Arduino - Part 1
https://learn.adafruit.com/multi-taskin ... ino-part-1

then there are many shedulers, taskers and event loops
https://github.com/joysfera/arduino-tasker
https://github.com/philbowles/H4
https://github.com/arcturial/arduino-event
https://github.com/johnnyb/Eventually
https://github.com/talybin/ard-events
https://github.com/ag88/stm32duino-eventloop

for context switching RTOS, you need to deal with 2 things, 1st memory is highly fragmented and you only have 20k for everything, each task needs its own stack so say 2 k per task x 4 tasks that is 8k, then the os and rest use a main stack say 3k so 11k is used for just for stacks, minus 5k for buffers and global variables, you are left with 4k for everything else, and if one of your task stack overflows or the core stack overflows it overwrite some global variables silently. you would have to use all sorts of tricks to figure out what overwrite whats.

second, if you call Serial.print() in a vTask() you are in trouble. Because, most functions in the core and all those that work with the h/w registers are *non reentrant*, for instance you have 2 vTask() that calls Serial.print(), in a benign case, perhaps they simply overwrite each other's outputs.
if a spin lock is encountered, e.g.

Code: Select all

while(1)
  if(check_variable()) break;
one thread will exit that spin lock, the other will get caught in the spin lock and hang
you will need to use semaphores, mutexes and to figure out which function use spinlocks and to call them so that they happen sequentially, not concurrently and that they don't overwrite the same state variables or most often the hardware registers.

the above is much much harder than if you simply do

Code: Select all

void loop() {
  task1();
  task2();
  task3();
}
you'd just need to go into the codes of each task() and to make sure that non of the task hogs time
Post Reply

Return to “General discussion”