ESP32 esp-idf esp-adf环境安装及.a库创建与编译

简介

ESP32

功能丰富的 Wi-Fi & 蓝牙 MCU, 适用于多样的物联网应用。使用freertos操作系统。

ESP-IDF 官方物联网开发框架。

ESP-ADF 官方音频开发框架。

文档参照

https://espressif-docs.readthedocs-hosted.com/projects/esp-adf/zh-cn/latest/get-started/index.html#get-started-step-by-step

ESP-IDF

windows建议直接安装exe

https://dl.espressif.cn/dl/esp-idf/?idf=4.4

从上面这个网址,下载offline installer的,一般会有3到4个版本,选择一种就行了,这里是建议往下拉,选择4.4版本,它适配的ESP-ADF版本比较多。

exe下载完,直接安装,安装后会在桌面或开始菜单中添加 "ESP-IDF 4.4 CMD", "ESP-IDF 4.4 PowerShell"的图标,

直接点击"ESP-IDF 4.4 CMD"会弹出一个cmd窗口,。

会打印类似这种信息, 它会自动配置好python, git , esp-idf的环境。

bash 复制代码
Setting PYTHONNOUSERSITE, was not set
Using Python in C:\Espressif\python_env\idf4.4_py3.11_env\Scripts\
Python 3.11.2
Using Git in C:\Espressif\tools\idf-git\2.39.2\cmd\
git version 2.39.2.windows.1
Setting IDF_PATH: C:\Espressif\frameworks\esp-idf-v4.4.6

ESP-ADF

安装完ESP-IDF,接下来安装ESP-ADF, 它属于IDF的扩展,要先安装好IDF,再安装ADF。

ESP-IDF与ESP-ADF有对应关系的,版本要对的上,版本对应信息及开发板对应的SDK可以从这个链接查看

https://github.com/espressif/esp-adf/blob/master/README.md#idf-version

安装git bash

要下载源码,需要先安装git bash

官方下载地址:https://www.git-scm.com/download/

选择for windows版本下载,然后安装。

下载ESP-ADF源码

下载ESP-ADF源码,在windows中,打开git bash,输入以下指令进行下载, 这里指定下载到D:\work\c1\,可以根据需要更改

bash 复制代码
cd D:\work\c1\
git clone --recursive https://gitee.com/EspressifSystems/esp-adf.git

如果出错了,提示timeout , error之类的, 可能是子模块下载失败了。

可以这样解决, 先进入esp-adf目录

cd esp-adf

然后再执行下面这个指令,如果出错,多执行几次

bash 复制代码
git submodule update --init --recursive

编译示例代码

打开安装IDF后的"ESP-IDF 4.4 CMD",会进入一个cmd命令窗口,

先进入ESP-ADF的源码目录

bash 复制代码
d:

cd D:\work\c1\esp-adf

执行配置adf环境的指令

bash 复制代码
export.bat

进入播放sdcard音乐的示例目录

bash 复制代码
cd examples\player\pipeline\_play\_sdcard\_music

指定主板类型,比如esp32s3

bash 复制代码
idf.py set-target esp32s3

编译示例代码

bash 复制代码
idf.py build

编译成功后会生成build\play_sdcard_music.bin

烧录

用usb转串口,连接电脑与设备,假设连接后串口为COM3, 默认的波特率为460800

则烧录指令如下

bash 复制代码
idf.py -p COM3 -b 460800 flash

ESP-ADF创建.a库

进入ESP-ADF的源码,在example创建generate_static_library路径

创建静态库项目hello_world

generate_static_library目录下创建

components\hello_world

CMakeLists.txt

    idf_component_register(SRCS "hello_world.c"
                        INCLUDE_DIRS "./include")

component.mk文件

    #
    # "main" pseudo-component makefile.
    #
    # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

hello_world.c

c 复制代码
#include <stdio.h>

#include "hello_world.h"

void hello_world(void)
{
    printf("hello world!\n");
}

include\hello_world.h

c 复制代码
    #ifndef _HELLO_WORLD_H_
    #define _HELLO_WORLD_H_

    #include "string.h"
    #include "stdio.h"


    #ifdef __cplusplus
    extern "C"
    {
    #endif

    void hello_world(void);

    #ifdef __cplusplus
    }
    #endif
    #endif

创建调用hellow_world库的工程

generate_static_library目录下创建

CMakeLists.txt test.c component.mk放main/目录

test.c源码, 调用上面hello_world中的函数

c 复制代码
#include <stdio.h>

#include "hello_world.h"

void app_main(void)
{
    hello_world();
}

CMakeLists.txt

    idf_component_register(SRCS "test.c"
                        INCLUDE_DIRS ".")

component.mk文件

    #
    # "main" pseudo-component makefile.
    #
    # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

generate_static_library目录下创建

CMakeLists.txt

# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(test)

Makefile

Makefile 复制代码
    #
    # This is a project Makefile. It is assumed the directory this Makefile resides in is a
    # project subdirectory.
    #

    PROJECT_NAME := test

    include $(IDF_PATH)/make/project.mk

编译

电脑中打开"ESP-IDF 4.4 CMD",

cd 进入generate_static_library目录,

编译

idf.py build

会生成test.bin在目录examples\generate_static_library\build中,

libhello_world.a也会生成,在目录generate_static_library\build\esp-idf\hello_world中。

作者:帅得不敢出门 csdn原创谢绝收录转载

相关推荐
Zevalin爱灰灰10 分钟前
编程技巧(基于STM32)第一章 定时器实现非阻塞式程序——按键控制LED灯闪烁模式
stm32·单片机·嵌入式硬件
苏慕TRYACE4 小时前
RT-Thread+STM32L475VET6实现红外遥控实验
stm32·单片机·嵌入式硬件·rt-thread
小幽余生不加糖5 小时前
deepseek帮我设计物理量采集单片机口保护电路方案
单片机·嵌入式硬件
Ronin-Lotus6 小时前
蓝桥杯篇---IAP15F2K61S2串口
单片机·嵌入式硬件·职场和发展·蓝桥杯·c·iap15f2k61s2
yyqzjw7 小时前
【STM32】外部时钟|红外反射光电开关
stm32·单片机·嵌入式硬件
charlie1145141917 小时前
(萌新入门)如何从起步阶段开始学习STM32 —— 0.碎碎念
c语言·stm32·单片机·嵌入式硬件·学习·教程
苏慕TRYACE7 小时前
RT-Thread+STM32L475VET6——ADC采集电压
stm32·单片机·嵌入式硬件·rt-thread
jmlinux8 小时前
STM32 HAL库USART串口中断编程:环形缓冲区防止数据丢失
stm32·单片机·嵌入式硬件
W说编程10 小时前
STM32物联网终端实战:从传感器到云端的低功耗设计
网络·stm32·嵌入式硬件·物联网·struts
此去经年。10 小时前
I2C学习笔记-软件模拟I2C
笔记·单片机·学习