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原创谢绝收录转载

相关推荐
鸿喵小仙女34 分钟前
HC32 SWDT看门狗
单片机·嵌入式硬件·hc32
点灯小铭36 分钟前
基于单片机的喷漆机器人自动控制系统
单片机·嵌入式硬件·机器人·毕业设计·课程设计·期末大作业
Dillon Dong1 小时前
STM32嵌入式开发:巧用位运算,打造高效参数ID管理方案
stm32·单片机·嵌入式硬件
亿道电子Emdoor1 小时前
【Arm】Arm DS如何导出Build log文件
stm32·单片机·嵌入式硬件
DIY机器人工房2 小时前
解决方法:关于上传经纬度绑定到onenet可视化平台地图上位置偏移的问题
stm32·单片机·嵌入式硬件·gps·定位·diy机器人工房
richxu202510012 小时前
嵌入式学习之路>单片机核心原理篇>(14) ARM 架构
arm开发·单片机·学习
清风6666662 小时前
基于单片机的蔬菜大棚温湿度远程测报系统设计
单片机·嵌入式硬件·毕业设计·课程设计·期末大作业
民乐团扒谱机3 小时前
十字路口交通信号灯控制器设计(Multisim 电路 + Vivado 仿真)
单片机·fpga开发·verilog·状态机·仿真·时序逻辑·multism
bai5459363 小时前
STM32 CubeIDE 按键控制LED
stm32·单片机·嵌入式硬件
小π军3 小时前
51单片机第2讲:数码管
单片机·嵌入式硬件·51单片机