ESP-IDF中给出的ESP32-C3的例程都只有一个任务。即void app_main()
而且没看见这个app_main任务是在哪里被创建的???
如果我想建一个ESP32-C3的多任务的工程该怎么实现呢?
如果芯片设置成ESP32(idf.py set-target esp32),可以用带有多任务创建的例程。也可以编译成功。
就是不知道当把芯片选成esp32-c3时怎么做。
请大佬帮忙指点下
求助:esp32-c3工程中怎么创建多个freertos任务?
Moderator: Bob
Re: 求助:esp32-c3工程中怎么创建多个freertos任务?
创建任务就按正常的 freeRTOS 的创建方式来就行了,没有什么特殊的,和芯片没什么关系,你既然可以使用 32 创建多任务,C3也是一样的创建方法。这个需要你要去了解 freeRTOS 的相关基础知识,然后复杂一点的例程里都会涉及到事件啊,多任务的之类的,你仔细看一下
-
wanzhilin88
- Posts: 25
- Joined: Sat Jan 08, 2022 3:11 am
-
wanzhilin88
- Posts: 25
- Joined: Sat Jan 08, 2022 3:11 am
-
wanzhilin88
- Posts: 25
- Joined: Sat Jan 08, 2022 3:11 am
Re: 求助:esp32-c3工程中怎么创建多个freertos任务?
您好!
想再请教些问题,先谢谢啦!
在我使用的这个例程中没有看见程序使用xTaskCreate()函数来创建任务,但是app_main()任务却可以运行。
我想请教一下,
1.那app_main()这个任务是在什么时候被创建的呢?
2.如果我在app_main任务里创建多个任务的时候,任务优先级该怎么设置?(app_main任务的优先级是多少还不知道)
3.如果我在app_main任务里创建好自己的任务后,再把app_main任务删除掉(使用vTaskDelete(NULL))对整个工程的运行会不会有什么影响?
想再请教些问题,先谢谢啦!
在我使用的这个例程中没有看见程序使用xTaskCreate()函数来创建任务,但是app_main()任务却可以运行。
我想请教一下,
1.那app_main()这个任务是在什么时候被创建的呢?
2.如果我在app_main任务里创建多个任务的时候,任务优先级该怎么设置?(app_main任务的优先级是多少还不知道)
3.如果我在app_main任务里创建好自己的任务后,再把app_main任务删除掉(使用vTaskDelete(NULL))对整个工程的运行会不会有什么影响?
Re: 求助:esp32-c3工程中怎么创建多个freertos任务?
https://docs.espressif.com/projects/esp ... s.html#id4 如果你对 app main 感兴趣,可以仔细阅读这一部分,
1.app_main()在bootloader阶段被创建
2.优先级在menuconfig里设置
3.直接return就结束task了
1.app_main()在bootloader阶段被创建
2.优先级在menuconfig里设置
3.直接return就结束task了
Re: 求助:esp32-c3工程中怎么创建多个freertos任务?
和ESP32一样的,只是将核心号码都写为0
TaskHandle_t Task1;
TaskHandle_t Task2;
// LED pins
const int led1 = 10;
const int led2 = 0;
void setup() {
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
0); /* pin task to core 1 */
delay(500);
}
//Task1code: blinks an LED every 1000 ms
void Task1code(void* pvParameters) {
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}
}
//Task2code: blinks an LED every 700 ms
void Task2code(void* pvParameters) {
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
digitalWrite(led2, HIGH);
delay(700);
digitalWrite(led2, LOW);
delay(700);
}
}
void loop() {
}
TaskHandle_t Task1;
TaskHandle_t Task2;
// LED pins
const int led1 = 10;
const int led2 = 0;
void setup() {
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(500);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
1, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
0); /* pin task to core 1 */
delay(500);
}
//Task1code: blinks an LED every 1000 ms
void Task1code(void* pvParameters) {
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
delay(1000);
}
}
//Task2code: blinks an LED every 700 ms
void Task2code(void* pvParameters) {
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for (;;) {
digitalWrite(led2, HIGH);
delay(700);
digitalWrite(led2, LOW);
delay(700);
}
}
void loop() {
}
Who is online
Users browsing this forum: No registered users and 1 guest
