STM32F103C8T6 how to Thread?
STM32F103C8T6 how to Thread?
STM32F103C8T6 how to Thread?
- MCU: STM32F103C8T6
Nice to meet you. I want to use 'Thread' function.
Q1) Is 'Thread' function possible in 'STM32F103C8T6'?
Q2) Is there any way to do it?
- 'STM32Duino' example file or source code is required.
help. I need your help.
- MCU: STM32F103C8T6
Nice to meet you. I want to use 'Thread' function.
Q1) Is 'Thread' function possible in 'STM32F103C8T6'?
Q2) Is there any way to do it?
- 'STM32Duino' example file or source code is required.
help. I need your help.
@myksj1105
Same thing. Parallel threads can be achieved only on multi core MCUs.
Concurrent threads can be achieved using RTOS. There is a FreeRTOS for STM32duino: https://github.com/stm32duino/STM32FreeRTOS
But concurrent multithreading should be used only if there is no other way. Jumping between thread is time and resource consuming.
Go to full postSame thing. Parallel threads can be achieved only on multi core MCUs.
Concurrent threads can be achieved using RTOS. There is a FreeRTOS for STM32duino: https://github.com/stm32duino/STM32FreeRTOS
But concurrent multithreading should be used only if there is no other way. Jumping between thread is time and resource consuming.
Re: STM32F103C8T6 how to Thread?
There are no threads without a RTOS that supports threads.
Re: STM32F103C8T6 how to Thread?
@GonzoG

@GonzoG
Thank you for your kind reply.
1. 'STM32F103C8T6' means that there is no 'thread' due to hardware characteristics.
2. If so, is there a 'thread'(Parallelism Thread) in the 'F4' chip?

@GonzoG
Thank you for your kind reply.
1. 'STM32F103C8T6' means that there is no 'thread' due to hardware characteristics.
2. If so, is there a 'thread'(Parallelism Thread) in the 'F4' chip?
Re: STM32F103C8T6 how to Thread?
@myksj1105
Same thing. Parallel threads can be achieved only on multi core MCUs.
Concurrent threads can be achieved using RTOS. There is a FreeRTOS for STM32duino: https://github.com/stm32duino/STM32FreeRTOS
But concurrent multithreading should be used only if there is no other way. Jumping between thread is time and resource consuming.
Same thing. Parallel threads can be achieved only on multi core MCUs.
Concurrent threads can be achieved using RTOS. There is a FreeRTOS for STM32duino: https://github.com/stm32duino/STM32FreeRTOS
But concurrent multithreading should be used only if there is no other way. Jumping between thread is time and resource consuming.
Re: STM32F103C8T6 how to Thread?
In a simple sketch, it is basically setup() and loop()
and a common implementation is
where main() is the entry point, so loop runs indefinitely. Among the ways that you can *multitask* can be codes like
that would make
runs approximately every 100 ms.
and you can have multiple set of those clauses to do different
there are even simpler 'dumb' implementations like such
it works well if the tasks() don't hold things up
of course, then there are interrupts, hardware timers etc, they are there in the wiki
https://github.com/stm32duino/Arduino_Core_STM32/wiki
and a common implementation is
Code: Select all
void main() {
setup();
while(1)
loop();
}
Code: Select all
uint32_t wait = 100; //ms
uint32_t end;
void setup() {
end = millis() + wait;
}
void loop() {
if( millis() > end ) {
// do my work
end = millis() + wait;
}
}
Code: Select all
//do my work
and you can have multiple set of those clauses to do different
Code: Select all
//do my work
Code: Select all
void loop() {
task1();
task2();
task3();
}
of course, then there are interrupts, hardware timers etc, they are there in the wiki
https://github.com/stm32duino/Arduino_Core_STM32/wiki
Re: STM32F103C8T6 how to Thread?
it depends on your definition of "thread".Q1) Is 'Thread' function possible in 'STM32F103C8T6'?
as the chip has only one execution unit (cpu or core), true concurrency (aka multi-thread execution) is not possible.
but that's not the end of the world: if you run multiple tasks fast enough, you can create the perception of "concurrency".
one way to achieve that is to use an OS. many different OSs exist for that, with varying degrees of complexity.
The simplest would be to run them serially - assuming that they are individually short enough.
using interrupts is a way of doing that as well.
or some form of a state machine:
Code: Select all
switch (state) {
case state 1: execute task1; break;
case state 2: execute task2; break;
...
}
A more structured way of doin that is protothreads. http://dunkels.com/adam/pt/
or my "tiny scheduler":
Code: Select all
//tiny scheduler macro
#define TS_RUN_WHILE(cs) if (cs) //tiny scheduler macro
Code: Select all
TS_RUN_WHILE(condition1) task1(); //run task1 if condition1 is true
TS_RUN_WHILE(condition2) task2(); //run task2 if condition2 is true
...
the simplicity comes at a huge limitation: those tasks cannot hang. That limitation actually can be quite effectively addressed on a mcu, via a watchdog.
Re: STM32F103C8T6 how to Thread?
Code: Select all
void loop() {
if( millis() > end ) {
// do my work
end = millis() + wait;
}
}
the way I do it is slightly different:
Code: Select all
void loop() {
if( millis() - millis0 > DURATION ) {
// do my work
millis0 += DURATION; //advance millis
}
}