apns pem 推送证书生成

  1. Certificates, Identifiers & Profiles,下载 Apple Push Services文件,生成的是 apns.cer,将cer双击导入到苹果系统。

  2. 从钥匙串中导出p12文件,证书和证书的key,注意设置安全密码:
    file

  3. 通过命令行开始生成

    cert:
    openssl pkcs12 -clcerts -nokeys -out apns_cert.pem -in apns_cert.p12
    key:
    openssl pkcs12 -nocerts -out apns_cert_key.pem -in apns_cert_key.p12

    这个过程会提示你输入之前的文件的密码,以及新生成的文件的密码,一定要区分清楚,因为后面的程序调试是需要生成文件的密码的。

  4. 将两个pem合成一个

    cat apns_cert.pem apns_cert_key.pem > ck.pem
  5. 验证
    开发证书:
    openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns_cert.pem -key apns_cert_key.pem
    量产证书:
    openssl s_client -connect gateway.push.apple.com:2195 -cert apns_cert.pem -key apns_cert_key.pem
    如果验证成功,内容结尾显示如下:

    SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DES-CBC3-SHA
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: xxx
    Start Time: 1627218051
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)

    Verify return code: 0 (ok),说明成功。

如何解除google ads和google账户的绑定关系

如果你恰好在研究admob,当你开通admob时,提示你有ads绑定无法开通。

那么如何将ads从google账号下解除呢:

  • 登录ads
  • 依次点击顶部的“工具与设置”-“帐号访问权限和安全”,在这里可以看到有权访问该Google Ads帐号的用户,其中就有“您本人”。
  • 点击“您本人”后面的“移除访问权限”,即可彻底删除Google Ads帐号

esp32 header fields are too long issue

error log

httpd_txrx: httpd_resp_send_err: 431 Request Header Fields Too Large - Header fields are too long for server to interpret

解决

在menuconfig中,调整HTTPD_MAX_REQ_HDR_LEN 的值:

menuconfig=>component config=>HTTP server=>max http request header leagth

官方其实已经对此问题做了说明,\examples\protocols\http_server\simple\README.md

If the server log shows "httpd_parse: parse_block: request URI/header too long", especially when handling POST requests, then you probably need to increase HTTPD_MAX_REQ_HDR_LEN, which you can find in the project configuration menu (`idf.py menuconfig`): Component config -> HTTP Server -> Max HTTP Request Header Length

esp32 console 源码关键部分解析

相关源码路径: \examples\system\console\components\cmd_system

这个框架实际就是一个现成构架好的命令字,参数以及回调函数的框架,只要我们按照规范填写对应的参数,就能实现一个完整的console命令。

流程框架

    // 第1步:
    /*参数段设置*/
    // 第2步:
    /*命令结构体配置*/
    // 第3步:将命令结构体插入命令序列
    ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));

第1步,参数段说明

我们找一个例子说明,其他的都是类似的步骤。

    int num_args                = 1;
    deep_sleep_args.wakeup_time = arg_int0("t", "time", "<t>", "Wake up time, ms");
#if SOC_PM_SUPPORT_EXT_WAKEUP
    deep_sleep_args.wakeup_gpio_num = arg_int0(NULL, "io", "<n>", "If specified, wakeup using GPIO with given number");
    deep_sleep_args.wakeup_gpio_level = arg_int0(NULL, "io_level", "<0|1>", "GPIO level to trigger wakeup");
    num_args += 2;
#endif
    deep_sleep_args.end = arg_end(num_args);

字段

deep_sleep_args 是用户创建的结构体,这个根据实际需要创建,例子中用的是int做参数,所以结构体主要是 arg_int, 以此类推,你可以选择arg_rem、arg_lit、arg_db1、arg_str等等。

这个结构体定义的最后一个成员是固定的 end,用来限制参数的个数。

参数构造函数

arg_int0:表示当前字段最多一个参数,可以为空,类型为int。
arg_int1:标识当前为一个必填字段,类型为int。
arg_intn:以此类推。

如果是其他类型,就有其他类似arg_xxx的参数构造函数。

我们具体以上面的内容为例子

arg_int0("t", "time", "<t>", "Wake up time, ms");

其中有4个成员,分别是:

  • "t":参数字段简写
  • "time":参数字段全拼
  • "< t >":参数类型,t表示时间值
  • "Wake up time, ms":参数功能描述

第2步,命令结构体

