在ESP8266上尝试使用FreeRTOS
在官方论坛上下载了esp8266的lubuntu环境,里面自带了toolchain,按照文档配置好
用Git,clone https://github.com/espressif/esp_iot_rtos_sdk 里面的,按readme配置好环境变量
找到examples/project_template/user/user_main.c,编辑
view plaincopy
[*]/****************************************************
[*] * Copyright 2013-2014 Espressif Systems (Wuxi)
[*] *
[*] * FileName: user_main.c
[*] *
[*] * Description: entry file of user application
[*] *
[*] * Modification history:
[*] * 2014/12/1, v1.0 create this file.
[*]*****************************************************/
[*]#include "esp_common.h"
[*]#include "freertos/FreeRTOS.h"
[*]#include "freertos/task.h"
[*]void ICACHE_FLASH_ATTR
[*]task1(void *pvParameters)
[*]{
[*] printf("task 1\n");
[*]for (;;)
[*] {
[*] printf("Task 1 is running\n");
[*] vTaskDelay(100 / portTICK_RATE_MS);
[*] }
[*] vTaskDelete(NULL);
[*]}
[*]void ICACHE_FLASH_ATTR
[*]task2(void *pvParameters)
[*]{
[*] printf("task 2 init\n");
[*]for (;;)
[*] {
[*] printf("Task 2 is running\n");
[*] vTaskDelay(1000 / portTICK_RATE_MS);
[*] }
[*] vTaskDelete(NULL);
[*]}
[*]/****************************************************
[*] * FunctionName : user_init
[*] * Description: entry of user application, init user function here
[*] * Parameters : none
[*] * Returns : none
[*]*****************************************************/
[*]void ICACHE_FLASH_ATTR
[*]user_init(void)
[*]{
[*] printf("Hello World!\n");
[*] printf("SDK version:%s\n", system_get_sdk_version());
[*] xTaskCreate(task1, "task1", 256, NULL, 2, NULL);
[*] xTaskCreate(task2, "task2", 256, NULL, 2, NULL);
[*]}
然后执行gen_misc.sh脚本,对于我的板子是y,一路回车,到step5选 4,回车
然后用esp flash download tool下载两个文件到对应位置
串口默认已经初始化好,波特率74880,运行输出如下:
view plaincopy
[*] ets Jan8 2013,rst cause:2, boot mode:(3,6)
[*]load 0x40100000, len 24244, room 16
[*]tail 4
[*]chksum 0x8e
[*]load 0x3ffe8000, len 1156, room 4
[*]tail 0
[*]chksum 0xf0
[*]load 0x3ffe8490, len 668, room 8
[*]tail 4
[*]chksum 0x85
[*]csum 0x85
[*]R珸蔙€H@)鑠p_task_hdl : 3ffef768, prio:13, stack:512
[*]pm_task_hdl : 3fff0048, prio:1, stack:176
[*]ApiMsgMutex created
[*]tcpip_task_hdl : 3fff0460, prio:10,stack:512
[*]wdt_task : 3fff0d20, prio:14, stack:176
[*]idle_task_hdl : 3fff1890
[*]tim_task_hdl : 3fff1c88
[*]xPortStartScheduler
[*]frc2_timer_task_hdl:3fff2598, prio:12, stack:512
[*]OS SDK ver: 1.2.0(b900bd2) compiled @ Aug 28 2015 17:18:41
[*]phy ver: 356, pp ver: 9.0
[*]Hello World!
[*]SDK version:1.2.0(b900bd2)
[*]user_init:init complete.
[*]mode : sta(18:fe:34:a0:1a:64)
[*]add if0
[*]task 1
[*]Task 1 is running
[*]task 2 init
[*]Task 2 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 1 is running
[*]Task 2 is running
[*]Task 1 is running
[*]Task 1 is running
一个最简单的程序就弄好了。。
一些奇怪的细节:
1.串口波特率默认是74880,小黄板单独引出的RXD/GND/TXD那个接口不需要交叉
2.板子需要独立供电
3.跳线帽质量堪忧
4.task最后要加入vTaskDelete(NULL);,不加的话会出一些奇怪的问题。。这跟上面提到的教程里不一样
5.不用手工启动调度器
页:
[1]