【嵌入式硬件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在嵌入式上的运用,这里给大家 ...
随机推荐
- webuploader+asp.net如何实现分片+断点续传
文件夹数据库处理逻辑 public class DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject() ...
- POJ 2778 DNA Sequence (矩阵快速幂 + AC自动鸡)
题目:传送门 题意: 给你m个病毒串,只由(A.G.T.C) 组成, 问你生成一个长度为 n 的 只由 A.C.T.G 构成的,不包含病毒串的序列的方案数. 解: 对 m 个病毒串,建 AC 自动机, ...
- Cogs 1708. 斐波那契平方和(矩阵乘法)
斐波那契平方和 ★★☆ 输入文件:fibsqr.in 输出文件:fibsqr.out 简单对比 时间限制:0.5 s 内存限制:128 MB [题目描述] ,对 1000000007 取模.F0=0, ...
- 页面上有tab,如何点击加载更多?
加载更多是一个很简单的东西.但是也有几点需要注意: 1.首先在你切换tab的时候,要么在调用这个函数的时候将这个的thispage设为1,要么在切换tab的时候将这个thispage设为1,当你将这个 ...
- select2多选设置select多选,select2取值和赋值
select2设置select多选,select2取值和赋值,作为筛选条件的时候,取值相对简单,把选中的id值转为字符串传给后端查询,查询之后会刷新页面,为了在下拉框中显示刚刚选中的值,就需要给sel ...
- Redis恢复数据
对于单点或者集群,都可以用 cat data.txt | redis-cli --pipe方式进行冷恢复. 对于大数据量会很慢,但不会出错.
- CentOS下载与服务器版安装(VMware)
1. 下载 首先需要选择一个版本,因为华为云最新只提供了CentOS 7.6,所以要选择CentOS 7版本的. 官网只提供了最新的版本,而且服务器在国外,下载速度贼慢. 不过官方提供了分布在各个地区 ...
- 【转】adb server is out of date. killing完美解决
今天,久未出现的著名的“adb server is out of date. killing”又发生了,在此,将解决方法记下,以便日后查看. 1. 错误信息: C:\Users\lizy>ad ...
- 解决url传递过程中加号变空格的问题<转>
url传递过程中加号变空格在接收url参数的过程中,会发现如果参数中存在‘+’号,接收后会变成空格. 如11+22接收后变成11 22.要解决这个问题,需要将加号替换为%2B进行传递. 如11%2B2 ...
- RabbitMQ之Topic交换器模式开发
Topic交换器,即主题模式,进行规则匹配. 一.Provider 配置文件 spring.application.name=provider spring.rabbitmq.host=192.168 ...