【嵌入式硬件Esp32】(1)例程Hello World Example 注释
/* Hello World Example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h" void app_main()
{
printf("Hello world!\n"); /* Print chip information */
esp_chip_info_t chip_info; //该结构代表有关芯片的信息
esp_chip_info(&chip_info);
printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : ""); printf("silicon revision %d, ", chip_info.revision); printf("%dMB %s flash\n", spi_flash_get_chip_size() / ( * ),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external"); for (int i = ; i >= ; i--) {
printf("Restarting in %d seconds...\n", i);
vTaskDelay( / portTICK_PERIOD_MS);
}
printf("Restarting now.\n");
fflush(stdout);
esp_restart();
}
void esp_chip_info(esp_chip_info_t * out_info )
使用有关芯片的信息填充esp_chip_info_t结构。 参数
out_info:要填充的结构
Structures
结构:esp_chip_info_t
该结构代表有关芯片的信息。 公众成员 esp_chip_model_t model
芯片模型,esp_chip_model_t之一 uint32_t的features
CHIP_FEATURE_x功能标志的位掩码 uint8_t cores
CPU核心数量 uint8_t revision
芯片修订号
size_t spi_flash_get_chip_size()
获取闪存芯片大小,如二进制映像头中所设置。
注意
此值不一定与实际闪存大小匹配。
返回
闪存芯片的大小,以字节为单位
void vTaskDelay(const TickType_t xTicksToDelay)
Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate. The constant portTICK_PERIOD_MS can be used to calculate real time from the tick rate - with the resolution of one tick period. INCLUDE_vTaskDelay must be defined as 1 for this function to be available. See the configuration section for more information. vTaskDelay() specifies a time at which the task wishes to unblock relative to the time at which vTaskDelay() is called. For example, specifying a block period of 100 ticks will cause the task to unblock 100 ticks after vTaskDelay() is called. vTaskDelay() does not therefore provide a good method of controlling the frequency of a periodic task as the path taken through the code, as well as other task and interrupt activity, will effect the frequency at which vTaskDelay() gets called and therefore the time at which the task next executes. See vTaskDelayUntil() for an alternative API function designed to facilitate fixed frequency execution. It does this by specifying an absolute time (rather than a relative time) at which the calling task should unblock. Example usage: void vTaskFunction( void * pvParameters )
{
// Block for 500ms.
const TickType_t xDelay = 500 / portTICK_PERIOD_MS; for( ;; )
{
// Simply toggle the LED every 500ms, blocking between each toggle.
vToggleLED();
vTaskDelay( xDelay );
}
}
Parameters
xTicksToDelay: The amount of time, in tick periods, that the calling task should block.
看完hello_world也总要学点东西吧:
1.#include <stdio.h>可以看出来该SDK是依赖标准C库
2.#include "freertos/FreeRTOS.h"可以看出来该SDK定义为FreeRTOS系统,即嵌入式实时操作系统RTOS
#include "freertos/task.h"
3.void app_main(){}可以看出app_main是程序入口函数,也是我们所说的主函数main
4.vTaskDelay(1000 / portTICK_PERIOD_MS)是FreeRTOS里面的常用延迟函数,这函数有一定的研究价值,后面讨论
5.fflush(stdout)的使用很细心,乐鑫代码水平还是不错的
分析fflush(stdout)的使用:
printf是一个行缓冲函数,先写到缓冲区,满足条件后,才将缓冲区刷到对应文件中,刷缓冲区的条件如下:
1 )缓冲区填满
2 )写入的字符中有'\n'
3 )调用fflush手动刷新缓冲区
4 )调用scanf要从缓冲区中读取数据时,也会将缓冲区内的数据刷新
有人问为何我以前程序没有添加'\n'也能顺利打印出来,因为你printf不是在一个循环里面,便也不会牵扯到问题,因为就算执行printf后只是将内容送到缓冲区,但是你到程序结束里,程序结束便会导致缓冲区刷新,你便看到你到屏幕上有你期望到东西出现了,当然,经过测试,这也是跟编译器有关,但在while里面使用printf是跟上一句fflush(stdout)是保险的做法,手动刷新缓冲区,避免造成不必要的bug
最后,这代码分析到这里,可以尝试运行你的第一个hello_world demo
【嵌入式硬件Esp32】(1)例程Hello World Example 注释的更多相关文章
- 【嵌入式硬件Esp32】ESP32 正确下载姿势
程序的正确下载步骤,以8M flash为例子: 一.硬件连接 ESP32 的运行状态主要由 GPIO0 决定 二.ESP32 Flash 地址配置 ESP32 在编译时,通过 make menucon ...
- 【嵌入式硬件Esp32】Ubuntu 1804下ESP32交叉编译环境搭建
一.ESP32概述EPS32是乐鑫最新推出的集成2.4GWi-Fi和蓝牙双模的单芯片方案,采用台积电(TSMC)超低功耗的40nm工艺,拥有最佳的功耗性能.射频性能.稳定性.通用性和可靠性,适用于多种 ...
- 【嵌入式硬件Esp32】ESP32学习之在windows下搭建eclipse开发环境
一.所需工具 由于项目要用ESP32模块进行开发,折腾了下集成开发环境,现将过程记录下来,以便需要的人使用.其中需要的有交叉编译工具,esp-idf示例代码以及C/C++版的eclipse. 交叉编译 ...
- 【嵌入式硬件Esp32】ESP32使用visual studio cod界面
如何下载安装IDE Visual Studio Code大家可以在微软的官网上根据自身的开发平台下载,至于安装方法就是无脑式地按Next就好了,下载地址如下所示: Visual Studio Cod ...
- 【嵌入式硬件Esp32】MQTT链接测试工具
1.Eclipse Paho MQTT Utility GUI测试工具 下载地址: 链接:https://pan.baidu.com/s/1ivxk3DWJkod-jBsowlcoBA 提取码:0lp ...
- 【嵌入式硬件Esp32】安装MQTT服务器(Windows) 并连接测试
对于不知道MQTT的肯定会问MQTT是干什么的....... 现在我有一个项目需求, 看到这个项目第一想法肯定需要一个服务器,所有的wifi设备和手机都去连接这个服务器,然后服务器进行信息的中转,类似 ...
- 【嵌入式硬件Esp32】Ubuntu18.04 更换阿里云软件源
使用Ubuntu 的apt-get来安装软件是总是因为官方源的速度太慢而抓狂. 但是用阿里云的源就很快,下面总结一下如何更换Ubuntu的软件源. 一.备份sudo cp /etc/apt/sourc ...
- 【嵌入式硬件Esp32】Eclipse c++切换回英文方法
1.英文版汉化为中文版时是通过:Help-Install New Soft,下载安装中文支持包,重启即可. 2.恢复回英文界面步骤则如下: 2.1.打开安装目录下的eclipse.ini,在文件文件中 ...
- FFMPEG在嵌入式硬件上应用之 —— 基本环境搭建及编译
前段时间在翻看电脑里面资料时,发现了以前做的在嵌入式硬件上面运行以ffmepg为基础,以嵌入式硬件解码的多媒体播放工作,发现都快忘记完了.今日得闲整理温习了一下ffmpeg在嵌入式上的运用,这里给大家 ...
随机推荐
- 017_Python3 数据结构
本章节我们主要结合前面所学的知识点来介绍Python数据结构. ***************************** 1.列表 Python中列表是可变的,这是它区别于字符串和元组的最重 ...
- QQ首页 案例
一.知识点 ①background-attachment属性设置背景图像是否固定或者随着页面的其余部分滚动.scroll默认值.背景图像会随着页面其余部分的滚动而移动.fixed当页面的其余部分滚动时 ...
- JSON字符串 拼接与解析
常用方式: json字符串拼接(目前使用过两种方式): 1.运用StringBuilder拼接 StringBuilder json = new StringBuilder(); json.appen ...
- Random Target Moving~
测试了一下用向量处理随机目标,还是挺有趣的,源码如下: PVector p1, p2; float gap = 10; void setup() { size(1920, 1080); backgro ...
- 【一起来烧脑】一步学会HTML体系
[外链图片转存失败(img-zk4xNuy1-1563431241992)(https://upload-images.jianshu.io/upload_images/11158618-4e9cac ...
- Matlab中的变量名
在Matlab中使用save和load命令时,可能会出现变量名出错的问题. 如: save('A1.mat', 'A1'); load('A1.mat', 'A1'); 如果程序中还有名为a1的变量名 ...
- manjaro (arch) 安装搜狗输入法
本文通过MetaWeblog自动发布,原文及更新链接:https://extendswind.top/posts/technical/sogou_input_install_in_arch_manja ...
- tecplot不能导入fluent多面体的解决办法
多面体网格在fluent当中计算完成,如果保存cas和dat文件,如果直接将cas和dat文件导入tecplot进行后处理,tecplot会提示多面体网格在fluent当中计算完成,如果保存cas和d ...
- vue中如何动态添加readonly属性
动态绑定input的readonly属性 1 <inpu :readonly="status ? false : 'readonly'"> status 为 false ...
- web 安全登录算法
摘自:http://hi.baidu.com/weiqi228/blog/item/922e961bbcc2c0188618bfb5.html 对于 Web 应用程序,安全登录是很重要的.但是目前大多 ...