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版本比较多。
esp-idf windows安装包

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

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

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

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\,可以根据需要更改

cd D:\work\c1\
git clone --recursive https://gitee.com/EspressifSystems/esp-adf.git

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

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

cd esp-adf

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

git submodule update --init --recursive

编译示例代码

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

先进入ESP-ADF的源码目录

d:

cd D:\work\c1\esp-adf

执行配置adf环境的指令

export.bat

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

cd examples\player\pipeline\_play\_sdcard\_music

指定主板类型,比如esp32s3

idf.py set-target esp32s3

编译示例代码

idf.py build

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

烧录

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

则烧录指令如下

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

#include <stdio.h>

#include "hello_world.h"

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

include\hello_world.h

    #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中的函数

#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

    #
    # 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中。
生成的.a库
作者:帅得不敢出门 csdn原创谢绝收录转载

  • 27
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值