源码例子:

 const esp_console_cmd_t cmd = {
        .command = "deep_sleep",
        .help =
            "Enter deep sleep mode. "
#if SOC_PM_SUPPORT_EXT_WAKEUP
            "Two wakeup modes are supported: timer and GPIO. "
#else
            "Timer wakeup mode is supported. "
#endif
            "If no wakeup option is specified, will sleep indefinitely.",
        .hint     = NULL,
        .func     = &deep_sleep,
        .argtable = &deep_sleep_args
    };

其中 command、help、hint、func、argtable 是系统的固定定义,分别表示:

  1. command:命令字
  2. help:帮助说明
  3. hint:参数详细说明,为NULL时,由系统生成
  4. func:回调函数
  5. argtable:参数列表

第3步,开发自己的命令行

从上面的内容可以知道,我们要设计自己的命令行需要做一下工作:

  1. 设计完整的命令。
  2. 拆分出命令字,参数,搞清楚参数的类型和个数。
  3. 填写deep_sleep_args参数结构(填写实际的对象,这里只是举例)。
  4. 填写 esp_console_cmd_t cmd对象。
  5. 实现回调函数,这个也是最主要的内容。
  6. 将cmd将入系统命令队列。

到这里,我们就实现了自己的命令行,是不是很简单,主要的工作量都在准确实现参数列表和回调上。

How to Secure ESP32 Firmware and Flash Memory on ESP-IDF Framework

ref:https://circuitdigest.com/article/how-to-secure-esp32-firmware-and-flash-memory-using-esp-idf-framework

How to Secure ESP32 Firmware and Flash Memory on ESP-IDF Framework

In the era of Internet of Things(IoT), wireless communication is getting increasingly popular in everyday life. In the world of IoT devices, ESP32 is a popular low-cost System on Chip (SoC) microcontroller with built-in hybrid WiFi and Bluetooth chips by Espressif Systems. Because of its robust design and ultra-low power consumption, it has become so popular in IoT applications. But when we talk about IoT applications, security in IoT will come to our mind for data safety and secure connection. ESP32 supports X.509 certificate-based mutual authentication for HTTPs, IoT cloud (AWS-IoT, Azure, Google Firebase, etc.) authentication, and data communications. Over the Internet, ESP32 also gives us the data security for stored data into FLASH memory and Boot Sectors to prevent the data from being stolen. Today we talk about the ESP32 security features, mainly related to of Boot sectors. The two main security features on ESP32 are called Secure-Boot and flash security, also known as Flash-Encryption.

What eFUSE Blocks in ESP32?

The ESP32 has a 1024-bits One-Time-Programmable (OTP) memory block. This OTP memory block is divided into 4-block of 256-bits each.

file

These blocks of memory store the keys of the Flash encryption and Secure Boot. Because of the OTP memory block, there is no software present to read out those memory blocks. One and only ESP32 hardware can read and validate the Security features.

What is Flash Encryption? How to Enable it on ESP32?

ESP32 Flash Encryption is a security feature for the ESP32 provided by the ESP-IDF by Espressif System to protect the flash memory. Flash encryption is encrypting the contents of ESP32’s SPI flash memory and when this feature is enabled, the following types of data are encrypted by default:

  • Firmware Bootloader
  • Partition Table
  • “app” type partitions or Application partitions
  • Any partition marked with an “encrypted” flag in the partition table is also encrypted.
    In ESP-IDF projects, users can easily enable the Flash Encryption from the project configuration by the
idf.py menuconfig

After open the ESP32 project config menu, now navigate to

“Security Features” -->  
“Enable flash encryption on boot” --> 
“Enable usage mode (Development(NOT SECURE))” / “Enable usage mode (Release)”

In flash encryption there are two modes:

  • Development Mode: In this mode, the ESP32 flash memory partitions are all encrypted and open for modification and are also accessible to readout flash by the UART.
  • Release Mode: This mode is especially recommended for the manufacturing and production stages. In this mode, the readout of the flash by the UART/JTAG is totally blocked and new firmware can only be updated by over-the-air(OTA).

When the flash encryption is enabled, the binaries of the current code flash into the ESP32’s memory as a plain text file. But after completion of the flash process, on the first boot of the ESP32, the device itself encrypted each and every upper mention partition, one by one by using the AES flash encryption key which is stored into the eFUSE-BLK1 at the time of flash. After encrypting the partition the ESP32 device restarted itself and processed with the programmed logic.

The ESP32’s flash execution process decrypts the flash memory data when the ESP32’s execution unit tries to read and for the writing process, the flash execution process encrypts the data before writing into the flash memory.

file

What is Secure-Boot? How to Enable it on ESP32?

The ESP32 Secure-boot is a security feature, which provides security to run correct applications on ESP32 hardware. When secure boot is enabled, each and every flash memory’s binaries [Software bootloader & Application firmware] are verified before loading with the RSA-3072 based Secure-boot’s signature keys. We can call the Secure-boot a “Guardian of The ESP32”.

For enabling the Flash Encryption, in the same steps we can enable the Secure-boot from the project menuconfig.

“Security Features” -->  
“Enable hardware Secure Boot in bootloader”

How Secure-boot works?

When the ESP32 device is booted up, then ESP32 hardware’s trusted rom or we said the 1st stage bootloader runs verification with RSA-3072 based secure-boot key on the software bootloader and then the software bootloader verifies the application firmware with the same signature key and start the application.
file

Conclusion

The ESP32 comes with a secure environment [Secure-boot & Flash-Encryption], which we need to enable while flashing the code. For more security, we need to enable both of them.

centos change timezone

copy /usr/share/zoneinfo/xxx/xxx to /etc/localtime

原因:

为什么设置了时区以后,已经运行的程序在使用localtime函数调用时没有使用新时区呢?这个可以通过glibc的源码来回 答。localtime等涉及到本地所在时区的函数在调用的时候会先调用tzset这个函数,这一点可以通过tzset函数的manpage看出来。 tzset完成的工作是把当前时区信息(通过TZ环境变量或者/etc/localtime)读入并缓冲。事实上tzset在实现的时候是通过内部的 tzset_internal函数来完成的,显式的调用tzset会以显式的方式告知tzset_internal,而单独调用localtime的时候 是以隐式的方式告知tzset_internal,前者将强制tzset不管何种情况一律重新加载TZ信息或者/etc/localtime,而后者则是 只有在TZ发生变化,或者加载文件名发生变化的时候才会再次加载时区信息。因此,如果只是/etc/localtime的内容发生了变化,而文件名" /etc/localtime"没有变化,则不会再次加载时区信息,导致localtime函数调用仍然以老时区转换UTC时间到本地时间。

解决方法:在调用localtime之前调用tzset,则可强制刷新时区信息

当iphone升级成14.6以后,xcode12.4出现Unsupported OS version的问题

配置

system:mac air 11.4beta
xcode:12.4 12D4e
iphone:XR 14.6

现象

在xcode,手机出现“Unsupported OS version”,导致无法下载调试。

原因

原因是当前系统和硬件下,xcode就本限制在了当前版本,无法升级到最新的,导致无法支持最新的手机版本。

解决

参考:

https://stackoverflow.com/questions/67863355/xcode-12-4-unsupported-os-version-after-iphone-ios-update-14-6

因为原贴已经说的很清楚了,建议直接看原贴,如果想偷懒可以直接看以下总结步骤:

  1. 本机切换到路径:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
  2. 下载最新的release版本 https://raw.githubusercontent.com/iGhibli/iOS-DeviceSupport/master/DeviceSupport/14.5(FromXcode_12.5_Release_Candidate_xip).zip
  3. 解压后,出现的是14.5
  4. 将14.5复制一份,改成14.6,然后xcode退出,重进,然后iphone就正常了,可以连接下载了

esp32分区表分析总结

esp32分区表分析总结

要点

  • 分区表的首地址是0x8000。
  • 分区若偏移地址为空,则会紧跟着前一个分区之后开始;若为首个分区,则将紧跟着分区表开始。目前根据实际的代码和信息分析,第一个分区默认是从0x9000开始。
  • factory (0x00) 是默认的 app 分区。启动加载器将默认加载该应用程序。但如果存在类型为 data/ota 分区,则启动加载器将加载 data/ota 分区中的数据,进而判断启动哪个 OTA 镜像文件。
  • OTA 升级永远都不会更新 factory 分区中的内容。
  • 如果您希望在 OTA 项目中预留更多 flash,可以删除 factory 分区,转而使用 ota_0 分区
  • app 分区始终会被加密,不管 Flags 字段是否设置。
  • 如果您在项目配置菜单(idf.py menuconfig)中设置了分区表 CSV 文件的名称,然后构建项目或执行 idf.py partition_table。这时,转换将在编译过程中自动完成。
  • idf.py partition_table-flash :使用 esptool.py 工具烧写分区表。
  • idf.py flash :会烧写所有内容,包括分区表。

官方参考: https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-guides/partition-tables.html

分区表

如下是Factory app, two OTA definitions 的内容

# ESP-IDF Partition Table
# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000,  1M,
ota_0,    app,  ota_0,   0x110000, 1M,
ota_1,    app,  ota_1,   0x210000, 1M,
  • nvs:系统的非易失区,wifi配置,校准数据,以及其他通过api写入的非易失数据在这里。
  • otadata:这个用户存储ota的过程数据,比如当前区标识,完整性,校验等等。
  • phy_init:针对不同PHY的初始配置信息
  • factory:出厂分区,内容是我们的用户代码,我们的程序主体。当ota区有效时,此区会被跳过,默认没有ota时,运行的就是此区,一旦有ota版本,系统会尝试去启动ota的内容。
  • ota_0:第1个ota分区。
  • ota_1:第2个ota分区,无论如何总有一个是当期使用的激活区,另一个作为ota缓存空间用。
  • nvs_key:nvs区的秘钥分区。

    解释

    分区表的长度是0xc00,后面还md5校验,签名等,所以整个内容在 0x1000以内。
    0x9000=0x8000+0x1000
    0xd000=0x9000+0x4000
    0xf000=0xd000+0x2000
    0x10000=0xf000+0x1000
    0x110000=0x10000+0x100000(1M)
    0x210000=0x110000+0x100000(1M)

从上面的计算中,我们就可以看到,偏移地址和容量都是连续的,这也就是为什么实际的分区表,只天容量,不填其实偏移地址,因为地址可以根据容量进行计算得出。

实际例子分析

分区表

# Name,   Type, SubType, Offset,   Size, Flags
# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild
nvs,      data, nvs,     ,        0x4000,
otadata,  data, ota,     ,        0x2000,
phy_init, data, phy,     ,        0x1000,
ota_0,    app,  ota_0,   ,        0x180000,
ota_1,    app,  ota_1,   ,        0x180000,
fctry,    data, nvs,     ,        0x4000

系统运行日志

I (58) boot: ## Label            Usage          Type ST Offset   Length
I (65) boot:  0 nvs              WiFi data        01 02 00009000 00004000
I (72) boot:  1 otadata          OTA data         01 00 0000d000 00002000
I (80) boot:  2 phy_init         RF data          01 01 0000f000 00001000
I (87) boot:  3 ota_0            OTA app          00 10 00010000 00180000
I (95) boot:  4 ota_1            OTA app          00 11 00190000 00180000
I (102) boot:  5 fctry            WiFi data        01 02 00310000 00004000

从运行日志看,跟我们上面介绍的计算结果一致。

flash工具配置

烧录时的地址配置如下:
file

  • bootloader.bin: 默认从0地址开始。
  • partition-table.bin: 默认起始地址0x8000
  • ota_data_initial.bin: 对应的otadata和phy_init两个分区内容
  • app.bin:对应的是ota_0

从这个例子看,为了节省空间,factory分区被省掉了,直接是ota_0分区。

how to build an esp32 centos environment

esp32 centos开发环境搭建

系统:CentOS Linux release 7.8.2003 (Core)

chip:esp32c3

前言

重点:之前是在windows下工作的,因为编译烧录都比较方便。最近因为各种git的不稳定原因,导致无法正确编译和运行,所以才打算在海外搞个linux环境,这样就可以解决git相关的困扰。

环境安装

官方指导参考:https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32c3/get-started/index.html#id4

  1. 进入目标目录, 下载工具:

    git clone --recursive https://github.com/espressif/esp-idf.git
  2. 设置工具

    ./install.sh

    遇到的问题:

1)python版本问题

ESP-IDF supports Python 3.6 or newer but you are using Python 2.7.5. Please upgrade your installation as described in the documentation.

需要升级python,请参考网上文章,通过最新源码更新python。

2)ModuleNotFoundError: No module named '_ctypes' 问题

解决:

yum install libffi-devel -y

然后需要重新安装python3

make clean 
./configure
make&&make install
  1. 设置环境变量

    ./export.sh

遇到的问题:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'click'
env: idf.py: No such file or directory

解决:

python -m pip install click

由于是vps,所以 export.sh 实际上不会成功,一直卡死在 libusb-1.0 的错误中。所以只能手动设置环境变量,需要设置IDF_PYTHON_ENV_PATH 和PATH:

export PATH=/data/develop/esp/esp-idf/tools:$PATH
export PATH=/root/.espressif/python_env/idf4.4_py3.9_env/bin:$PATH
export IDF_PYTHON_ENV_PATH=/root/.espressif/python_env/idf4.4_py3.9_env

注意IDF_PYTHON_ENV_PATH一定要设置成 espressif的python路径,否则会一直提醒你执行 install.sh

验证idf.py环境ok:

idf.py --version
Setting IDF_PATH environment variable: /data/develop/esp/esp-idf
ESP-IDF v4.4-dev-1849-g8e3e65a-dirty

编译

找一个例子测试下

idf.py set-target esp32c3
idf.py build

出现错误:

  1. CMake 3.5 or higher is required. You are running version 2.8.12.2

升级cmake:

wget https://github.com/Kitware/CMake/releases/download/v3.21.0-rc2/cmake-3.21.0-rc2.tar.gz
tar zxvf cmake-3.21.0-rc2.tar.gz
make&&make install

添加cmake的环境变量
/usr/local/share/cmake-3.21

cmake --version
cmake version 3.21.0-rc2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
  1. 工具链错误 :
    
    riscv32-esp-elf-gcc

is not a full path and was not found in the PATH.


解决:把
> /root/.espressif/tools/riscv32-esp-elf/esp-2021r1-8.4.0/riscv32-esp-elf/bin 

添加到PATH环境变量里

排除完问题后,以前在windows下无法正常编译的demo,编译通过,

centos python2.7 升级 python3

安装一个软件要求python3.6 以上版本,当前的版本是2.7.5

系统配置

CentOS Linux release 7.8.2003 (Core)

python源码下载

https://www.python.org/downloads/source/
我们下载最新的版本。

wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
tar zxvf Python-3.9.6.tgz

编译

./configure
make
make install

设置系统默认的python版本

检查版本

python -V
Python 2.7.5
python3 -V
Python 3.9.6

我们需要设置环境变量,默认使用python3

cd /usr/bin
ls -al /usr/bin | grep python
lrwxrwxrwx    1 root root          7 Jul 10  2020 python -> python2
lrwxrwxrwx    1 root root          9 Jul 10  2020 python2 -> python2.7
-rwxr-xr-x    1 root root       7144 Apr  2  2020 python2.7
-rwxr-xr-x    1 root root       1835 Apr  2  2020 python2.7-config
lrwxrwxrwx    1 root root         16 Jul 10  2020 python2-config -> python2.7-config
lrwxrwxrwx    1 root root         14 Jul 10  2020 python-config -> python2-config

照猫画虎,将建立python3的软连接

ln -s /usr/local/bin/python3 /usr/bin/python
python -V
Python 3.9.6
[root@li1974-11

可见python3已生效。

还原yum

因为yum是用的默认版本,python3会导致yum失效。需要对yum的python做指定。修改以下2个文件:

vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down

修改首行的 #!/usr/bin/python 为 #!/usr/bin/python2.7

验证yum修改后的效果:

yum --version
3.4.3
  Installed: rpm-4.11.3-43.el7.x86_64 at 2020-07-10 12:34
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-04-01 04:21
  Committed: Panu Matilainen <pmatilai@redhat.com> at 2019-10-04

  Installed: subscription-manager-1.24.45-1.el7.centos.x86_64 at 2021-04-29 18:18
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-12-15 16:38
  Committed: William Poteat <wpoteat@redhat.com> at 2020-11-24

  Installed: yum-3.4.3-167.el7.centos.noarch at 2020-07-10 12:36
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-04-02 15:56
  Committed: CentOS Sources <bugs@centos.org> at 2020-03-31

  Installed: yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch at 2020-07-10 12:36
  Built    : CentOS BuildSystem <http://bugs.centos.org> at 2020-05-12 16:27
  Committed: Michal Domonkos <mdomonko@redhat.com> at 2020-03-12

yum 正常。

ESP32 下载工具说明

ESP32系列 flash下载

环境

硬件: esp32c3

环境: windows7

目前最新的IDF环境编译和下载都是python脚本完成的,但是对于非开发人员,测试或者工厂等下载最简单的方式还是通过下载工具,而不是配置负载的开发环境。

工具获取

去乐鑫官网下载最新的下载工具,工具页面:
https://www.espressif.com/zh-hans/support/download/other-tools

V3.8.8下载链接:
https://www.espressif.com/sites/default/files/tools/flash_download_tool_v3.8.8.zip

下载

解压后,运行工具,chip选择esp32c3,workmode选择develop

确定后,进入主页面,需要选择3个对应的bin档,他们分别是:

build\bootloader\bootloader.bin
build\partition_table\partition_table.bin
build\xxx.bin

其中xxx.bin是你的工程名称,也就是你的用户代码bin。
3个bin对应的地址分别是 0x0,0x8000,0x1000。以上bin的名称和地址都是根据命令行模式下载的日志中找到的,根据对应的size和地址,基本就能找到以上的信息。具体如图所示:

注意设置正确的串口,点击开始后,工具会自动读取正确的spiflash信息。

完成

完成后,绿色的按钮会显示完成字样,中间不要断电或者中断。
工具下载完成后不像命令行,不会自动重启,需要手动重启。

esp8266-window7-environment-installation

esp8266 window7开发环境搭建

最新代码

https://github.com/espressif/ESP8266_RTOS_SDK

安装toolchain

下载msys32

在windows环境下我们需要msys32,在linux不需要

https://dl.espressif.com/dl/esp32_win32_msys2_environment_and_toolchain-20181001.zip

下载8266对应的toolchain

在默认的msys下是没有8266的toolchain的,我们需要下载:

https://dl.espressif.com/dl/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-win32.zip

将解压后的xtensa-lx106-elf放到/msys32/opt/下

安装python环境

# python -m pip install --user -r $IDF_PATH/requirements.txt
Requirement already satisfied: setuptools in g:/msys32/mingw32/lib/python2.7/site-packages (from -r requirements.txt (line 4)) (40.4.3)
Collecting click>=5.0 (from -r requirements.txt (line 8))
  Downloading https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl (82kB)
    49% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒                | 40kB 450kB/s eta 0:00    61% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒            | 51kB 248kB/s eta     74% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒        | 61kB 296kB/s     86% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒    | 71kB 344k    98% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒| 81kB     100% |▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒| 92kB 385kB/s
Requirement already satisfied: pyserial>=3.0 in g:/msys32/mingw32/lib/python2.7/site-packages (from -r requirements.txt (line 9)) (3.4)
Requirement already satisfied: future>=0.15.2 in g:/msys32/mingw32/lib/python2.7/site-packages (from -r requirements.txt (line 10)) (0.16.0)
Requirement already satisfied: cryptography>=2.1.4 in g:/msys32/mingw32/lib/python2.7/site-packages (from -r requirements.txt (line 11)) (2.3.1)
Requirement already satisfied: pyparsing<2.4.0,>=2.0.3 in g:/msys32/mingw32/lib/python2.7/site-packages (from -r requirements.txt (line 12)) (2.2.0)
Collecting pyelftools>=0.22 (from -r requirements.txt (line 13))
  Using cached https://files.pythonhosted.org/packages/6f/50/3d7729d64bb23393aa4c166af250a6e6f9def40c90bf0e9af3c5ad25b6f7/pyelftools-0.27-py2.py3-none-any.whl
Requirement already satisfied: idna>=2.1 in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (2.7)
Requirement already satisfied: asn1crypto>=0.21.0 in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (0.24.0)
Requirement already satisfied: six>=1.4.1 in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (1.11.0)
Requirement already satisfied: cffi!=1.11.3,>=1.7 in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (1.10.0)
Requirement already satisfied: enum34 in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (1.1.6)
Requirement already satisfied: ipaddress in g:/msys32/mingw32/lib/python2.7/site-packages (from cryptography>=2.1.4->-r requirements.txt (line 11)) (1.0.22)
Requirement already satisfied: pycparser in g:/msys32/mingw32/lib/python2.7/site-packages (from cffi!=1.11.3,>=1.7->cryptography>=2.1.4->-r requirements.txt (line 11)) (2.19)
Installing collected packages: click, pyelftools
Successfully installed click-7.1.2 pyelftools-0.27

编译工程

设置环境变量

因为我们使用的是msys32的虚拟环境,所以我们只要设置msys32的虚拟环境变量即可,不需要设置windows的环境变量。这样正好可以让我们在window系统下同时兼容esp32和esp8266的开发环境。
修改/home/xxx[用户]/.bashrc

新增:

export IDF_PATH=~/esp/ESP8266_RTOS_SDK
export PATH=/opt/xtensa-lx106-elf/bin:$PATH

检验环境变量:
重新打开mingw32.exe,执行

xtensa-lx106-elf-gcc -v
# xtensa-lx106-elf-gcc -v
Using built-in specs.
COLLECT_GCC=G:\msys32\opt\xtensa-lx106-elf\bin\xtensa-lx106-elf-gcc.exe
COLLECT_LTO_WRAPPER=g:/msys32/opt/xtensa-lx106-elf/bin/../libexec/gcc/xtensa-lx106-elf/8.4.0/lto-wrapper.exe
Target: xtensa-lx106-elf
Configured with: /builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-lx106-elf/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=i686-host_w64-mingw32 --target=xtensa-lx106-elf --prefix=/builds/idf/crosstool-NG/builds/xtensa-lx106-elf --with-local-prefix=/builds/idf/crosstool-NG/builds/xtensa-lx106-elf/xtensa-lx106-elf --with-headers=/builds/idf/crosstool-NG/builds/xtensa-lx106-elf/xtensa-lx106-elf/include --with-newlib --enable-threads=no --disable-shared --with-pkgversion='crosstool-NG esp-2020r3-49-gd5524c1' --disable-__cxa_atexit --enable-cxx-flags=-ffunction-sections --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-gmp=/builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-lx106-elf/buildtools/complibs-host --with-mpfr=/builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-lx106-elf/buildtools/complibs-host --with-mpc=/builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-lx106-elf/buildtools/complibs-host --with-isl=/builds/idf/crosstool-NG/.build/HOST-i686-w64-mingw32/xtensa-lx106-elf/buildtools/complibs-host --enable-lto --enable-target-optspace --without-long-double-128 --disable-nls --enable-multiarch --enable-languages=c,c++ --disable-libstdcxx-verbose --enable-threads=posix --enable-libstdcxx-time=yes
Thread model: posix
gcc version 8.4.0 (crosstool-NG esp-2020r3-49-gd5524c1)

下载最新代码

务必git pull,不要zip解压,windows下很多隐藏文件容易出问题

git pull https://github.com/espressif/ESP8266_RTOS_SDK.git

menuconfig

进入需要编译的工程例子目录

make menuconfig

进行必要的配置。为了接下来的下载,我们需要配置串口:Serial flasher config > Default serial port,根据实际的串口来配置。

On Windows, serial ports have names like COM1. On MacOS, they start with /dev/cu.. On Linux, they start with /dev/tty

编译

make

# make
Toolchain path: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
Toolchain version: esp-2020r3-49-gd5524c1
Compiler version: 8.4.0
Python requirements from G:/msys32/home/zcj/esp/ESP8266_RTOS_SDK/requirements.txt are satisfied.
App "wifi_softAP" version: v3.4-28-g08e225dd
To flash all build output, run 'make flash' or:
python /home/zcj/esp/ESP8266_RTOS_SDK/components/esptool_py/esptool/esptool.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size 2MB 0x0 /home/zcj/esp/ESP8266_RTOS_SDK/examples/wifi/getting_started/softAP/build/bootloader/bootloader.bin 0x10000 /home/zcj/esp/ESP8266_RTOS_SDK/examples/wifi/getting_started/softAP/build/wifi_softAP.bin 0x8000 /home/zcj/esp/ESP8266_RTOS_SDK/examples/wifi/getting_started/softAP/build/partitions_singleapp.bin

编译 & 下载

make flash

esp32 menuconfig 中Example Configuration及sdkconfig.h中宏的生成

在esp32的框架中,我们发现例子引用的sdkconfig.h在 build\config\ 目录下,因为build目录是生成的,所以我们很容易判断这个头文件也是动态生成的。

那么这个头文件的内容我们怎么控制呢?
经过验证,文件中大概分两类宏,用户自定义宏和硬件默认规格宏。用户自定义宏都是CONFIG_ESP_ 开头,其他的都是默认规格宏。

那么这些用户自定义宏又是在什么地方定义的呢,答案是 \main\Kconfig.projbuild 文件,这个文件是类似yaml的脚本,当你执行 idf.py menuconfig 时,会加载这个文件,进行对应的修改。

esp32 win7开发环境搭建

环境

系统:win7
hw target:esp32c3

注意:很多问题都跟git的网络有关,要仔细看错误提示。很多错误需要尝试多遍,才有可能成功。

安装包

离线包安装 https://dl.espressif.com/dl/esp-idf/?idf=4.4

更新最新代码

将安装的IDF_PATH更新成最新的git版本 https://github.com/espressif/esp-idf

更新submodule

git submodule update --init --recursive

安装python virtual environment

install.bat

设置环境变量

export.bat

编译工程

设置hw 平台类型

idf.py set-target esp32c3

错误1:

Unable to checkout '4f5e89fa84ce1d178a6765b8b46f2b6f91216677' in submodule path 'components/libsodium/libsodium'

解决1:
看日志是git无法成功,我们改为手动git pull,如果提示 openssl 10054错误。则

git config --global http.sslVerify "false"

其后还有很多的失败,基本需要逐个确认,多次执行

git submodule update --init --recursive

配置成功

-- Configuring done
-- Generating done
-- Build files have been written to: G:/esp/esp-idf/examples/wifi/getting_started/softAP/build

菜单配置

idf.py menuconfig

component config->esp32c3-specific,选择rev 2:
file

编译成功

idf.py build
[84/85] Generating binary image from built executable
esptool.py v3.1-dev
Merged 1 ELF section Generated G:/esp/espidf/examples/wifi/getting_started/softAP/build/bootloader/bootloader.bin
[85/85] cmd.exe /C "cd /D G:\esp\espidf\examples\wifi\getting_started\softAP\build\bootloader\esp-idf\esptool_py &&g:\esp\espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe G:/esp/espidf/components/partition_table/check_sizes.py --
offset 0x8000 bootloader 0x0 G:/esp/espidf/examples/wifi/getting_started/softAP
/build/bootloader/bootloader.bin"
Bootloader binary size 0x48a0 bytes. 0x3760 bytes (76%) free.
[954/955] Generating binary image from built executable
esptool.py v3.1-dev
Merged 1 ELF section
Generated G:/esp/esp-idf/examples/wifi/getting_started/softAP/build/wifi_softAP.bin
[955/955] cmd.exe /C "cd /D G:\esp\esp..._started/softAP/build/wifi_softAP.bin"
wifi_softAP.bin binary size 0xa3490 bytes. Smallest app partition is 0x100000 by
tes. 0x5cb70 bytes (36%) free.

Project build complete. To flash, run this command:
g:\esp\espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe ..\..\..\..\comp
onents\esptool_py\esptool\esptool.py -p (PORT) -b 460800 --before default_reset
--after hard_reset --chip esp32c3  write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 build\bootloader\bootloader.bin 0x8000 build\partition_
table\partition-table.bin 0x10000 build\wifi_softAP.bin
or run 'idf.py -p (PORT) flash'

烧录

idf.py -p COM105 flash
esptool.py v3.1-dev
Serial port COM105
Connecting....
Chip is ESP32-C3 (revision 2)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:86:4a:94
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00010000 to 0x000b3fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 18592 bytes to 11216...
Writing at 0x00000000... (100 %)
Wrote 18592 bytes (11216 compressed) at 0x00000000 in 0.6 seconds (effective 253
.8 kbit/s)...
Hash of data verified.
Compressed 668816 bytes to 372018...
Writing at 0x00010000... (4 %)
Writing at 0x0001bf69... (8 %)
Writing at 0x00025854... (13 %)
Writing at 0x0002c95b... (17 %)
Writing at 0x0003382e... (21 %)
Writing at 0x0003ae72... (26 %)
Writing at 0x00041d6a... (30 %)
Writing at 0x0004886c... (34 %)
Writing at 0x0004fb4e... (39 %)
Writing at 0x00056b56... (43 %)
Writing at 0x0005d1f1... (47 %)
Writing at 0x0006332e... (52 %)
Writing at 0x00068eeb... (56 %)
Writing at 0x0006f110... (60 %)
Writing at 0x0007537e... (65 %)
Writing at 0x0007b840... (69 %)
Writing at 0x00081ae0... (73 %)
Writing at 0x00087df9... (78 %)
Writing at 0x0008df30... (82 %)
Writing at 0x000945f7... (86 %)
Writing at 0x0009b5fe... (91 %)
Writing at 0x000a66e9... (95 %)
Writing at 0x000ae4bc... (100 %)
Wrote 668816 bytes (372018 compressed) at 0x00010000 in 11.2 seconds (effective
476.2 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 103...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 258.7
kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Done

擦除flash

idf.py erase_flash

查看日志

idf.py -p COMXXX monitor

esp32 windows environment issue of python requirements

pc系统:win7 x64

按照指导文档,无论是命令行安装还是msi安装,都一直卡在:

G:\esp\esp-idf-src\examples\wifi\getting_started\softAP>idf.py build
The following Python requirements are not satisfied:
pyserial>=3.0
future>=0.15.2
cryptography>=2.1.4
pyparsing>=2.0.3,<2.4.0
pyelftools>=0.22
gdbgui==0.13.2.0
pygdbmi<=0.9.0.2
reedsolo>=1.5.3,<=1.5.4
bitstring>=3.1.6
ecdsa>=0.16.0
esp-windows-curses; sys_platform == 'win32'
To install the missing packages, please run "G:\esp\esp-idf\install.bat"
Diagnostic information:
    IDF_PYTHON_ENV_PATH: D:\Programs\Python\Python38
    Python interpreter used: D:\Programs\Python\Python38\python.exe

ESP-IDF v4.2.1

解决:
python -m pip install --user -r \xxx\xxx\requirements.txt